-
Notifications
You must be signed in to change notification settings - Fork 1
121 lines (114 loc) · 4 KB
/
build_and_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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: PGIS Toolkit Frontend
on:
push:
branches:
- '*'
workflow_dispatch:
jobs:
build:
name: Build Static Files
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Use Node.js 12.22.12
uses: actions/setup-node@v1
with:
node-version: 12.22.12
- name: Cache node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Write Environment Variables
id: write_env
run: |
set -e
case "${{ github.ref }}" in
refs/heads/staging)
cat > .env <<EOF
#STAGING MODE
TITLE=USAFIRI
BASE_URL=https://pgis.naxa.com.np/api
USERS_URL=https://pgis.naxa.com.np/api
ASSETS_URL=https://pgis.naxa.com.np
API_URL=https://pgis.naxa.com.np/api/v1
DASHBOARD_API_URL=https://pgis.naxa.com.np/api/v2
LOGIN_API_URL=https://pgis.naxa.com.np/api
BIPAD_API_URL=https://bipadportal.gov.np/api/v1
TOKEN=${{ secrets.ENV_SECRET }}
EOF
;;
refs/heads/master)
cat > .env <<EOF
#PROD MODE
TITLE=USAFIRI
BASE_URL=https:///app.usafiri.io/api
USERS_URL=https:///app.usafiri.io/api
ASSETS_URL=https:///app.usafiri.io
API_URL=https:///app.usafiri.io/api/v1
DASHBOARD_API_URL=https:///app.usafiri.io/api/v2
LOGIN_API_URL=https:///app.usafiri.io/api
BIPAD_API_URL=https://bipadportal.gov.np/api/v1
TOKEN=${{ secrets.ENV_SECRET }}
EOF
;;
esac
- name: Install dependencies
run: npm install --force
- name: Generate build
run: |
npm run build
- name: Upload Dist as Artifacts
uses: actions/upload-artifact@v3
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' }}
with:
name: Pgis-${{ github.ref_name }}
path: dist
retention-days: 2
deploy:
name: Deploy static files
needs:
- build
if: ${{ github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Get Artifacts
uses: actions/download-artifact@v1
with:
path: dist
name: Pgis-${{ github.ref_name }}
- name: Get VM SSH host and user
id: get_vm_conf
run: |
case "${{ github.ref }}" in
refs/heads/staging)
export SERVER_HOST=159.89.164.123
export SERVER_USERNAME=devops
export PROJECT_PATH=/srv/Projects/pgis-toolkit_frontend_staging/dist
;;
refs/heads/master)
export SERVER_HOST=13.39.95.193
export SERVER_USERNAME=ubuntu
export PROJECT_PATH=/home/ubuntu/Projects/pgis-toolkit_frontend_prod_landing/dist
;;
esac
echo "SERVER_HOST=${SERVER_HOST}" >> $GITHUB_OUTPUT
echo "SERVER_USERNAME=${SERVER_USERNAME}" >> $GITHUB_OUTPUT
echo "PROJECT_PATH=${PROJECT_PATH}" >> $GITHUB_OUTPUT
- name: Configure SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
ssh-keyscan ${{ steps.get_vm_conf.outputs.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: copy static files
run: |
scp -r ./dist/* ${{ steps.get_vm_conf.outputs.SERVER_USERNAME }}@${{ steps.get_vm_conf.outputs.SERVER_HOST }}:${{ steps.get_vm_conf.outputs.PROJECT_PATH }}
echo "Build Pass"