-
Notifications
You must be signed in to change notification settings - Fork 5
81 lines (68 loc) Β· 2.19 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
name: Deploy To EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./BE # BE λλ ν 리λ₯Ό μμ
λλ ν λ¦¬λ‘ μ€μ
steps:
- name: Github Repository νμΌ λΆλ¬μ€κΈ°
uses: actions/checkout@v4
- name: Node μ€μΉ
uses: actions/setup-node@v4
with:
node-version: "20"
- name: μμ‘΄μ±(λΌμ΄λΈλ¬λ¦¬) μ€μΉ
run: npm ci
- name: .env νμΌ λ§λ€κΈ°
run: |
echo '${{ secrets.ENV }}' > .env
- name: ν
μ€νΈ μ½λ μ€ν
run: npm run test
- name: λΉλ
run: npm run build
- name: github-action μ»΄ν¨ν°μμ μμΆνκΈ°
run: |
# νμ¬ μμΉ νμΈ (λλ²κΉ
μ©)
pwd
# BEμ FE λͺ¨λ νμ νμΌλ€μ ν¨κ» μμΆ
tar -czvf project.tar.gz \
BE/dist \
BE/package.json \
BE/package-lock.json \
BE/.env \
FE/build \
FE/package.json \
FE/package-lock.json \
FE/.env
# μμΆ νμΌ λ΄μ© νμΈ (λλ²κΉ
μ©)
echo "Created archive with contents:"
tar -tvf project.tar.gz
- name: SCPλ‘ EC2μ λΉλλ νμΌ μ μ‘νκΈ°
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: project.tar.gz
target: /root/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 /root/nest-server/current
mkdir /root/nest-server/current
mv /root/nest-server/tobe/project.tar.gz /root/nest-server/current/project.tar.gz
cd /root/nest-server/current
tar -xvf project.tar.gz
npm i
pm2 kill
pm2 start dist/main.js --name "backend-server"