A build spec is a collection of build commands and related settings, in YAML format, that AWS CodeBuild uses to run a build.
You are going to include a build specification as part of the source code.
You are going to add buildspec.yml
to Northwind solution, not CDK project.
Create buildspec.yml
file in the root of the solution (next to Northwind.sln
file) that describes how to build and publish Docker container to the Amazon ECR.
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 .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
This build spec simply does the following:
docker build
)docker tag
)docker push
)Please note the following environment variables that you will setup in next module:
AWS_DEFAULT_REGION
with a value of region IDAWS_ACCOUNT_ID
with a value of account IDIMAGE_TAG
with a value of LatestIMAGE_REPO_NAME
with a value of Amazon ECR repository nameAdd this new file to source control:
git add buildspec.yml
git commit -m "Add buildspec file"
git push aws master
git add buildspec.yml
git commit -m "Add buildspec file"
git push origin master