-
-
Notifications
You must be signed in to change notification settings - Fork 281
98 lines (85 loc) · 3.02 KB
/
cd.yaml
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
87
88
89
90
91
92
93
94
95
96
97
98
name: Continuous Deployment Workflow
# This workflow is triggered whenever commits are pushed to the main branch
on:
push:
branches:
- 'main'
paths:
- 'web/**'
workflow_dispatch:
defaults:
run:
shell: bash
# Define the working directory for all run steps in the workflow
working-directory: ./web
jobs:
# ======================================================
# Deploy the main branch to staging
#
# It's important to test the main branch in staging
# before going to production with it.
# ======================================================
deploy_staging:
environment: staging
name: 'Deploy to staging'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: 'Checkout repository'
- uses: burnett01/rsync-deployments@23a557dceb19f9bb960ef40cf75cab5e9b37ec1f
name: 'Deploy to staging'
with:
switches: -avzr --delete
path: ./web
remote_path: /var/app
remote_host: ${{ secrets.HOSTNAME }}
remote_user: ${{ secrets.REMOTE_USER }}
remote_key: ${{ secrets.SSH_PRIVATE_KEY }}
- uses: JimCronqvist/action-ssh@7737f1192ddd8376686e9d6354dea44592c942bf
name: Execute SSH commmands on remote server
with:
hosts: '${{ secrets.REMOTE_USER }}@${{ secrets.HOSTNAME }}'
privateKey: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
cd /var/app/web
npm ci
pm2 start /var/app/web/bin/www || pm2 restart /var/app/web/bin/www
sudo service nginx restart
# ======================================================
# Deploy the main branch to production
#
# This job will require the `deploy_staging` job to
# run and complete successfully first!
#
# WARNING: this job will sync all the files that are
# in the folder ./web/ to the production server
# while removing all the files that are already
# in the production server!
# ======================================================
deploy_production:
environment: production
name: 'Deploy to production'
runs-on: ubuntu-latest
needs: deploy_staging
steps:
- uses: actions/checkout@v2
name: 'Checkout repository'
- uses: burnett01/rsync-deployments@23a557dceb19f9bb960ef40cf75cab5e9b37ec1f
name: 'Deploy to production'
with:
switches: -avzr --delete
path: ./web
remote_path: /var/app
remote_host: ${{ secrets.HOSTNAME }}
remote_user: ${{ secrets.REMOTE_USER }}
remote_key: ${{ secrets.SSH_PRIVATE_KEY }}
- uses: JimCronqvist/action-ssh@7737f1192ddd8376686e9d6354dea44592c942bf
name: Execute SSH commmands on remote server
with:
hosts: '${{ secrets.REMOTE_USER }}@${{ secrets.HOSTNAME }}'
privateKey: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
cd /var/app/web
npm ci
pm2 start /var/app/web/bin/www || pm2 restart /var/app/web/bin/www
sudo service nginx restart