-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (100 loc) · 3.73 KB
/
api-CD.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Motivoo API Server CD
on: # 트리거
push:
branches: [ "develop" ]
paths:
- motivoo-api/**
- motivoo-domain/**
- motivoo-common/**
- motivoo-external/**
- .github/workflows/**
- ./
- scripts/**
jobs:
deploy-ci: # job#1
runs-on: ubuntu-22.04
env:
working-directory: ./ # 프로젝트 디렉토리
steps: # 작업 단위
- name: 체크아웃
uses: actions/checkout@v3
- name: Java 실행 환경 - JDK 17 세팅
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: application.yml (API 모듈) 파일 생성
run: |
# yml을 생성할 디렉터리로 작업 디렉터리 이동
cd ./motivoo-api/src/main/resources
echo "${{ secrets.APPLICATION }}" > ./application-deploy.yml
working-directory: ${{ env.working-directory }}
- name: Firebase JSON 파일 생성
run: |
cd ./motivoo-api/src/main/resources
mkdir ./firebase
cd ./firebase
echo $(ls -al)
aws s3 cp --region ap-northeast-2 s3://${{ secrets.S3_BUCKET_PATH }}/motivoo-firebase-adminsdk.json .
echo $(ls -al; pwd)
shell: bash
- name: Gradle Properties 파일 생성
run: |
echo "${{ secrets.GRADLE_PROPERTIES }}" > ./local.properties
working-directory: ${{ env.working-directory }}
- name: 빌드
run: |
chmod +x gradlew
./gradlew motivoo-api:bootJar
working-directory: ${{ env.working-directory }}
shell: bash
- name: Docker 빌드 환경 설정
uses: docker/[email protected]
- name: Docker Hub에 로그인
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN }}
- name: Docker Image 빌드 및 푸시
run: |
docker build --platform linux/amd64 -f Dockerfile-API -t yejunpark1/motivoo-api-server .
docker push yejunpark1/motivoo-api-server
- name: deploy.sh EC2 인스턴스로 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
source: "./scripts/api/deploy.sh"
target: "/home/ubuntu/api-server/"
- name: docker-compose.yml EC2 인스턴스로 전송
uses: appleboy/scp-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
source: "./docker-compose-api.yml"
target: "/home/ubuntu/"
deploy-cd: # job#2
needs: deploy-ci
runs-on: ubuntu-22.04
steps: # EC2 인스턴스 내부에서 이루어지는 작업
- name: 도커 컨테이너 실행 및 이미지 Pull
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
script: |
cd ~
sudo docker pull yejunpark1/motivoo-api-server
sudo chmod 777 ./deploy-api.sh
cp ./api-server/scripts/api/deploy.sh ./deploy-api.sh
./deploy-api.sh
docker image prune -f