-
Notifications
You must be signed in to change notification settings - Fork 5
128 lines (109 loc) Β· 3.61 KB
/
deploy.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
name: Deploy To EC2
on:
push:
branches: [ "release" ]
env:
NODE_ENV: test #μ΄κ±Έ λ°κΎΈλ©΄ BE λΉλκ° μλ¨
DB_HOST_TEST: localhost
DB_PORT_TEST: 3306
DB_PASSWD_TEST: test
DB_NAME_TEST: test_db
jobs:
deploy:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test_db
MYSQL_ROOT_HOST: '%' # λͺ¨λ νΈμ€νΈμμ μ κ·Ό νμ©
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
redis:
image: redis
ports:
- 6379:6379
steps:
- name: Github Repository νμΌ λΆλ¬μ€κΈ°
uses: actions/checkout@v4
- name: Node μ€μΉ
uses: actions/setup-node@v4
with:
node-version: "20"
- name: BE μμ‘΄μ± μ€μΉ
working-directory: ./BE
run: npm ci
- name: FE μμ‘΄μ± μ€μΉ
working-directory: ./FE
run: npm ci
- name: .env νμΌ λ§λ€κΈ°
run: |
echo '${{ secrets.ENV }}' > .env
# - name: BE ν
μ€νΈ μ½λ μ€ν (unit test)
# working-directory: ./BE
# run: npm run test
# - name: BE ν
μ€νΈ μ½λ μ€ν2 (integration test)
# working-directory: ./BE
# run: npm run test:integration
# todo: FE ν
μ€νΈ μ½λ μ€ν 2
# - name: FE ν
μ€νΈ μ½λ μ€ν
# working-directory: ./FE
# run: npm run test
- name: BE λΉλ
working-directory: ./BE
run: npm run build
- name: FE λΉλ
working-directory: ./FE
run: npm run build
- name: github-action μ»΄ν¨ν°μμ μμΆνκΈ°
run: |
# BEμ FE λͺ¨λ νμ νμΌλ€μ ν¨κ» μμΆ
tar -czvf project.tar.gz \
BE/dist \
BE/package.json \
BE/package-lock.json \
BE/ecosystem.config.js \
.env \
FE/dist \
FE/package.json \
FE/package-lock.json \
- name: Rsyncλ‘ EC2μ λΉλλ νμΌ μ μ‘νκΈ°
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
rsync -avz project.tar.gz \
ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/nest-server/tobe/
- name: SSHλ‘ EC2μ μ μνκΈ°
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
rm -rf /home/ubuntu/nest-server/current
mkdir /home/ubuntu/nest-server/current
mv /home/ubuntu/nest-server/tobe/project.tar.gz /home/ubuntu/nest-server/current/project.tar.gz
cd /home/ubuntu/nest-server/current
tar -xvf project.tar.gz
cd /home/ubuntu/nest-server/current/BE
npm i
cd
cd /home/ubuntu/nest-server/current/FE
npm i
npx pm2 delete quiz-ground-was1 quiz-ground-was2 || true
cd /home/ubuntu/nest-server/current/BE
npx pm2 start ecosystem.config.js
# todo: # FrontEnd λ°°ν¬
# # Frontend λ°°ν¬
# echo "Deploying Frontend..."
# sudo rm -rf /var/www/html/*
# sudo cp -r ../FE/dist/* /var/www/html/