-
Notifications
You must be signed in to change notification settings - Fork 2
202 lines (175 loc) · 5.86 KB
/
build-release.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build And Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
build-backend:
runs-on: ubuntu-20.04
env:
SQLX_VERSION: ^0.6.2
SQLX_FEATURES: rustls postgres
APP_URL: 127.0.0.1
APP_PORT: 8080
EDITOR_PORT: 4040
DATABASE_USER: username
DATABASE_PASSWORD: password
DATABASE_NAME: database
DATABASE_PORT: 5432
DATABASE_HOST: localhost
DATABASE_URL: postgres://username:password@localhost/database
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
POSTGRES_DB: database
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache dependencies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
backend/target/
key: ${{ runner.os }}-cargo-dependencies-${{ hashFiles('**/Cargo.lock') }}
- name: ⚡ Cache sqlx-cli
uses: actions/cache@v2
id: cache-sqlx
with:
path: |
~/.cargo/bin/sqlx
~/.cargo/bin/cargo-sqlx
key: ${{ runner.os }}-cargo-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }}
- name: Install sqlx-cli
if: steps.cache-sqlx.outputs.cache-hit == false
run: cargo install sqlx-cli --force --version ${{ env.SQLX_VERSION }} --no-default-features --features "${{ env.SQLX_FEATURES }}"
- name: Migrate database
run: SKIP_DOCKER=true ./init_db.sh
working-directory: backend
- name: 🔨 Build
run: cargo build --release --verbose
working-directory: backend
- name: 🧪 Test
run: cargo test
working-directory: backend
- name: tar files to keep permissions
run: |
mv target/release/climate_risk_map ./
tar -cvf backend.tar climate_risk_map migrations
working-directory: backend
- uses: actions/upload-artifact@v2
with:
name: backend
path: backend/backend.tar
build-frontend:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: "20"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
working-directory: frontend
- name: ⚡ Cache yarn dependencies
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', 'frontend/.yarnrc.yml') }}
restore-keys: |
yarn-cache-folder-
- name: 🔨 Build
run: |
yarn install --immutable
yarn lint
yarn build
working-directory: frontend
- name: 🧪 Test
run: yarn test
working-directory: frontend
- uses: actions/upload-artifact@v2
with:
name: frontend
path: frontend/build
deploy-development:
if: github.event_name == 'pull_request'
environment:
name: development
url: https://svante3.mit.edu
needs: [build-backend, build-frontend]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v2
with:
path: ${{ github.event.pull_request.head.sha }}
- name: extract backend
run: |
tar -xvf backend.tar
rm backend.tar
working-directory: ${{ github.event.pull_request.head.sha }}/backend
- name: deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ${{ github.event.pull_request.head.sha }}
target: ~/builds/
- name: run on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: >
podman pod start crm_pod &&
podman stop crm_backend &&
ln -snf ~/builds/${{ github.event.pull_request.head.sha }} ~/climate-risk-map &&
podman run --rm -v ~/climate-risk-map/backend:/opt/climate-risk-map/backend:Z --tz=America/New_York --env-file=$HOME/.env --pod=crm_pod sqlx database reset -y &&
podman start crm_backend
deploy-production:
if: github.event_name == 'push'
environment:
name: production
url: https://est.mit.edu
needs: [build-backend, build-frontend]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v2
with:
path: ${{ github.sha }}
- name: extract backend
run: |
tar -xvf backend.tar
rm backend.tar
working-directory: ${{ github.sha }}/backend
- name: deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ${{ github.sha }}
target: ~/builds/
- name: run on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: >
podman stop crm_backend &&
ln -snf ~/builds/${{ github.sha }} ~/climate-risk-map &&
podman run --rm -v ~/climate-risk-map/backend:/opt/climate-risk-map/backend:Z --tz=America/New_York --env-file=$HOME/.env --pod=crm_pod sqlx migrate run &&
podman start crm_backend