-
-
Notifications
You must be signed in to change notification settings - Fork 19
50 lines (47 loc) · 1.6 KB
/
main.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
name: Deploy API
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: 'just-a-placeholder'
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.REMOTE_SERVER_ADDRESS }} >> ~/.ssh/known_hosts
- uses: actions/checkout@v2
- name: Build API
run: |
npm install
npm run build api
npx copyfiles -f apps/**/*.graphql libs/**/*.graphql dist/apps/api/graphql
- name: Zip artifacts
run: |
tar -czvf build.tar.gz dist/apps/api prisma/
- name: Send artifacts to remote
env:
REMOTE_SERVER_USER: ${{ secrets.REMOTE_SERVER_USER }}
REMOTE_SERVER_ADDRESS: ${{ secrets.REMOTE_SERVER_ADDRESS }}
run: |
rsync -azIv ./build.tar.gz $REMOTE_SERVER_USER@$REMOTE_SERVER_ADDRESS:/home/$REMOTE_SERVER_USER/flare/build.tar.gz
- name: Start API
uses: appleboy/ssh-action@master
env:
REMOTE_SERVER_USER: ${{ secrets.REMOTE_SERVER_USER }}
with:
host: ${{ secrets.REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.REMOTE_SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: REMOTE_SERVER_USER
script: |
cd /home/$REMOTE_SERVER_USER/flare
tar -xzvf build.tar.gz
npm run prod
pm2 stop flare
pm2 start dist/apps/api/main.js --name flare
rm -rf build.tar.gz