-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (96 loc) · 3.98 KB
/
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
# 워크플로우의 이름 지정
name: GUNBBANG-SERVER CD
# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정
on:
push:
branches: [ dev ] # main branch로 push 될 때 실행됩니다.
env:
S3_BUCKET_NAME: gunbbang-bucket-release
jobs:
build:
name: Code deployment
# 실행 환경
runs-on: ubuntu-latest
steps:
# 1) 워크플로우 실행 전 기본적으로 체크아웃 필요
- name: checkout
uses: actions/checkout@v3
# 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# 3) 환경변수 파일 생성
- name: make application.properties 파일 생성
run: |
pwd
## create application.yml in api module
mkdir ./api/src/main/resources
cd ./api/src/main/resources
touch ./application.yml
ls -al
cd /home/runner/work/GEON-PPANG-SERVER/GEON-PPANG-SERVER
## create application.yml in client module
mkdir ./client/client-feign/src/main/resources
cd ./client/client-feign/src/main/resources
touch ./application.yml
touch ./client.yml
ls -al
cd /home/runner/work/GEON-PPANG-SERVER/GEON-PPANG-SERVER
## create application.yml in storage module
mkdir ./storage/db-core/src/main/resources
cd ./storage/db-core/src/main/resources
touch ./application.yml
touch ./db-core.yml
ls -al
cd /home/runner/work/GEON-PPANG-SERVER/GEON-PPANG-SERVER
pwd
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
echo "${{ secrets.GUNBBANG_SECRET_API_APPLICATION_YML }}" >> ./api/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE_APPLICATION_YML }}" >> ./storage/db-core/src/main/resources/application.yml
echo "${{ secrets.GUNBBANG_SECRET_DB_CORE }}" >> ./storage/db-core/src/main/resources/db-core.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT }}" >> ./client/client-feign/src/main/resources/client.yml
echo "${{ secrets.GUNBBANG_SECRET_CLIENT_APPLICATION_YML }}" >> ./client/client-feign/src/main/resources/application.yml
pwd
shell: bash
# 이 워크플로우는 gradle build
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외)
run: ./gradlew build -x test
# 디렉토리 생성
- name: Make Directory
run: mkdir -p deploy
# Jar 파일 복사
- name: Copy Jar
run: cp ./api/build/libs/*.jar ./deploy
# appspec.yml 파일 복사
- name: Copy appspec.yml
run: cp appspec.yml ./deploy
# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy
- name: Make zip file
run: zip -r ./gunbbang_server.zip ./deploy
shell: bash
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.GUNBBANG_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.GUNBBANG_AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./gunbbang_server.zip s3://$S3_BUCKET_NAME/
# Deploy
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.GUNBBANG_AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.GUNBBANG_AWS_SECRET_KEY }}
run:
aws deploy create-deployment
--application-name gunbbang-server-codedeploy
--deployment-group-name gunbbang-server-codedeploy-group
--file-exists-behavior OVERWRITE
--s3-location bucket=gunbbang-bucket-release,bundleType=zip,key=gunbbang_server.zip
--region ap-northeast-2