@naturalcycles/backend-lib 4.21.1 → 4.23.0

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
+ const deployGae_1 = require("../deploy/deployGae");
6
+ (0, nodejs_lib_1.runScript)(async () => {
7
+ await (0, deployGae_1.undeployGae)();
8
+ });
@@ -55,6 +55,9 @@ async function createDeployInfo(backendCfg) {
55
55
  ].join('-');
56
56
  }
57
57
  const versionUrl = `https://${[gaeVersion, gaeService, gaeProject].join('-dot-')}.appspot.com`;
58
+ // Check the 63-char limit
59
+ const versionUrlString = [gaeVersion, gaeService, gaeProject].join('-dot-');
60
+ (0, js_lib_1._assert)(versionUrlString.length <= 63, `versionUrl length should be <= 63 characters, but it's ${versionUrlString.length} instead: ${versionUrlString}`);
58
61
  const serviceUrl = `https://${[gaeService, gaeProject].join('-dot-')}.appspot.com`;
59
62
  const deployInfo = {
60
63
  gaeProject,
@@ -138,12 +141,10 @@ function redactedAppYaml(appYaml) {
138
141
  }
139
142
  function validateGAEServiceName(serviceName) {
140
143
  // May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.
141
- return replaceAll(serviceName, '_', '-')
144
+ return serviceName
145
+ .replaceAll('_', '-')
142
146
  .toLowerCase()
143
147
  .replaceAll(/[^0-9a-z-]/gi, '')
144
148
  .slice(0, 40);
145
149
  }
146
150
  exports.validateGAEServiceName = validateGAEServiceName;
147
- function replaceAll(str, search, replacement) {
148
- return str.split(search).join(replacement);
149
- }
@@ -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(): Promise<void>;
@@ -1,6 +1,6 @@
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");
@@ -57,6 +57,20 @@ async function deployGae(opt = {}) {
57
57
  }
58
58
  }
59
59
  exports.deployGae = deployGae;
60
+ /**
61
+ * Undeploys/removes the GAE service/version, using the same rules as deployGae.
62
+ * Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
63
+ */
64
+ async function undeployGae() {
65
+ const { gaeProject, gaeService, gaeVersion, prod } = await (0, deployPrepare_1.deployPrepare)();
66
+ if (prod) {
67
+ console.log('undeployGae: not removing prod version (safety check)');
68
+ return;
69
+ }
70
+ console.log(`undeployGae: going to remove ${gaeProject}/${gaeService}/${gaeVersion}`);
71
+ (0, nodejs_lib_1.execVoidCommandSync)(`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`, [], { shell: true });
72
+ }
73
+ exports.undeployGae = undeployGae;
60
74
  function logs(gaeProject, gaeService, gaeVersion) {
61
75
  try {
62
76
  (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.21.1",
3
+ "version": "4.23.0",
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,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { runScript } from '@naturalcycles/nodejs-lib'
4
+ import { undeployGae } from '../deploy/deployGae'
5
+
6
+ runScript(async () => {
7
+ await undeployGae()
8
+ })
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs'
2
- import { _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib'
2
+ import { _assert, _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib'
3
3
  import { dimGrey, white } from '@naturalcycles/nodejs-lib'
4
4
  import yaml from 'js-yaml'
5
5
  import { BackendCfg } from './backend.cfg.util'
@@ -79,6 +79,13 @@ export async function createDeployInfo(backendCfg: BackendCfg): Promise<DeployIn
79
79
 
80
80
  const versionUrl = `https://${[gaeVersion, gaeService, gaeProject].join('-dot-')}.appspot.com`
81
81
 
82
+ // Check the 63-char limit
83
+ const versionUrlString = [gaeVersion, gaeService, gaeProject].join('-dot-')
84
+ _assert(
85
+ versionUrlString.length <= 63,
86
+ `versionUrl length should be <= 63 characters, but it's ${versionUrlString.length} instead: ${versionUrlString}`,
87
+ )
88
+
82
89
  const serviceUrl = `https://${[gaeService, gaeProject].join('-dot-')}.appspot.com`
83
90
 
84
91
  const deployInfo: DeployInfo = {
@@ -198,12 +205,9 @@ function redactedAppYaml(appYaml: AppYaml): AppYaml {
198
205
 
199
206
  export function validateGAEServiceName(serviceName: string): string {
200
207
  // May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.
201
- return replaceAll(serviceName, '_', '-')
208
+ return serviceName
209
+ .replaceAll('_', '-')
202
210
  .toLowerCase()
203
211
  .replaceAll(/[^0-9a-z-]/gi, '')
204
212
  .slice(0, 40)
205
213
  }
206
-
207
- function replaceAll(str: string, search: string, replacement: string): string {
208
- return str.split(search).join(replacement)
209
- }
@@ -79,6 +79,27 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
79
79
  }
80
80
  }
81
81
 
82
+ /**
83
+ * Undeploys/removes the GAE service/version, using the same rules as deployGae.
84
+ * Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
85
+ */
86
+ export async function undeployGae(): Promise<void> {
87
+ const { gaeProject, gaeService, gaeVersion, prod } = await deployPrepare()
88
+
89
+ if (prod) {
90
+ console.log('undeployGae: not removing prod version (safety check)')
91
+ return
92
+ }
93
+
94
+ console.log(`undeployGae: going to remove ${gaeProject}/${gaeService}/${gaeVersion}`)
95
+
96
+ execVoidCommandSync(
97
+ `gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`,
98
+ [],
99
+ { shell: true },
100
+ )
101
+ }
102
+
82
103
  function logs(gaeProject: string, gaeService: string, gaeVersion: string): void {
83
104
  try {
84
105
  execVoidCommandSync(