-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
64 lines (54 loc) · 2.32 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
53
54
55
56
57
58
59
60
61
62
63
64
version: 0.2
phases:
install:
runtime-versions:
docker: 20
pre_build:
commands:
# Docker Hub 로그인 추가
- echo "Logging in to Docker Hub..."
- echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
# Amazon ECR 로그인
- 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
# 리소스 디렉토리 생성 및 설정 파일 가져오기
- echo "Creating resources directory..."
- mkdir -p src/main/resources
- echo "Fetching configuration from Parameter Store..."
- aws ssm get-parameter --name "/easystay/backend/application.yml" --query Parameter.Value --output text > src/main/resources/application.yml
- aws ssm get-parameter --name "/easystay/backend/application-dev.yml" --query Parameter.Value --output text > src/main/resources/application-dev.yml
- ls -la src/main/resources/
# Docker 빌드 설정
- echo "Setting up Docker build..."
- IMAGE_TAG=v${CODEBUILD_BUILD_NUMBER}
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPOSITORY_NAME
# Gradle 캐시 디렉토리 생성
- echo "Setting up Gradle cache directories..."
- mkdir -p /root/.gradle
- chmod -R 777 /root/.gradle
build:
commands:
- echo "Building the Docker image..."
- |
docker build \
--build-arg GRADLE_CACHE=/root/.gradle \
--cache-from $REPOSITORY_URI:latest \
-t $REPOSITORY_URI:$IMAGE_TAG .
- docker tag $REPOSITORY_URI:$IMAGE_TAG $REPOSITORY_URI:latest
post_build:
commands:
- echo "Pushing the Docker images..."
- docker push $REPOSITORY_URI:$IMAGE_TAG
- docker push $REPOSITORY_URI:latest
- echo "Updating ECS service..."
- aws ecs update-service --cluster $ECS_CLUSTER_NAME --service $ECS_SERVICE_NAME --force-new-deployment
- echo "Creating artifacts..."
- printf '{"ImageURI":"%s","ImageTag":"%s"}' $REPOSITORY_URI:$IMAGE_TAG $IMAGE_TAG > imageDefinitions.json
artifacts:
files:
- imageDefinitions.json
discard-paths: yes
cache:
paths:
- '/root/.gradle/caches/**/*'
- '/root/.gradle/wrapper/**/*'