Skip to content

Instantly share code, notes, and snippets.

@MrMikeFloyd
Created May 23, 2022 07:19
Show Gist options
  • Save MrMikeFloyd/c991ed661a9930a5a1be2fe449e710f1 to your computer and use it in GitHub Desktop.
Save MrMikeFloyd/c991ed661a9930a5a1be2fe449e710f1 to your computer and use it in GitHub Desktop.
AWS CodeBuild build specification file to be included in the repo of the artifact we'd like built. Find the most recent version here: https://github.com/codecentric/accelerate-kickstarter-aws/blob/main/cloud-bootstrap-app/buildspec.yml
version: 0.2
runtime-versions:
java: openjdk8
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')
build:
commands:
- echo Build started on `date`
- echo Packaging the application...
- mvn package
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- printf '{"ImageURI":"%s"}' $REPOSITORY_URI:$IMAGE_TAG > imageDetail.json
artifacts:
files:
- imagedefinitions.json
- imageDetail.json
- appspec-prod.yaml
- taskdef-prod.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment