Skip to content

Instantly share code, notes, and snippets.

@choi-ys
Created February 15, 2022 13:00
Show Gist options
  • Save choi-ys/547395b58ac2c17aef7d6dba7430a298 to your computer and use it in GitHub Desktop.
Save choi-ys/547395b58ac2c17aef7d6dba7430a298 to your computer and use it in GitHub Desktop.
Application build 및 artifact upload를 위한 AWS Code Build의 설정 파일 buildspec.yml
version: 0.2
env:
variables:
SPRING_PROFILE: "prod"
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin AWS_계정_ID.dkr.ecr.ap-northeast-2.amazonaws.com
- REPOSITORY_URI=AWS_계정_ID.dkr.ecr.ap-northeast-2.amazonaws.com/리포지토리명
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
build:
commands:
- chmod +x ./gradlew
- echo unit testing ...
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILE} ./gradlew test
- echo make jar ...
- ./gradlew assemble
- echo Build started on `date`
- echo Building the Docker image...
- docker build -f Dockerfile -t $REPOSITORY_URI:latest --build-arg JAR_FILE=build/libs/JAR_파일명.jar .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"리포지토리명","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- cat imagedefinitions.json
cache:
paths:
- '/root/.gradle/**/*'
artifacts:
files: imagedefinitions.json
# 참조 URL https://developerbee.tistory.com/228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment