To setup CodeBuild, first we need to create/modify buildspec.yml file to describe build steps. After that we can configure CodeBuild Project linking with CodeCommit Repository.
cd ~/environment/tripmgmt/ wget https://build-first-devops-ecs.workshop.aws/reference-files/buildspec.yml
Replace «YOUR_REPOSITORY_URI» with Container Repository URL - For example, accountid.dkr.ecr.region.amazonaws.com/repository name
git add buildspec.yml git commit -m "Updated buildspec file with ECR path" git push
Setup CodeBuild Project
Open the CodeBuild console.
On the Build projects page, choose Create build project.
In Project configuration: Enter a name for this build project
tripmgmt-demo-build. Build project names must be unique across each AWS account. You can also include an optional description of the build project to help other users understand what this project is used for.
If required, Select Build badge to make your project’s build status visible and embeddable.
In Source: For Source provider, choose AWS CodeCommit.
From Repository, choose the repository you have created for this project demo.
For Reference type, choose Branch and select master branch.
In Environment: choose Managed Image with Operating system as Amazon Linux 2,
For Runtime(s) choose Standard and Image choose the one with Standard:2.0 with Image Version as Always use the latest image for this runtime version
For Environment type choose Linux and Check mark Privileged action.
For Service role choose New service role and give meaningful name
Under Additional configuration, for Compute choose right spec EC2 instance type to run your build (i.e. 7 GB memory, 4 vCPUs)
For Buildspec name - optional, add buildspec.yml file location -
For Logs, check mark CloudWatch logs and give Group name as codebuild-logs, Stream name as tripmgmtdemo-build.
Click Create build project.
Now edit newly created service role
codebuild-tripmgmt-demo-build-service-role to allow accessing ECR repository through AmazonEC2ContainerRegistryPowerUser managed policy.
codebuild-tripmgmt-demo-build-service-rolerole from IAM console.
Select the build project and Start build to test CodeCommit and CodeBuild integration.
Post successful build, you can verify new docker image in Amazon ECR console.