Last active
July 6, 2024 13:51
-
-
Save overnew/f91e0fabaa02cf62f98d377700280ba5 to your computer and use it in GitHub Desktop.
buildspec.yaml example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 0.2 | |
env: # 환경변수를 정의 | |
variables: | |
AWS_DEFAULT_REGION: "ap-northeast-1" | |
ECR_URL: "awsid.dkr.ecr.ap-northeast-1.amazonaws.com/milliapp" | |
IMAGE_REPO_NAME: "milliapp" | |
IMAGE_TAG: "appv02" | |
AWS_ACCOUNT_ID: "awsid" | |
ECS_FAMILY: "app-service" | |
CONTAINER_NAME: "appv02" | |
NEW_IMAGE_URL: "awsid.dkr.ecr.ap-northeast-1.amazonaws.com/milliapp:appv02" | |
#빌드 환경에 필요한 것 설치 | |
phases: | |
install: | |
# https://github.com/aws/aws-codebuild-docker-images/blob/master/ubuntu/standard/4.0/Dockerfile | |
runtime-versions: | |
python: 3.9 | |
#이후 빌드를 위한 command 작성 | |
pre_build: | |
commands: | |
- echo Logging in to Amazon ECR... | |
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com | |
#pre/build에 들어가야 하는 명령어가 다른 것은 아니라, 편의상 나누어 둔다. | |
build: | |
commands: | |
- echo Build started on `date` | |
- echo Building the Docker image... | |
#새로운 이미지 url | |
- echo $NEW_IMAGE_URL | |
- 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 | |
- echo Pushed the Docker image! | |
# from https://github.com/cheekykorkind/medium_example/blob/main/terraform/7e3ae5ade965/server/buildspec.yml | |
- export EDITED_TASK_DEF1=task_definition.json | |
- export LAST_TASK_DEF_ARN1=$(aws ecs list-task-definitions --family-prefix $ECS_FAMILY --sort DESC --max-items 1 --query 'taskDefinitionArns[0]' --output json) | |
# LAST_TASK_DEF_ARN1의 결과값에 「"」가 붙어있음. 지워야함 | |
- LAST_TASK_DEF_ARN1="${LAST_TASK_DEF_ARN1%\"}" | |
- LAST_TASK_DEF_ARN1="${LAST_TASK_DEF_ARN1#\"}" | |
- echo $LAST_TASK_DEF_ARN1 | |
- aws ecs describe-task-definition --task-definition $LAST_TASK_DEF_ARN1 --output json | jq . > origin_task_definition1.json | |
- cat origin_task_definition1.json | |
- echo setting done | |
- cat ./appspec.yml | |
#- cat ./appspec.yml | sed -e s@\<ONE_CONTAINER_NAME\>@web@ > ./appspec.yml | |
# task def를 만듬 | |
- python ./edit_task_def.py | |
#- cat $EDITED_TASK_DEF1 | sed -e s@\<ONE_CONTAINER_NAME\>@$web@ > $EDITED_TASK_DEF1 | |
- cat $EDITED_TASK_DEF1 | |
- cat ./appspec.yml | |
# 추후 code deploy에 사용할 artifact 파일을 만들어 준다. | |
artifacts: | |
files: | |
- appspec.yml | |
- task_definition.json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment