-
Notifications
You must be signed in to change notification settings - Fork 2
144 lines (119 loc) · 4.03 KB
/
deploy-prod-by-realease-tag.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
# 운영서버 배포 워크플로우
# 백엔드 + 프런트엔드 동시 배포
name: deploy production by tag
on:
workflow_dispatch:
inputs:
version:
description: "배포할 Version Tag"
required: true
type: string
permissions:
contents: read
jobs:
build-backend:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: backend
steps:
- name: Set up Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "corretto"
- name: Give permission for Gradle
run: chmod +x gradlew
- name: Cache Gradle
id: cache-gradle
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew bootJar
- name: Upload jar file artifact
uses: actions/upload-artifact@v4
with:
name: BackendApplicationJar
path: backend/build/libs/*.jar
build-frontend:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: frontend
steps:
- name: Set up Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
- name: Setup node with cache
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Setup environment variables
run: |
echo "REACT_APP_BASE_URL=${{ secrets.REACT_APP_PROD_BASE_URL }}" >> .env
- name: Install dependencies
run: npm ci
- name: Build App
run: npm run build:prod
- name: Upload frontend build file to artifact
uses: actions/upload-artifact@v4
with:
name: FrontendApplication
path: frontend/dist
deploy:
needs: [build-frontend, build-backend]
runs-on: self-hosted
env:
BACK_DEPLOY_SCRIPT: ${{ secrets.PROD_BACK_DEPLOY_SCRIPT }}
CLOUD_FRONT_DISTRIBUTION_ID: ${{ secrets.CLOUD_FRONT_PROD_DISTRIBUTION_ID}}
steps:
- name: Remove previous version FRONT app
working-directory: frontend/prod/
run: rm -rf dist
- name: Download FRONT build file from artifact
uses: actions/download-artifact@v4
with:
name: FrontendApplication
path: frontend/prod/dist
- name: Remove previous version BACK jar
working-directory: backend/prod/
run: rm -f team-by-team-*.jar
- name: Init Checkout for get property
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
submodules: true
token: ${{ secrets.TBT_REPO_TOKEN }}
path: backend/prod/
sparse-checkout: |
backend/src/main/resources/security
- name: Download BACK jar file from artifact
uses: actions/download-artifact@v4
with:
name: BackendApplicationJar
path: backend/prod/
- name: Move prod application.yml
working-directory: backend/prod/
run: cp backend/src/main/resources/security/application-prod.yml ./
- name: Deploy BACK to production server
working-directory: backend/prod/
run: |
echo "$BACK_DEPLOY_SCRIPT" > prod-deploy.sh
chmod 700 prod-deploy.sh
./prod-deploy.sh
- name: Deploy FRONT to production server
working-directory: frontend/prod/
run: |
aws s3 sync ./dist/ s3://team-by-team-static-resource/prod/front --delete
aws cloudfront create-invalidation --distribution-id "$CLOUD_FRONT_DISTRIBUTION_ID" --paths "/*"