Building projects with AWS CodeBuild

Let's perform the following steps to build a project from the CodeCommit repository that we created in the previous recipe:

  1. Sign in to your AWS account and open AWS Developer Tools at https://us-west-2.console.aws.amazon.com/codesuite.
  1. From the Developer Tools menu, expand the Build menu and click on Build Projects. The following screenshot shows the menu's location:

  1. On the Build projects page, click on the Create build project button. The following screenshot shows the other available menu options and the location of the Create build project button:

  1. Enter a project name.
  2. Now, we will set the primary source of the project. In the Source box, select AWS CodeCommit as a source provider. Select the repository you created in the Creating an AWS CodeCommit code repository recipe. Select the master branch. In our example, the repository's name is k8sdevopscookbook:

  1. In the Environment box, select Managed image and Ubuntu as your OS.
  2. Select New service role:

  1. Expand the additional configuration settings. Add the AWS_DEFAULT_REGION, AWS_ACCOUNT_ID, IMAGE_TAG, and IMAGE_REPO_NAME environment variables, as shown in the following screenshot:

Never store environmental variables in a repository location. Always use environmental parameters to provide the values during the build process.
  1. In the Buildspec box, select Use a buildspec file. Make sure the buildspec.yaml file exists in the root of your code repository. This file should look something like this:
version: 0.2
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
...

  1. Finally, click on Create build project.
  2. Find the Service Role you created in step 7 in Identity and Access Management (IAM) and add this statement to the policy attached to the CodeBuild service role:
{
"Version": "2012-10-17"
"Statement": [
### BEGIN ADDING STATEMENT HERE ### { "Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:GetAuthorizationToken",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart" ],
"Resource": "*",
"Effect": "Allow"
},
### END ADDING STATEMENT HERE ### ... ],
}
  1. Now that the project is ready, click on the Start build button on the upper right-hand corner of the page. In the following screenshot, you can view its status under the Build history tab, after it's been started. In our example, it shows that the build Succeeded:

If your builds fail, make sure that the AmazonEC2ContainerRegistryPowerUser policy is assigned to your IAM role.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.80.34