-
Notifications
You must be signed in to change notification settings - Fork 3
167 lines (142 loc) · 4.89 KB
/
deploy_server_dev.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Deploy Server Development
on:
push:
branches: [develop]
env:
LANG: "ko_KR.UTF-8"
LANGUAGE: "ko_KR.UTF-8"
LC_ALL: "ko_KR.UTF-8"
jobs:
deploy_development:
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Seoul"
- name: Set Locale
run: |
sudo locale-gen ko_KR.UTF-8
sudo update-locale LANG=ko_KR.UTF-8
- 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: ap-northeast-2
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Setup JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
- name: Create Cache Docker Image Directory
run: mkdir -p ~/db-docker-image
- name: Check Gradle Cache
id: cache
run: |
RESULT=$(curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}" \
"${{ secrets.CACHE_PATH }}-1")
if [[ $RESULT == *"created_at"* ]]
then
echo "new=2" >> $GITHUB_OUTPUT
echo "old=1" >> $GITHUB_OUTPUT
else
echo "new=1" >> $GITHUB_OUTPUT
echo "old=2" >> $GITHUB_OUTPUT
fi
- name: Cache DB Docker Image
id: db-docker-image
uses: actions/cache@v3
with:
path: ~/db-docker-image
key: db-docker-image-${{ runner.os }}
- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ steps.cache.outputs.new }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Pull DB Image From ECR
if: steps.db-docker-image.outputs.cache-hit != 'true'
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker pull $ECR_REGISTRY/keeper-homepage-db:${{ secrets.KEEPER_DB_TAG }}
docker save -o \
~/db-docker-image/keeper-homepage-db.tar \
$ECR_REGISTRY/keeper-homepage-db:${{ secrets.KEEPER_DB_TAG }}
- name: Create Env File
working-directory: ./docker
run: |
touch .env
echo "${{ secrets.DOCKER_ENV }}" >> .env
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> .env
- name: Create application.properties
working-directory: ./src/main/resources
run: |
touch application.properties
echo '${{ secrets.APPLICATION_PROPERTIES }}' >> application.properties
echo '${{ secrets.APPLICATION_PROPERTIES_DEPLOY }}' >> application-deploy.properties
- name: Start Containers
working-directory: ./docker
run: docker-compose -p keeper up -d
- name: Build
run: |
./gradlew build --daemon --build-cache --parallel
java -Djarmode=layertools -jar build/libs/homepage-0.0.1-SNAPSHOT.jar extract
- name: Compress
run: |
tar -zcvf ${GITHUB_SHA::8}.tar.gz \
dependencies \
snapshot-dependencies \
spring-boot-loader \
application
- name: Upload to S3
run: |
aws s3 mv --region ap-northeast-2 \
${GITHUB_SHA::8}.tar.gz \
${{ secrets.S3_DEV_BACK_LOCATION }}/${GITHUB_SHA::8}.tar.gz
- name: Update Test Result
if: failure()
run: |
aws s3 cp --region ap-northeast-2 --recursive \
build/reports/tests/test \
${{ secrets.S3_TEST_REPORT }} --recursive
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME_DEV }}
port: ${{ secrets.PORT_DEV }}
key: ${{ secrets.KEY_DEV }}
envs: GITHUB_SHA
script: |
cd ~/keeper/deploy
./deploy_server.sh ${GITHUB_SHA::8}
- name: Notify Slack
if: always()
uses: 8398a7/action-slack@v3
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
status: ${{ job.status }}
author_name: Keeper Devlopment Backend CICD
fields: repo, commit, message, author, job, took
- name: Delete Previous Gradle Cache
run: |
curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TOKEN }}" \
"${{ secrets.CACHE_PATH }}-${{ steps.cache.outputs.old }}"