This CloudFormation stack helps you to integrate your GitLab to AWS CodeBuild quickly.
-
Click the following button to launch the CloudFormation Stack in your account.
-
(Optional) Modify your AWS CodeBuild service role to add permissions like Amazon ECR access. You can find the role ARN in the output of this stack if you use
admin
orminimal
as the input parameterRoleArnForCodeBuild
. You can always modify this role later. -
Modify your repository to adapt your build command. The default build command is
bash build.sh
, in this case your need a filebuild.sh
in your repository to specify your build steps. -
Create a webhook in your GitLab project settings.
- For the webhook URL, use the value of the output
WebhookURL
of the CloudFormation stack. - For the secret token, use the value of the parameter
WebhookSecretToken
of the CloudFormation stack. - Add webhook triggers as you need.
- For the webhook URL, use the value of the output
-
When your webhook is triggered, you will find your builds in the AWS CodeBuild console.
Here is an example of build.sh
if you want to build a docker image and upload it to Amazon ECR:
# install docker
apt update -y
apt install docker -y
# login to AWS ECR
aws ecr get-login-password --region us-east-1 | docker login \
--username AWS --password-stdin \
1234567890.dkr.ecr.us-east-1.amazonaws.com
# build image
docker build -t myImage .
docker tag myImage 1234567890.dkr.ecr.us-east-1.amazonaws.com/myImage
# create ECR repository
aws ecr create-repository --repository-name=myImage
# publish image
docker push 1234567890.dkr.ecr.us-east-1.amazonaws.com/myImage
- The parameters
GitLabPassword
andWebhookSecretToken
are stored in the AWS Secrets Manager. - The AWS CodeBuild project has the permission to retrieve
GitLabPassword
from the AWS Secrets Manager to download your source codes. The GitLab password will be stored as an environment variable and can be accessed by your build command.
Since this is a quick start template, many AWS CodeBuild features are not included, but you can configure them by yourself.
Those AWS CodeBuild features includes:
- Access assets within your VPCs like RDS, ElastiCache, etc.
- Cache build assets to accelerate later builds.
- Generate build badge.
- Set timeout and queued timeout.
- Use certificates from your Amazon S3 bucket.
- Attach to Amazon EFS file systems.
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.