forked from swm-nodriversomabus/BPP-API-Spring
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (100 loc) · 4.14 KB
/
deploy-dev-be.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: 백엔드 dev 배포
on:
push:
branches:
- "dev"
- "main"
# 환경 변수 설정
env:
ACTIVE_PROFILE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
AWS_REGION: ap-northeast-2
CONTAINER_NAME: ${{ github.ref == 'refs/heads/main' && 'prod-yeohaeng-api' || 'dev-yeohaeng-api' }}
ECR_REPOSITORY: ${{ github.ref == 'refs/heads/main' && 'prod-yeohaeng-api' || 'dev-yeohaeng-api' }}
# ECS 클러스터명
ECS_CLUSTER: ${{ github.ref == 'refs/heads/main' && 'yeohang-api-far-prod' || 'yeohang-api-far-dev' }}
# ECS 서비스명
ECS_SERVICE: ${{ github.ref == 'refs/heads/main' && 'yeohang-api-far-prod-ser' || 'yeohang-api-far-dev-ser' }}
# ECS Task definition 파일명
ECS_TASK_DEFINITION: ${{ github.ref == 'refs/heads/main' && './cicd/task-definition-prod.json' || './cicd/task-definition-dev.json' }}
JASYPT_SECRET: ${{ secrets.JASYPT_SECRET }}
CONFIG_IMPORT: ${{ secrets.CONFIG_IMPORT }}
permissions:
contents: read
jobs:
be-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout # 현재 Repo Clone
uses: actions/checkout@v3
- name: Set Up Firebase Folder and Files
run: |
mkdir -p src/main/resources/firebase
- name: Checkout files
uses: actions/checkout@v3
with:
repository: swm-nodriversomabus/Files
token: ${{ secrets.PAT_SECRET }}
ref: main
path: './src/main/resources/firebase'
# - name: Move File to src/resources/firebase
# run: |
# mkdir -p src/resources/firebase
# cp temp-repo/path/to/file.ext src/resources/firebase/
# working-directory: your/app/path # 앱의 작업 디렉토리
# JDK 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permisson for gradlew # gradlew 실행 권한 부여
run: chmod +x gradlew
# Gradle clean build
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean build -x test # 임시로 테스트 안함
env:
SPRING_PROFILES_ACTIVE: ${{ env.ACTIVE_PROFILE }}
# AWS 자격 인증 설정
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# ECR 로그인
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# ECR에 도커 이미지 Push
- name: Push docker image to ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
SERVICE_TAG: . # Dockerfile 경로
# IMAGE_TAG: ${{ github.sha }}
IMAGE_TAG: latest
run: |
docker build --build-arg JASYPT_SECRET=$JASYPT_SECRET --build-arg CONFIG_IMPORT=$CONFIG_IMPORT --build-arg PROFILE_ACTIVE=$ACTIVE_PROFILE -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
# ECS Task 정의
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: updating task-definition file
run: cat ${{ steps.task-def.outputs.task-definition }}
# ECS Task Push
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
codedeploy-appspec: appspec.yaml
wait-for-service-stability: true