-
Notifications
You must be signed in to change notification settings - Fork 4
256 lines (226 loc) · 10.4 KB
/
temp-forestgeo-livesite.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
name: ForestGEO Live Site Deployment Pipeline
on:
push:
branches:
- main
- 'forestgeo-app-*'
workflow_dispatch:
jobs:
# Production Job (only runs on main branch)
build-app-production:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
env:
AZURE_AD_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
AZURE_AD_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
AZURE_AD_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
AZURE_SQL_USER: ${{ secrets.AZURE_SQL_USER }}
AZURE_SQL_PASSWORD: ${{ secrets.AZURE_SQL_PASSWORD }}
AZURE_SQL_SERVER: ${{ secrets.AZURE_SQL_SERVER }}
AZURE_SQL_DATABASE: ${{ secrets.AZURE_SQL_DATABASE }}
AZURE_SQL_PORT: ${{ secrets.AZURE_SQL_PORT }}
AZURE_STORAGE_SAS_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_SAS_CONNECTION_STRING }}
AZURE_SQL_SCHEMA: ${{ secrets.AZURE_SQL_SCHEMA }}
AZURE_SQL_CATALOG_SCHEMA: ${{ secrets.AZURE_SQL_CATALOG_SCHEMA }}
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
NODE_ENV: production
PORT: 3000
FG_PAT: ${{ secrets.FG_PAT }}
OWNER: ${{ secrets.OWNER }}
REPO: ${{ secrets.REPO }}
steps:
- uses: actions/checkout@v4
- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: create env file (in frontend/ directory) -- production
id: create-env-file-prod
if: github.ref == 'refs/heads/main'
run: |
touch frontend/.env
echo AZURE_AD_CLIENT_SECRET=${{ secrets.AZURE_AD_CLIENT_SECRET }} >> frontend/.env
echo AZURE_AD_CLIENT_ID=${{ secrets.AZURE_AD_CLIENT_ID }} >> frontend/.env
echo AZURE_AD_TENANT_ID=${{ secrets.AZURE_AD_TENANT_ID }} >> frontend/.env
echo NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} >> frontend/.env
echo NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }} >> frontend/.env
echo AZURE_SQL_USER=${{ secrets.AZURE_SQL_USER }} >> frontend/.env
echo AZURE_SQL_PASSWORD=${{ secrets.AZURE_SQL_PASSWORD }} >> frontend/.env
echo AZURE_SQL_SERVER=${{ secrets.AZURE_SQL_SERVER }} >> frontend/.env
echo AZURE_SQL_DATABASE=${{ secrets.AZURE_SQL_DATABASE }} >> frontend/.env
echo AZURE_SQL_PORT=${{ secrets.AZURE_SQL_PORT }} >> frontend/.env
echo AZURE_STORAGE_SAS_CONNECTION_STRING=${{ secrets.AZURE_STORAGE_SAS_CONNECTION_STRING }} >> frontend/.env
echo AZURE_SQL_SCHEMA=${{ secrets.AZURE_SQL_SCHEMA }} >> frontend/.env
echo AZURE_SQL_CATALOG_SCHEMA=${{ secrets.AZURE_SQL_CATALOG_SCHEMA }} >> frontend/.env
echo AZURE_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} >> frontend/.env
echo NODE_ENV=production >> frontend/.env
echo PORT=3000 >> frontend/.env
echo FG_PAT=${{ secrets.FG_PAT }} >> frontend/.env
echo OWNER=${{ secrets.OWNER }} >> frontend/.env
echo REPO=${{ secrets.REPO }} >> frontend/.env
- name: Write Certificate to File
run: |
echo "${{ secrets.CERTIFICATE }}" > frontend/DigiCertGlobalRootCA.crt.pem
- name: check env vars
run: printenv | grep AZURE
- name: check node env
run: echo "NODE_ENV is $NODE_ENV"
- name: Cache node modules
uses: actions/cache@v2
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache Next.js build
uses: actions/cache@v2
with:
path: frontend/.next/cache
key: ${{ runner.os }}-next-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/.next/cache') }}
restore-keys: |
${{ runner.os }}-next-
${{ runner.os }}-next-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies, build, and test
run: |
cd frontend/
npm install
npm run build
npm run test --if-present
- name: Move directories into build/standalone to reduce app load
run: |
mv ./frontend/build/static ./frontend/build/standalone/build
mv ./frontend/public ./frontend/build/standalone
mv ./frontend/*.pem ./frontend/build/standalone/
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: app-build
path: frontend/build/standalone
# Development Job (runs on forestgeo-app-* branches)
build-app-development:
if: startsWith(github.ref, 'refs/heads/forestgeo-app-')
runs-on: ubuntu-latest
environment: development
env:
AZURE_AD_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
AZURE_AD_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
AZURE_AD_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_DEV_URL }}
AZURE_SQL_USER: ${{ secrets.AZURE_SQL_USER }}
AZURE_SQL_PASSWORD: ${{ secrets.AZURE_SQL_PASSWORD }}
AZURE_SQL_SERVER: ${{ secrets.AZURE_SQL_SERVER }}
AZURE_SQL_DATABASE: ${{ secrets.AZURE_SQL_DATABASE }}
AZURE_SQL_PORT: ${{ secrets.AZURE_SQL_PORT }}
AZURE_STORAGE_SAS_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_SAS_CONNECTION_STRING }}
AZURE_SQL_SCHEMA: ${{ secrets.AZURE_SQL_SCHEMA }}
AZURE_SQL_CATALOG_SCHEMA: ${{ secrets.AZURE_SQL_CATALOG_SCHEMA }}
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
NODE_ENV: development
PORT: 3000
FG_PAT: ${{ secrets.FG_PAT }}
OWNER: ${{ secrets.OWNER }}
REPO: ${{ secrets.REPO }}
steps:
- uses: actions/checkout@v4
- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: create env file (in frontend/ directory) -- development
id: create-env-file-dev
if: startsWith(github.ref, 'refs/heads/forestgeo-app-')
run: |
touch frontend/.env
echo AZURE_AD_CLIENT_SECRET=${{ secrets.AZURE_AD_CLIENT_SECRET }} >> frontend/.env
echo AZURE_AD_CLIENT_ID=${{ secrets.AZURE_AD_CLIENT_ID }} >> frontend/.env
echo AZURE_AD_TENANT_ID=${{ secrets.AZURE_AD_TENANT_ID }} >> frontend/.env
echo NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} >> frontend/.env
echo NEXTAUTH_URL=${{ secrets.NEXTAUTH_DEV_URL }} >> frontend/.env
echo AZURE_SQL_USER=${{ secrets.AZURE_SQL_USER }} >> frontend/.env
echo AZURE_SQL_PASSWORD=${{ secrets.AZURE_SQL_PASSWORD }} >> frontend/.env
echo AZURE_SQL_SERVER=${{ secrets.AZURE_SQL_SERVER }} >> frontend/.env
echo AZURE_SQL_DATABASE=${{ secrets.AZURE_SQL_DATABASE }} >> frontend/.env
echo AZURE_SQL_PORT=${{ secrets.AZURE_SQL_PORT }} >> frontend/.env
echo AZURE_STORAGE_SAS_CONNECTION_STRING=${{ secrets.AZURE_STORAGE_SAS_CONNECTION_STRING }} >> frontend/.env
echo AZURE_SQL_SCHEMA=${{ secrets.AZURE_SQL_SCHEMA }} >> frontend/.env
echo AZURE_SQL_CATALOG_SCHEMA=${{ secrets.AZURE_SQL_CATALOG_SCHEMA }} >> frontend/.env
echo AZURE_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} >> frontend/.env
echo NODE_ENV=development >> frontend/.env
echo PORT=3000 >> frontend/.env
echo FG_PAT=${{ secrets.FG_PAT }} >> frontend/.env
echo OWNER=${{ secrets.OWNER }} >> frontend/.env
echo REPO=${{ secrets.REPO }} >> frontend/.env
- name: Write Certificate to File
run: |
echo "${{ secrets.CERTIFICATE }}" > frontend/DigiCertGlobalRootCA.crt.pem
- name: check env vars
run: printenv | grep AZURE
- name: check node env
run: echo "NODE_ENV is $NODE_ENV"
- name: Cache node modules
uses: actions/cache@v2
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache Next.js build
uses: actions/cache@v2
with:
path: frontend/.next/cache
key: ${{ runner.os }}-next-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/.next/cache') }}
restore-keys: |
${{ runner.os }}-next-
${{ runner.os }}-next-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies, build, and test
run: |
cd frontend/
npm install
npm run build
npm run test --if-present
- name: Move directories into build/standalone to reduce app load
run: |
mv ./frontend/build/static ./frontend/build/standalone/build
mv ./frontend/public ./frontend/build/standalone
mv ./frontend/*.pem ./frontend/build/standalone/
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: app-build
path: frontend/build/standalone
deploy-app:
needs: [build-app-production, build-app-development]
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: app-build
path: frontend/build/standalone
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: app-build
path: frontend/build/standalone
# Deploy to production environment (runs only on main branch)
- name: 'Deploy to Azure Web App (main)'
if: github.ref == 'refs/heads/main'
uses: azure/webapps-deploy@v2
with:
app-name: 'forestgeo-livesite'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_852346BD764D45D08854E6679137F844 }}
package: ./frontend/build/standalone
# Deploy to development environment (runs on forestgeo-app-* branches)
- name: 'Deploy to Azure Web App (development)'
if: startsWith(github.ref, 'refs/heads/forestgeo-app-')
uses: azure/webapps-deploy@v2
with:
app-name: 'forestgeo-livesite'
slot-name: 'development'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_DEVELOPMENT }}
package: ./frontend/build/standalone