generated from Medici-Mansion/basic-template
-
Notifications
You must be signed in to change notification settings - Fork 1
49 lines (40 loc) · 1.32 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
name: Deploy to Lightsail
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20.11.1'
- name: Create .env file
run: |
echo '${{ secrets.ENV_FILE }}' > .env
- name: Install dependencies
run: yarn install
- name: Build the project
run: yarn build
- name: Archive production artifacts
run: tar -czf build.tar.gz dist node_modules .env
- name: Deploy to Lightsail
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
LIGHTSAIL_IP: ${{ secrets.LIGHTSAIL_IP }}
run: |
echo "$SSH_PRIVATE_KEY" > key.pem
chmod 600 key.pem
scp -o StrictHostKeyChecking=no -i key.pem build.tar.gz $SSH_USERNAME@$LIGHTSAIL_IP:~/build.tar.gz
ssh -o StrictHostKeyChecking=no -i key.pem $SSH_USERNAME@$LIGHTSAIL_IP << 'EOF'
cd ~/
pm2 stop all || true
if [ -d dist ]; then rm -rf dist; fi
tar -xzf build.tar.gz
if [ -f build.tar.gz ]; then rm build.tar.gz; fi
pm2 start dist/main.js --env .env