Skip to content

Commit 511500f

Browse files
committed
wrote deploy script for UI and deployed v0.0.4
1 parent bf0eeb4 commit 511500f

5 files changed

Lines changed: 211 additions & 3 deletions

File tree

Binary file not shown.

ui/package-lock.json

Lines changed: 168 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "eqmac",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"scripts": {
55
"start": "ng serve",
66
"build": "ng build --prod",
77
"package": "npm run build && cd dist/ && zip -r -D ../ui.zip * -x '*.DS_Store'",
8-
"deploy": "cd ../ && CI_COMMIT_SHA=latest CI_COMMIT_MESSAGE='deploying from VSCode (production) --deploy=ui' CI_COMMIT_REF_NAME=master ./node_modules/.bin/ts-node ./ci/base.ts"
8+
"deploy": "export $(egrep -v '^#' .env | xargs) && ./scripts/deploy.sh",
9+
"purge-cache": "./node_modules/.bin/ts-node -O '{\"module\":\"commonjs\"}' ./scripts/purge-cache.ts"
910
},
1011
"private": true,
1112
"dependencies": {
@@ -38,7 +39,10 @@
3839
"@types/google.analytics": "0.0.40",
3940
"@types/js-cookie": "^2.2.6",
4041
"@types/node": "~12.7.11",
42+
"axios": "^0.19.2",
43+
"cloudflare": "^2.7.0",
4144
"codelyzer": "~5.1.2",
45+
"dotenv": "^8.2.0",
4246
"ts-node": "~8.4.1",
4347
"tslint": "~5.20.0",
4448
"tslint-config-standard": "^8.0.1",

ui/scripts/deploy.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -e
3+
4+
VERSION=$(node -e "const [ major, minor ] = require('./package.json').version.split('.');console.log([major, minor, 0].join(''))")
5+
DOMAIN=ui-v$VERSION.eqmac.app
6+
7+
npm run build
8+
9+
gcloud config set account $GCLOUD_ACCOUNT
10+
gcloud config set project $GCLOUD_PROJECT_ID
11+
12+
gsutil -m cp -z js,css,html -r dist/* gs://$DOMAIN
13+
gsutil -m setmeta -h "Content-Type:text/html;charset=utf-8" gs://$DOMAIN/**/*.html
14+
gsutil iam ch allUsers:objectViewer gs://$DOMAIN
15+
16+
./node_modules/.bin/ts-node -O '{"module":"commonjs"}' ./scripts/purge-cache.ts || echo "❌ Failed to purge Cloudflare cache"

ui/scripts/purge-cache.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Cloudflare from 'cloudflare'
2+
import { config as InjectEnvs } from 'dotenv'
3+
import { version } from '../package.json'
4+
5+
InjectEnvs()
6+
7+
const cf = Cloudflare({
8+
token: process.env.CLOUDFLARE_TOKEN
9+
})
10+
11+
;(async () => {
12+
const [ major, minor ] = version.split('.')
13+
const domain = `https://ui-v${major}${minor}0.eqmac.app`
14+
await cf.zones.purgeCache(process.env.CLOUDFLARE_ZONE_ID, {
15+
files: [ domain ]
16+
})
17+
console.log(`🧹 Cloudflare cache successfully cleared for domain ${domain}`)
18+
})().catch(err => {
19+
console.error(err)
20+
process.exit(1)
21+
})

0 commit comments

Comments
 (0)