@invisible/deploy v1.0.13
deploy
Module to help deploy and run Google App Engine projects with features like:
- Deploy multiple services for production and staging.
- Sync static files from your PC to Google Storage and to App instances.
Install
npm install @invisible/deploy
# or
yarn add @invisible/deployMake sure to install as a normal dependency, since part of it is run on the deployed instance, and dev-dependencies are not installed on production.
Prerequisites
- Create a project https://console.cloud.google.com and note the project ID.
- Install the
gcloudsdk https://cloud.google.com/sdk/downloads - If this is your first time using the gcloud sdk make sure to run
gcloud auth login - From your project directory, run
gcloud app create --project=your-project-id --region=us-central
Setting up
- Create an
.envfile in your project's root folder. Add yourGCLOUD_PROJECTenvironment variable to it. Don't setPORTin yourstaging/.envorproduction/.env, GAE will set this for you.
GCLOUD_PROJECT=gae-project-id-1a6stdThis will be used to sync your local storage files to the bucket.
Run
./node_modules/.bin/deploy setupto create the backend bucket on Google Cloud.Create a folder named
storageon your project's root folder. Inside this folder you should have one folder for each services you want to deploy. In each folder you should store the files you want to sync in your instances.
// Storing environment files for production and staging:
storage
├── production
│ └── .env
└── staging
└── .envAdd
storageto your.gitignorefile.Create an GAE yaml config file for each environment you want to have.
# production.yaml
service: default
runtime: nodejs
env: flex
skip_files:
- ^node_modules$
- ^ignore$
- ^.env$# staging.yaml
service: staging
runtime: nodejs
env: flex
skip_files:
- ^node_modules$
- ^ignore$
- ^.env$
manual_scaling:
instances: 1- Add sync to your
prestarthook onpackage.json:
// package.json
"scripts": {
"prestart": "./node_modules/.bin/sync",
...
}Make sure you already have a
defaultservice running before you deploy any other. You can deploy to production with./node_modules/.bin/deploy production.If you are experience a bug, it might be a problem with the
--quietflag, so try running the commandgcloud app deploy production.yaml --project=your-project-id --promote
Commands
deploy
Usage:
deploy [setup|download|static|production|staging|branchName]Argument can be:
setupCreates the default backend bucket for this project.downloadDownloads all static files from the backend bucket.staticUploads all static files to the backend bucket.branchNameUploads branch static files and deploys the App to Google App Engine based onbranchName.yamlfile.
sync
Usage: Add ./node_modules/.bin/sync as the value of scripts.prestart on your package.json.
Retrieve files from your project's backend bucket and place it on current instance's root folder.