-
Notifications
You must be signed in to change notification settings - Fork 2
86 lines (72 loc) · 2.59 KB
/
deployment.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
name: Deploy to Production
on:
push:
branches:
- release
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.set_output.outputs.should_run }}
steps:
- name: Check if actor is authorized
id: set_output
run: |
if [[ ",${{ secrets.AUTHORIZED_USERS }}," == *",${{ github.actor }},"* ]]; then
echo "Actor is authorized"
echo "should_run=true" >> $GITHUB_ENV
else
echo "Actor is not authorized"
echo "should_run=false" >> $GITHUB_ENV
fi
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 16.20.0
cache: "yarn"
# - name: Run tests
# env:
# NODE_OPTIONS: "--max-old-space-size=20480"
# run: |
# yarn env:switch:dev
# yarn test:ci
- name: Setup production credentials
run: |
yarn env:switch:prod
echo "${{ secrets.API_ENV }}" > .env
- name: Prepare, build and push Docker image
run: |
# Prepare: install dependencies, build and lint
yarn install
yarn tsc && yarn lint
# Build the Docker image on Github cloud
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t laundrobot/laundrobot-team:api-latest .
docker push laundrobot/laundrobot-team:api-latest
- name: SSH into VPS and update containers
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_KEY }} #! SSH private key
passphrase: ${{ secrets.VPS_PASSPHRASE }}
script: |
# Update Docker image on the VPS
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull laundrobot/laundrobot-team:api-latest
# Fix to avoid npm not found (applyboy/ssh-action bug)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Update repository code
cd ~/laundrobot/api
# Clean untracked files if any
git clean -fd
git checkout release
git pull origin release
bash ~/laundrobot/api/environment/api-refresh-containers.sh