Skip to content

Commit

Permalink
Support deploy GAE
Browse files Browse the repository at this point in the history
  • Loading branch information
coinconket committed Apr 11, 2022
1 parent e2673d6 commit bbbf2b8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cloudbuild/app-engine.yaml
@@ -0,0 +1,40 @@
steps:
- name: node:16-bullseye
entrypoint: npm
args: ['install']

- name: node:16-bullseye
entrypoint: npm
args: ['run', 'lint', '${_SERVICE_NAME}']

- name: node:16-bullseye
entrypoint: npm
args: ['run', 'test', '${_SERVICE_NAME}']

- name: node:16-bullseye
entrypoint: npm
args:
['run', 'build', '${_SERVICE_NAME}', '--', '--configuration=production']

- name: node:16-bullseye
entrypoint: bash
args:
[
'-c',
'node tools/prepare-gcp-app-engine.js --serviceName=${_SERVICE_NAME}',
]

- name: gcr.io/google.com/cloudsdktool/cloud-sdk:376.0.0-slim
dir: dist/apps/${_SERVICE_NAME}
entrypoint: gcloud
args:
- app
- deploy
- app-engine.yaml
- --version=$SHORT_SHA
- --promote
- --stop-previous-version
- --quiet

substitutions:
_SERVICE_NAME: game-api
33 changes: 33 additions & 0 deletions tools/prepare-gcp-app-engine.js
@@ -0,0 +1,33 @@
const fs = require('fs');
const path = require('path');
const yargs = require('yargs/yargs');
console.log('Prepare GCP App Engine: ', new Date().toISOString());

const { serviceName } = yargs(process.argv).argv;
if (!serviceName) {
console.error('Missing serviceName args. Eg: --serviceName=explore-api');
process.exit(1);
}

const PACKAGE_PATH = path.join('dist', 'apps', serviceName, 'package.json');

function main() {
const packageJson = fs.readFileSync(PACKAGE_PATH).toString();
const scripts = {
start: 'node main.js',
};

const newPackageJson = {
...JSON.parse(packageJson),
scripts,
};

fs.writeFileSync(PACKAGE_PATH, JSON.stringify(newPackageJson, null, 2));

console.log(
'Updated package.json: ',
fs.readFileSync(PACKAGE_PATH).toString()
);
}

main();

0 comments on commit bbbf2b8

Please sign in to comment.