@naturalcycles/backend-lib 4.23.0 → 4.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/undeploy-gae.js +10 -1
- package/dist/deploy/backend.cfg.util.js +1 -3
- package/dist/deploy/deploy.util.d.ts +1 -1
- package/dist/deploy/deploy.util.js +2 -2
- package/dist/deploy/deployGae.d.ts +1 -1
- package/dist/deploy/deployGae.js +8 -4
- package/dist/deploy/deployPrepare.js +2 -2
- package/package.json +1 -3
- package/src/bin/undeploy-gae.ts +10 -1
- package/src/db/httpDBRequestHandler.ts +1 -1
- package/src/deploy/backend.cfg.util.ts +2 -3
- package/src/deploy/deploy.util.ts +5 -2
- package/src/deploy/deployGae.ts +11 -4
- package/src/deploy/deployPrepare.ts +3 -3
package/dist/bin/undeploy-gae.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
7
|
const deployGae_1 = require("../deploy/deployGae");
|
|
6
8
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
7
|
-
|
|
9
|
+
const { branch } = yargs_1.default.options({
|
|
10
|
+
branch: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
demandOption: true,
|
|
13
|
+
desc: `Because Github Actions delete event happens after the branch is already deleted - you need to pass it manually`,
|
|
14
|
+
},
|
|
15
|
+
}).argv;
|
|
16
|
+
await (0, deployGae_1.undeployGae)(branch);
|
|
8
17
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBackendCfg = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
7
5
|
const paths_cnst_1 = require("../paths.cnst");
|
|
8
6
|
const backendCfgSchema = nodejs_lib_1.AjvSchema.readJsonSync(`${paths_cnst_1.resourcesDir}/backendCfg.schema.json`, {
|
|
9
7
|
objectName: 'backend.cfg.yaml',
|
|
@@ -13,7 +11,7 @@ function getBackendCfg(projectDir = '.') {
|
|
|
13
11
|
(0, nodejs_lib_1.requireFileToExist)(backendCfgYamlPath);
|
|
14
12
|
const backendCfg = {
|
|
15
13
|
serviceWithBranchName: true,
|
|
16
|
-
...
|
|
14
|
+
...nodejs_lib_1.fs2.readYaml(backendCfgYamlPath),
|
|
17
15
|
};
|
|
18
16
|
backendCfgSchema.validate(backendCfg);
|
|
19
17
|
return backendCfg;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BackendCfg } from './backend.cfg.util';
|
|
2
2
|
import { AppYaml, DeployInfo } from './deploy.model';
|
|
3
3
|
export declare function createAndSaveDeployInfo(backendCfg: BackendCfg, targetDir: string): Promise<DeployInfo>;
|
|
4
|
-
export declare function createDeployInfo(backendCfg: BackendCfg): Promise<DeployInfo>;
|
|
4
|
+
export declare function createDeployInfo(backendCfg: BackendCfg, overrideBranch?: string): Promise<DeployInfo>;
|
|
5
5
|
export declare function createAndSaveAppYaml(backendCfg: BackendCfg, deployInfo: DeployInfo, projectDir: string, targetDir: string, appYamlPassEnv?: string): AppYaml;
|
|
6
6
|
export declare function createAppYaml(backendCfg: BackendCfg, deployInfo: DeployInfo, projectDir: string, appYamlPassEnv?: string): AppYaml;
|
|
7
7
|
export declare function validateGAEServiceName(serviceName: string): string;
|
|
@@ -32,11 +32,11 @@ async function createAndSaveDeployInfo(backendCfg, targetDir) {
|
|
|
32
32
|
return deployInfo;
|
|
33
33
|
}
|
|
34
34
|
exports.createAndSaveDeployInfo = createAndSaveDeployInfo;
|
|
35
|
-
async function createDeployInfo(backendCfg) {
|
|
35
|
+
async function createDeployInfo(backendCfg, overrideBranch) {
|
|
36
36
|
const simpleGit = require('simple-git'); // lazy load
|
|
37
37
|
const git = simpleGit('.');
|
|
38
38
|
const now = (0, js_lib_1.localTimeNow)();
|
|
39
|
-
const gitBranch = (await git.status()).current;
|
|
39
|
+
const gitBranch = overrideBranch || (await git.status()).current;
|
|
40
40
|
const gitRev = (await git.revparse(['HEAD'])).slice(0, 7);
|
|
41
41
|
let { gaeProject, gaeProjectByBranch = {}, gaeService, gaeServiceByBranch = {}, serviceWithBranchName, prodBranch, branchesWithTimestampVersions = [], } = backendCfg;
|
|
42
42
|
gaeProject = gaeProjectByBranch[gitBranch] || gaeProject;
|
|
@@ -7,4 +7,4 @@ export declare function deployGae(opt?: DeployGaeOptions): Promise<void>;
|
|
|
7
7
|
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
8
8
|
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
9
9
|
*/
|
|
10
|
-
export declare function undeployGae(): Promise<void>;
|
|
10
|
+
export declare function undeployGae(branch: string): Promise<void>;
|
package/dist/deploy/deployGae.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.undeployGae = exports.deployGae = void 0;
|
|
|
4
4
|
const dev_lib_1 = require("@naturalcycles/dev-lib");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
|
+
const backend_cfg_util_1 = require("./backend.cfg.util");
|
|
8
|
+
const deploy_util_1 = require("./deploy.util");
|
|
7
9
|
const deployHealthCheck_1 = require("./deployHealthCheck");
|
|
8
10
|
const deployPrepare_1 = require("./deployPrepare");
|
|
9
11
|
async function deployGae(opt = {}) {
|
|
@@ -61,13 +63,15 @@ exports.deployGae = deployGae;
|
|
|
61
63
|
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
62
64
|
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
63
65
|
*/
|
|
64
|
-
async function undeployGae() {
|
|
65
|
-
const
|
|
66
|
+
async function undeployGae(branch) {
|
|
67
|
+
const projectDir = '.';
|
|
68
|
+
const backendCfg = (0, backend_cfg_util_1.getBackendCfg)(projectDir);
|
|
69
|
+
const { gaeProject, gaeService, gaeVersion, prod } = await (0, deploy_util_1.createDeployInfo)(backendCfg, branch);
|
|
66
70
|
if (prod) {
|
|
67
|
-
console.log(
|
|
71
|
+
console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`);
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
|
-
console.log(`undeployGae: going to remove ${gaeProject}/${gaeService}/${gaeVersion}`);
|
|
74
|
+
console.log(`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`);
|
|
71
75
|
(0, nodejs_lib_1.execVoidCommandSync)(`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`, [], { shell: true });
|
|
72
76
|
}
|
|
73
77
|
exports.undeployGae = undeployGae;
|
|
@@ -58,7 +58,7 @@ async function deployPrepare(opt = {}) {
|
|
|
58
58
|
const appYamlPassEnv = opt.appYamlPassEnv || backendCfg.appYamlPassEnv;
|
|
59
59
|
console.log(`1. Copy files to ${(0, nodejs_lib_1.dimGrey)(targetDir)}`);
|
|
60
60
|
// Clean targetDir
|
|
61
|
-
|
|
61
|
+
nodejs_lib_1.fs2.emptyDir(targetDir);
|
|
62
62
|
(0, nodejs_lib_1.kpySync)({
|
|
63
63
|
baseDir: defaultFilesDir,
|
|
64
64
|
outputDir: targetDir,
|
|
@@ -74,7 +74,7 @@ async function deployPrepare(opt = {}) {
|
|
|
74
74
|
if (NPM_TOKEN && createNpmrc) {
|
|
75
75
|
const npmrcPath = `${targetDir}/.npmrc`;
|
|
76
76
|
const npmrc = `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`;
|
|
77
|
-
|
|
77
|
+
nodejs_lib_1.fs2.writeFile(npmrcPath, npmrc);
|
|
78
78
|
}
|
|
79
79
|
console.log(`2. Generate ${(0, nodejs_lib_1.dimGrey)('deployInfo.json')} and ${(0, nodejs_lib_1.dimGrey)('app.yaml')} in targetDir`);
|
|
80
80
|
const deployInfo = await (0, deploy_util_1.createAndSaveDeployInfo)(backendCfg, targetDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"serve": "APP_ENV=dev nodemon",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"express-promise-router": "^4.0.0",
|
|
32
32
|
"firebase-admin": "^12.0.0",
|
|
33
33
|
"helmet": "^7.0.0",
|
|
34
|
-
"js-yaml": "^4.0.0",
|
|
35
34
|
"on-finished": "^2.3.0",
|
|
36
35
|
"simple-git": "^3.0.3",
|
|
37
36
|
"yargs": "^17.0.0"
|
|
@@ -41,7 +40,6 @@
|
|
|
41
40
|
"@naturalcycles/dev-lib": "^13.0.0",
|
|
42
41
|
"@sentry/node": "^7.0.0",
|
|
43
42
|
"@types/ejs": "^3.0.0",
|
|
44
|
-
"@types/js-yaml": "^4.0.0",
|
|
45
43
|
"@types/node": "^20.1.0",
|
|
46
44
|
"@types/yargs": "^16.0.0",
|
|
47
45
|
"fastify": "^4.0.0",
|
package/src/bin/undeploy-gae.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { runScript } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import yargs from 'yargs'
|
|
4
5
|
import { undeployGae } from '../deploy/deployGae'
|
|
5
6
|
|
|
6
7
|
runScript(async () => {
|
|
7
|
-
|
|
8
|
+
const { branch } = yargs.options({
|
|
9
|
+
branch: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
demandOption: true,
|
|
12
|
+
desc: `Because Github Actions delete event happens after the branch is already deleted - you need to pass it manually`,
|
|
13
|
+
},
|
|
14
|
+
}).argv
|
|
15
|
+
|
|
16
|
+
await undeployGae(branch)
|
|
8
17
|
})
|
|
@@ -75,7 +75,7 @@ export function httpDBRequestHandler(db: CommonDB): BackendRouter {
|
|
|
75
75
|
|
|
76
76
|
// getTableSchema
|
|
77
77
|
router.get('/:table/schema', async (req, res) => {
|
|
78
|
-
res.json(await db.getTableSchema(req.params['table']
|
|
78
|
+
res.json(await db.getTableSchema(req.params['table']))
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
// todo: createTable
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StringMap } from '@naturalcycles/js-lib'
|
|
2
|
-
import {
|
|
3
|
-
import yaml from 'js-yaml'
|
|
2
|
+
import { AjvSchema, fs2, requireFileToExist } from '@naturalcycles/nodejs-lib'
|
|
4
3
|
import { resourcesDir } from '../paths.cnst'
|
|
5
4
|
|
|
6
5
|
export interface BackendCfg {
|
|
@@ -63,7 +62,7 @@ export function getBackendCfg(projectDir: string = '.'): BackendCfg {
|
|
|
63
62
|
|
|
64
63
|
const backendCfg: BackendCfg = {
|
|
65
64
|
serviceWithBranchName: true,
|
|
66
|
-
...
|
|
65
|
+
...fs2.readYaml(backendCfgYamlPath),
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
backendCfgSchema.validate(backendCfg)
|
|
@@ -38,12 +38,15 @@ export async function createAndSaveDeployInfo(
|
|
|
38
38
|
return deployInfo
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export async function createDeployInfo(
|
|
41
|
+
export async function createDeployInfo(
|
|
42
|
+
backendCfg: BackendCfg,
|
|
43
|
+
overrideBranch?: string,
|
|
44
|
+
): Promise<DeployInfo> {
|
|
42
45
|
const simpleGit = require('simple-git') // lazy load
|
|
43
46
|
const git = simpleGit('.')
|
|
44
47
|
|
|
45
48
|
const now = localTimeNow()
|
|
46
|
-
const gitBranch = (await git.status()).current!
|
|
49
|
+
const gitBranch = overrideBranch || (await git.status()).current!
|
|
47
50
|
const gitRev = (await git.revparse(['HEAD'])).slice(0, 7)
|
|
48
51
|
|
|
49
52
|
let {
|
package/src/deploy/deployGae.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { buildProdCommand } from '@naturalcycles/dev-lib'
|
|
2
2
|
import { _anyToError, _objectAssign, pRetry } from '@naturalcycles/js-lib'
|
|
3
3
|
import { appendToGithubSummary, execVoidCommandSync } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import { getBackendCfg } from './backend.cfg.util'
|
|
5
|
+
import { createDeployInfo } from './deploy.util'
|
|
4
6
|
import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
|
|
5
7
|
import { deployPrepare, DeployPrepareOptions } from './deployPrepare'
|
|
6
8
|
|
|
@@ -83,15 +85,20 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
|
|
|
83
85
|
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
84
86
|
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
85
87
|
*/
|
|
86
|
-
export async function undeployGae(): Promise<void> {
|
|
87
|
-
const
|
|
88
|
+
export async function undeployGae(branch: string): Promise<void> {
|
|
89
|
+
const projectDir = '.'
|
|
90
|
+
const backendCfg = getBackendCfg(projectDir)
|
|
91
|
+
|
|
92
|
+
const { gaeProject, gaeService, gaeVersion, prod } = await createDeployInfo(backendCfg, branch)
|
|
88
93
|
|
|
89
94
|
if (prod) {
|
|
90
|
-
console.log(
|
|
95
|
+
console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`)
|
|
91
96
|
return
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
console.log(
|
|
99
|
+
console.log(
|
|
100
|
+
`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`,
|
|
101
|
+
)
|
|
95
102
|
|
|
96
103
|
execVoidCommandSync(
|
|
97
104
|
`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dimGrey, fs2, kpySync } from '@naturalcycles/nodejs-lib'
|
|
2
2
|
import { srcDir } from '../paths.cnst'
|
|
3
3
|
import { getBackendCfg } from './backend.cfg.util'
|
|
4
4
|
import { DeployInfo } from './deploy.model'
|
|
@@ -75,7 +75,7 @@ export async function deployPrepare(opt: DeployPrepareOptions = {}): Promise<Dep
|
|
|
75
75
|
console.log(`1. Copy files to ${dimGrey(targetDir)}`)
|
|
76
76
|
|
|
77
77
|
// Clean targetDir
|
|
78
|
-
|
|
78
|
+
fs2.emptyDir(targetDir)
|
|
79
79
|
|
|
80
80
|
kpySync({
|
|
81
81
|
baseDir: defaultFilesDir,
|
|
@@ -94,7 +94,7 @@ export async function deployPrepare(opt: DeployPrepareOptions = {}): Promise<Dep
|
|
|
94
94
|
if (NPM_TOKEN && createNpmrc) {
|
|
95
95
|
const npmrcPath = `${targetDir}/.npmrc`
|
|
96
96
|
const npmrc = `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`
|
|
97
|
-
|
|
97
|
+
fs2.writeFile(npmrcPath, npmrc)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
console.log(`2. Generate ${dimGrey('deployInfo.json')} and ${dimGrey('app.yaml')} in targetDir`)
|