-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildspec.yml
52 lines (47 loc) · 1.87 KB
/
buildspec.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
version: 0.2
env:
git-credential-helper: 'yes'
variables:
# docker 파라미터 정의
ECS_CONTAINER_NAME: final-project-container
IMAGE_REPO_NAME: final-project-ecr # aws ecr에 등록이 되어 있는 name
IMAGE_TAG: latest
AWS_DEFAULT_REGION: ap-northeast-2
phases:
pre_build:
commands:
# Docker push를 할 ECR에 로그인 필요
# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/get-login-password.html
# https://stackoverflow.com/questions/77488134/codebuild-error-exit-status-127-file-name-too-long
- echo Logging in to Amazon ECR...
- aws --version
- ECR_PASSWORD=$(aws ecr get-login-password --region $AWS_DEFAULT_REGION)
- AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output
text)
- echo -n ${ECR_PASSWORD} | docker login --username AWS --password-stdin
${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
build:
commands:
- echo Build started on `date`
# 프로젝트 폴더로 이동
- cd ./frontend
- pwd
- echo Building the Docker image...
# Github Repository에 있는 Dockerfile의 위치에 맞춰 수정
- docker build -f ./dockerfile -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $REPOSITORY_URI
post_build:
commands:
- echo package Source...
- echo push the Docker image...
- docker push $REPOSITORY_URI
# Give your container name
- printf '[{"name":"%s","imageUri":"%s"}]' $ECS_CONTAINER_NAME
$REPOSITORY_URI > ../imagedefinitions.json
- echo $ECS_CONTAINER_NAME
- echo printing ../imagedefinitions.json
- cat ../imagedefinitions.json
artifacts:
files:
- imagedefinitions.json