Skip to content

Commit

Permalink
Bring back transpiled builds for /server and /email_backend cloud fun…
Browse files Browse the repository at this point in the history
…ction deploys
  • Loading branch information
Stephen-ONeil committed Apr 30, 2021
1 parent 53ff3ca commit 24dd399
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 12 deletions.
1 change: 0 additions & 1 deletion email_backend/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// for Jest, which is lacking usable esModule support
{
"plugins": [
"@babel/plugin-transform-modules-commonjs",
Expand Down
2 changes: 1 addition & 1 deletion email_backend/.gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# explicitly include just what's actually required in the cloud function
!/package.json
!/package-lock.json
!/src/**
!/transpiled_build/**
!/templates/**
1 change: 1 addition & 0 deletions email_backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
npm-debug*
coverage/
*credentials*.json
transpiled_build/
data_extracts/
146 changes: 146 additions & 0 deletions email_backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion email_backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infobase-email-backend",
"main": "src/index.js",
"main": "transpiled_build/index.js",
"engines": {
"node": "14"
},
Expand All @@ -17,6 +17,7 @@
"nodemailer": "^6.2.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7",
"@babel/plugin-transform-modules-commonjs": "^7.3.1",
"@babel/preset-env": "^7.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# must run this scripts in the email_backend dir
set -e # will exit if any command has non-zero exit value

npm run build

source scripts/util/set_prod_env_vars.sh
source scripts/util/set_transient_secrets.sh # these trap EXIT to handle their own cleanup

scripts/util/build.sh

gcloud beta functions deploy prod-email-backend --max-instances 1 --project ${PROJECT} --region us-central1 --entry-point email_backend --stage-bucket email-backend-staging-bucket --runtime nodejs14 --trigger-http --env-vars-file $scratch/envs.yaml > /dev/null
gcloud alpha functions add-iam-policy-binding prod-email-backend --project ${PROJECT} --region us-central1 --member allUsers --role roles/cloudfunctions.invoker

source scripts//util/unset_prod_env_vars.sh
source scripts/util/unset_prod_env_vars.sh

exit
6 changes: 6 additions & 0 deletions email_backend/scripts/util/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

rm -rf transpiled_build

babel src/ --out-dir transpiled_build --copy-files --ignore node_modules
2 changes: 1 addition & 1 deletion email_backend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// entry-point, for both dev and GCF
// entry-point for GCF

import { run_email_backend } from "./email_backend.js";

Expand Down
1 change: 0 additions & 1 deletion server/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// for Jest, which is lacking usable esModule support
{
"plugins": [
"@babel/plugin-transform-modules-commonjs",
Expand Down
2 changes: 1 addition & 1 deletion server/.gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# explicitly include just what's actually required in the cloud function
!/package.json
!/package-lock.json
!/src/**
!/transpiled_build/**
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
npm-debug*
coverage
*credentials*.json
transpiled_build/

# for old local dev dbs, might still be generated if checking out an old commit
mongo/mongo.log
Expand Down
6 changes: 6 additions & 0 deletions server/deploy_scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

rm -rf transpiled_build

babel src/ --out-dir transpiled_build --copy-files --ignore node_modules
2 changes: 2 additions & 0 deletions server/deploy_scripts/ci_deploy_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ echo "USE_REMOTE_DB: '1'" >> ./envs.yaml

source ../scripts/ci_scripts/redact_env_vars_from_logging.sh "redact-start"

./deploy_scripts/build.sh

gcloud functions deploy $CIRCLE_BRANCH --entry-point app --stage-bucket api-staging-bucket --runtime nodejs14 --trigger-http --env-vars-file ./envs.yaml
gcloud alpha functions add-iam-policy-binding $CIRCLE_BRANCH --member allUsers --role roles/cloudfunctions.invoker

Expand Down
4 changes: 2 additions & 2 deletions server/deploy_scripts/prod_deploy_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# must run this deploy_scripts in root of api project
set -e # will exit if any command has non-zero exit value

npm run build

source deploy_scripts/set_prod_env_vars.sh
source deploy_scripts/set_transient_function_secrets.sh # these trap EXIT to handle their own cleanup

deploy_scripts/build.sh

gcloud functions deploy prod-api-${CURRENT_SHA} --project ${PROJECT} --region us-central1 --entry-point app --stage-bucket prod-api-staging-bucket --runtime nodejs14 --trigger-http --env-vars-file $scratch/envs.yaml > /dev/null
gcloud alpha functions add-iam-policy-binding prod-api-${CURRENT_SHA} --project ${PROJECT} --region us-central1 --member allUsers --role roles/cloudfunctions.invoker

Expand Down
Loading

0 comments on commit 24dd399

Please sign in to comment.