Skip to content

Commit 226f116

Browse files
authored
๐Ÿ‘ทci: EC2 ๋ฐฐํฌ์šฉ GitHub Actions ์›Œํฌํ”Œ๋กœ์šฐ ์ถ”๊ฐ€
1 parent 94083ff commit 226f116

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup SSH
17+
run: |
18+
mkdir -p ~/.ssh
19+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
20+
chmod 600 ~/.ssh/id_rsa
21+
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
22+
23+
- name: Deploy to EC2
24+
run: |
25+
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
26+
set -e
27+
cd ~/ssakssak-commit
28+
29+
echo "๐Ÿ“ฆ Pull latest code"
30+
git pull origin main
31+
32+
echo "๐Ÿ“ฆ Install dependencies"
33+
npm ci
34+
35+
echo "๐Ÿ— Build Next.js"
36+
npm run build
37+
38+
echo "๐Ÿš€ Reload PM2 apps"
39+
pm2 reload next-app || pm2 start npm --name "next-app" -- run start -- --port 3000
40+
pm2 reload ssakssak-worker || pm2 start npm --name "ssakssak-worker" -- run worker:start
41+
42+
pm2 save
43+
EOF

0 commit comments

Comments
ย (0)