@naturalcycles/backend-lib 4.22.0 → 4.23.1
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.d.ts +2 -0
- package/dist/bin/undeploy-gae.js +17 -0
- package/dist/deploy/deploy.util.d.ts +1 -1
- package/dist/deploy/deploy.util.js +2 -2
- package/dist/deploy/deployGae.d.ts +5 -0
- package/dist/deploy/deployGae.js +19 -1
- package/package.json +2 -1
- package/src/bin/undeploy-gae.ts +17 -0
- package/src/deploy/deploy.util.ts +5 -2
- package/src/deploy/deployGae.ts +28 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
7
|
+
const deployGae_1 = require("../deploy/deployGae");
|
|
8
|
+
(0, nodejs_lib_1.runScript)(async () => {
|
|
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);
|
|
17
|
+
});
|
|
@@ -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;
|
|
@@ -3,3 +3,8 @@ import { DeployPrepareOptions } from './deployPrepare';
|
|
|
3
3
|
export interface DeployGaeOptions extends DeployPrepareOptions, DeployHealthCheckOptions {
|
|
4
4
|
}
|
|
5
5
|
export declare function deployGae(opt?: DeployGaeOptions): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
8
|
+
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
9
|
+
*/
|
|
10
|
+
export declare function undeployGae(branch: string): Promise<void>;
|
package/dist/deploy/deployGae.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deployGae = void 0;
|
|
3
|
+
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 = {}) {
|
|
@@ -57,6 +59,22 @@ async function deployGae(opt = {}) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
exports.deployGae = deployGae;
|
|
62
|
+
/**
|
|
63
|
+
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
64
|
+
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
65
|
+
*/
|
|
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);
|
|
70
|
+
if (prod) {
|
|
71
|
+
console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
console.log(`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`);
|
|
75
|
+
(0, nodejs_lib_1.execVoidCommandSync)(`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`, [], { shell: true });
|
|
76
|
+
}
|
|
77
|
+
exports.undeployGae = undeployGae;
|
|
60
78
|
function logs(gaeProject, gaeService, gaeVersion) {
|
|
61
79
|
try {
|
|
62
80
|
(0, nodejs_lib_1.execVoidCommandSync)(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`, [], { shell: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"serve": "APP_ENV=dev nodemon",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
],
|
|
61
61
|
"bin": {
|
|
62
62
|
"deploy-gae": "dist/bin/deploy-gae.js",
|
|
63
|
+
"undeploy-gae": "dist/bin/undeploy-gae.js",
|
|
63
64
|
"deploy-prepare": "dist/bin/deploy-prepare.js",
|
|
64
65
|
"deploy-health-check": "dist/bin/deploy-health-check.js"
|
|
65
66
|
},
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { runScript } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import yargs from 'yargs'
|
|
5
|
+
import { undeployGae } from '../deploy/deployGae'
|
|
6
|
+
|
|
7
|
+
runScript(async () => {
|
|
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)
|
|
17
|
+
})
|
|
@@ -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
|
|
|
@@ -79,6 +81,32 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
|
|
86
|
+
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
|
|
87
|
+
*/
|
|
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)
|
|
93
|
+
|
|
94
|
+
if (prod) {
|
|
95
|
+
console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log(
|
|
100
|
+
`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
execVoidCommandSync(
|
|
104
|
+
`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`,
|
|
105
|
+
[],
|
|
106
|
+
{ shell: true },
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
82
110
|
function logs(gaeProject: string, gaeService: string, gaeVersion: string): void {
|
|
83
111
|
try {
|
|
84
112
|
execVoidCommandSync(
|