@naturalcycles/backend-lib 9.79.0 → 9.80.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.
- package/dist/deploy/deployHealthCheck.d.ts +1 -5
- package/dist/deploy/deployHealthCheck.js +3 -34
- package/dist/deploy/index.d.ts +2 -9
- package/dist/deploy/index.js +1 -6
- package/dist/express/createDefaultApp.js +2 -2
- package/dist/server/serverStatusMiddleware.d.ts +2 -2
- package/dist/server/serverStatusMiddleware.js +5 -14
- package/dist/util.d.ts +0 -1
- package/dist/util.js +1 -4
- package/package.json +3 -13
- package/src/deploy/deployHealthCheck.ts +2 -48
- package/src/deploy/index.ts +2 -17
- package/src/express/createDefaultApp.ts +2 -2
- package/src/server/serverStatusMiddleware.ts +4 -20
- package/src/util.ts +1 -5
- package/bin/deploy-gae.js +0 -2
- package/bin/deploy-prepare.js +0 -2
- package/bin/undeploy-gae.js +0 -2
- package/dist/bin/deploy-gae.d.ts +0 -1
- package/dist/bin/deploy-gae.js +0 -12
- package/dist/bin/deploy-prepare.d.ts +0 -1
- package/dist/bin/deploy-prepare.js +0 -19
- package/dist/bin/undeploy-gae.d.ts +0 -1
- package/dist/bin/undeploy-gae.js +0 -13
- package/dist/deploy/backend.cfg.util.d.ts +0 -30
- package/dist/deploy/backend.cfg.util.js +0 -23
- package/dist/deploy/deploy.model.d.ts +0 -29
- package/dist/deploy/deploy.model.js +0 -1
- package/dist/deploy/deploy.util.d.ts +0 -7
- package/dist/deploy/deploy.util.js +0 -151
- package/dist/deploy/deployGae.d.ts +0 -10
- package/dist/deploy/deployGae.js +0 -90
- package/dist/deploy/deployInfo.util.d.ts +0 -1
- package/dist/deploy/deployInfo.util.js +0 -25
- package/dist/deploy/deployPrepare.d.ts +0 -13
- package/dist/deploy/deployPrepare.js +0 -85
- package/src/bin/deploy-gae.ts +0 -14
- package/src/bin/deploy-prepare.ts +0 -24
- package/src/bin/undeploy-gae.ts +0 -15
- package/src/deploy/backend.cfg.util.ts +0 -63
- package/src/deploy/deploy.model.ts +0 -32
- package/src/deploy/deploy.util.ts +0 -214
- package/src/deploy/deployGae.ts +0 -127
- package/src/deploy/deployInfo.util.ts +0 -27
- package/src/deploy/deployPrepare.ts +0 -113
- package/src/deploy/files-default/.gcloudignore +0 -7
|
@@ -4,11 +4,6 @@ export interface DeployHealthCheckOptions {
|
|
|
4
4
|
maxTries?: number;
|
|
5
5
|
timeoutSec?: number;
|
|
6
6
|
intervalSec?: number;
|
|
7
|
-
logOnFailure?: boolean;
|
|
8
|
-
logOnSuccess?: boolean;
|
|
9
|
-
gaeProject?: string;
|
|
10
|
-
gaeService?: string;
|
|
11
|
-
gaeVersion?: string;
|
|
12
7
|
authHeader?: string;
|
|
13
8
|
}
|
|
14
9
|
export declare const deployHealthCheckCliOptions: CliOptions;
|
|
@@ -16,5 +11,6 @@ export declare const deployHealthCheckCliOptions: CliOptions;
|
|
|
16
11
|
* Requires up to `healthyThreshold` consecutive OK responses to succeed.
|
|
17
12
|
* Fails on up to `unhealthyThreshold` consecutive FAIL responses.
|
|
18
13
|
* Fails after maxTries.
|
|
14
|
+
* Throws on failure.
|
|
19
15
|
*/
|
|
20
16
|
export declare function deployHealthCheck(url: string, opt?: DeployHealthCheckOptions): Promise<void>;
|
|
@@ -4,7 +4,6 @@ import { getFetcher } from '@naturalcycles/js-lib/http';
|
|
|
4
4
|
import { _filterFalsyValues, _filterUndefinedValues, } from '@naturalcycles/js-lib/object/object.util.js';
|
|
5
5
|
import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js';
|
|
6
6
|
import { dimGrey, red } from '@naturalcycles/nodejs-lib/colors';
|
|
7
|
-
import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
|
|
8
7
|
import { coloredHttpCode } from '../server/request.log.util.js';
|
|
9
8
|
export const deployHealthCheckCliOptions = {
|
|
10
9
|
thresholdHealthy: {
|
|
@@ -27,25 +26,6 @@ export const deployHealthCheckCliOptions = {
|
|
|
27
26
|
type: 'number',
|
|
28
27
|
default: 1,
|
|
29
28
|
},
|
|
30
|
-
logOnFailure: {
|
|
31
|
-
type: 'boolean',
|
|
32
|
-
default: true,
|
|
33
|
-
desc: 'Show server logs on health check failure (requires gaeProject, gaeService, gaeVersion)',
|
|
34
|
-
},
|
|
35
|
-
logOnSuccess: {
|
|
36
|
-
type: 'boolean',
|
|
37
|
-
default: false,
|
|
38
|
-
desc: 'Show server logs on health check success (requires gaeProject, gaeService, gaeVersion)',
|
|
39
|
-
},
|
|
40
|
-
gaeProject: {
|
|
41
|
-
type: 'string',
|
|
42
|
-
},
|
|
43
|
-
gaeService: {
|
|
44
|
-
type: 'string',
|
|
45
|
-
},
|
|
46
|
-
gaeVersion: {
|
|
47
|
-
type: 'string',
|
|
48
|
-
},
|
|
49
29
|
authHeader: {
|
|
50
30
|
type: 'string',
|
|
51
31
|
},
|
|
@@ -58,9 +38,10 @@ const inspectOpt = {
|
|
|
58
38
|
* Requires up to `healthyThreshold` consecutive OK responses to succeed.
|
|
59
39
|
* Fails on up to `unhealthyThreshold` consecutive FAIL responses.
|
|
60
40
|
* Fails after maxTries.
|
|
41
|
+
* Throws on failure.
|
|
61
42
|
*/
|
|
62
43
|
export async function deployHealthCheck(url, opt = {}) {
|
|
63
|
-
const { thresholdHealthy = 5, thresholdUnhealthy = 8, maxTries = 30, timeoutSec = 30, intervalSec = 1,
|
|
44
|
+
const { thresholdHealthy = 5, thresholdUnhealthy = 8, maxTries = 30, timeoutSec = 30, intervalSec = 1, authHeader, } = opt;
|
|
64
45
|
let attempt = 0;
|
|
65
46
|
let countHealthy = 0;
|
|
66
47
|
let countUnhealthy = 0;
|
|
@@ -74,19 +55,7 @@ export async function deployHealthCheck(url, opt = {}) {
|
|
|
74
55
|
}
|
|
75
56
|
if (failed) {
|
|
76
57
|
console.log(red(`Health check failed!`));
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
exec2.spawn(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`);
|
|
80
|
-
}
|
|
81
|
-
catch { }
|
|
82
|
-
}
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
if (logOnSuccess) {
|
|
86
|
-
try {
|
|
87
|
-
exec2.spawn(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`);
|
|
88
|
-
}
|
|
89
|
-
catch { }
|
|
58
|
+
throw new Error(`Health check failed: ${doneReason}`);
|
|
90
59
|
}
|
|
91
60
|
async function makeAttempt() {
|
|
92
61
|
attempt++;
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type { BackendCfg } from './backend.cfg.util.js';
|
|
2
|
-
import { getBackendCfg } from './backend.cfg.util.js';
|
|
3
|
-
import type { DeployInfo } from './deploy.model.js';
|
|
4
|
-
import { createAppYaml, createDeployInfo } from './deploy.util.js';
|
|
5
|
-
import { deployGae } from './deployGae.js';
|
|
6
1
|
import type { DeployHealthCheckOptions } from './deployHealthCheck.js';
|
|
7
2
|
import { deployHealthCheck } from './deployHealthCheck.js';
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export { createAppYaml, createDeployInfo, deployGae, deployHealthCheck, deployPrepare, getBackendCfg, };
|
|
11
|
-
export * from './deployInfo.util.js';
|
|
3
|
+
export type { DeployHealthCheckOptions };
|
|
4
|
+
export { deployHealthCheck };
|
package/dist/deploy/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { getBackendCfg } from './backend.cfg.util.js';
|
|
2
|
-
import { createAppYaml, createDeployInfo } from './deploy.util.js';
|
|
3
|
-
import { deployGae } from './deployGae.js';
|
|
4
1
|
import { deployHealthCheck } from './deployHealthCheck.js';
|
|
5
|
-
|
|
6
|
-
export { createAppYaml, createDeployInfo, deployGae, deployHealthCheck, deployPrepare, getBackendCfg, };
|
|
7
|
-
export * from './deployInfo.util.js';
|
|
2
|
+
export { deployHealthCheck };
|
|
@@ -5,9 +5,9 @@ import { logMiddleware } from '../server/logMiddleware.js';
|
|
|
5
5
|
import { notFoundMiddleware } from '../server/notFoundMiddleware.js';
|
|
6
6
|
import { requestTimeoutMiddleware } from '../server/requestTimeoutMiddleware.js';
|
|
7
7
|
import { simpleRequestLoggerMiddleware } from '../server/simpleRequestLoggerMiddleware.js';
|
|
8
|
-
import { isGAE } from '../util.js';
|
|
9
8
|
const isTest = process.env['APP_ENV'] === 'test';
|
|
10
9
|
const isDev = process.env['APP_ENV'] === 'dev';
|
|
10
|
+
const isGAE = !!process.env['GAE_INSTANCE'];
|
|
11
11
|
export async function createDefaultApp(cfg) {
|
|
12
12
|
const { sentryService } = cfg;
|
|
13
13
|
const { default: express } = await import('express');
|
|
@@ -43,7 +43,7 @@ export async function createDefaultApp(cfg) {
|
|
|
43
43
|
maxAge: 86400,
|
|
44
44
|
...cfg.corsOptions,
|
|
45
45
|
}));
|
|
46
|
-
if (!isGAE
|
|
46
|
+
if (!isGAE && isTest) {
|
|
47
47
|
// compression is not used in AppEngine, because AppEngine provides it by default
|
|
48
48
|
app.use(compressionMiddleware());
|
|
49
49
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BackendRequestHandler } from './server.model.js';
|
|
2
|
-
export declare function serverStatusMiddleware(
|
|
3
|
-
export declare function getServerStatusData(
|
|
2
|
+
export declare function serverStatusMiddleware(extra?: any): BackendRequestHandler;
|
|
3
|
+
export declare function getServerStatusData(extra?: any): Record<string, any>;
|
|
@@ -2,31 +2,22 @@ import os from 'node:os';
|
|
|
2
2
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
|
|
3
3
|
import { _filterNullishValues } from '@naturalcycles/js-lib/object/object.util.js';
|
|
4
4
|
import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib';
|
|
5
|
-
import { getDeployInfo } from '../deploy/deployInfo.util.js';
|
|
6
5
|
const { versions, arch, platform } = process;
|
|
7
6
|
const availableParallelismAtStart = os.availableParallelism();
|
|
8
|
-
const {
|
|
9
|
-
export function serverStatusMiddleware(
|
|
7
|
+
const { GOOGLE_CLOUD_PROJECT, K_SERVICE, K_REVISION, APP_ENV, NODE_ENV, NODE_OPTIONS, UV_THREADPOOL_SIZE, MALLOC_ARENA_MAX, DEPLOY_BUILD_TIME, BUILD_VERSION, } = process.env;
|
|
8
|
+
export function serverStatusMiddleware(extra) {
|
|
10
9
|
return async (_req, res) => {
|
|
11
|
-
res.json(getServerStatusData(
|
|
10
|
+
res.json(getServerStatusData(extra));
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
|
-
export function getServerStatusData(
|
|
15
|
-
let deployBuildTime = DEPLOY_BUILD_TIME;
|
|
16
|
-
if (!deployBuildTime) {
|
|
17
|
-
const { ts } = getDeployInfo(projectDir);
|
|
18
|
-
deployBuildTime = localTime(ts).toPretty();
|
|
19
|
-
}
|
|
13
|
+
export function getServerStatusData(extra) {
|
|
20
14
|
const availableParallelism = os.availableParallelism();
|
|
21
15
|
return _filterNullishValues({
|
|
22
16
|
nodeProcessStarted: getStartedStr(),
|
|
23
|
-
|
|
17
|
+
DEPLOY_BUILD_TIME,
|
|
24
18
|
BUILD_VERSION,
|
|
25
19
|
APP_ENV,
|
|
26
20
|
GOOGLE_CLOUD_PROJECT,
|
|
27
|
-
GAE_APPLICATION,
|
|
28
|
-
GAE_SERVICE,
|
|
29
|
-
GAE_VERSION,
|
|
30
21
|
K_SERVICE,
|
|
31
22
|
K_REVISION,
|
|
32
23
|
processInfo: {
|
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.80.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/db-lib": "^10",
|
|
7
7
|
"@naturalcycles/js-lib": "^15",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@sentry/node-core": "^10",
|
|
23
|
-
"firebase-admin": "^14"
|
|
24
|
-
"simple-git": "^4"
|
|
23
|
+
"firebase-admin": "^14"
|
|
25
24
|
},
|
|
26
25
|
"peerDependenciesMeta": {
|
|
27
26
|
"@sentry/node-core": {
|
|
@@ -29,9 +28,6 @@
|
|
|
29
28
|
},
|
|
30
29
|
"firebase-admin": {
|
|
31
30
|
"optional": true
|
|
32
|
-
},
|
|
33
|
-
"simple-git": {
|
|
34
|
-
"optional": true
|
|
35
31
|
}
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|
|
@@ -68,9 +64,6 @@
|
|
|
68
64
|
"!src/**/__exclude"
|
|
69
65
|
],
|
|
70
66
|
"bin": {
|
|
71
|
-
"deploy-gae": "bin/deploy-gae.js",
|
|
72
|
-
"undeploy-gae": "bin/undeploy-gae.js",
|
|
73
|
-
"deploy-prepare": "bin/deploy-prepare.js",
|
|
74
67
|
"deploy-health-check": "bin/deploy-health-check.js"
|
|
75
68
|
},
|
|
76
69
|
"types": "dist/index.d.ts",
|
|
@@ -85,7 +78,7 @@
|
|
|
85
78
|
"engines": {
|
|
86
79
|
"node": ">=24.10.0"
|
|
87
80
|
},
|
|
88
|
-
"description": "Standard library for making Express.js
|
|
81
|
+
"description": "Standard library for making Express.js based backend services",
|
|
89
82
|
"author": "Natural Cycles Team",
|
|
90
83
|
"license": "MIT",
|
|
91
84
|
"scripts": {
|
|
@@ -97,9 +90,6 @@
|
|
|
97
90
|
"check": "dev-lib check",
|
|
98
91
|
"typecheck": "dev-lib typecheck",
|
|
99
92
|
"dev": "APP_ENV=dev tsx watch src/test/server/server.ts",
|
|
100
|
-
"deploy-gae": "tsx src/bin/deploy-gae.ts",
|
|
101
|
-
"deploy-prepare": "tsx src/bin/deploy-prepare.ts",
|
|
102
|
-
"deploy-prepare-debug": "AA=AA1 BB=BB1 tsx src/bin/deploy-prepare.ts --projectDir ./src/test/project",
|
|
103
93
|
"deploy-health-check-debug1": "tsx src/bin/deploy-health-check.ts --url https://api-master.naturalcycles.com",
|
|
104
94
|
"deploy-health-check-debug2": "tsx src/bin/deploy-health-check.ts --url https://api-master2.naturalcycles.com --thresholdUnhealthy 5"
|
|
105
95
|
}
|
|
@@ -10,7 +10,6 @@ import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js'
|
|
|
10
10
|
import type { UnixTimestampMillis } from '@naturalcycles/js-lib/types'
|
|
11
11
|
import type { CliOptions } from '@naturalcycles/nodejs-lib/args'
|
|
12
12
|
import { dimGrey, red } from '@naturalcycles/nodejs-lib/colors'
|
|
13
|
-
import { exec2 } from '@naturalcycles/nodejs-lib/exec2'
|
|
14
13
|
import { coloredHttpCode } from '../server/request.log.util.js'
|
|
15
14
|
|
|
16
15
|
export interface DeployHealthCheckOptions {
|
|
@@ -19,11 +18,6 @@ export interface DeployHealthCheckOptions {
|
|
|
19
18
|
maxTries?: number
|
|
20
19
|
timeoutSec?: number
|
|
21
20
|
intervalSec?: number
|
|
22
|
-
logOnFailure?: boolean
|
|
23
|
-
logOnSuccess?: boolean
|
|
24
|
-
gaeProject?: string
|
|
25
|
-
gaeService?: string
|
|
26
|
-
gaeVersion?: string
|
|
27
21
|
authHeader?: string
|
|
28
22
|
}
|
|
29
23
|
|
|
@@ -48,25 +42,6 @@ export const deployHealthCheckCliOptions = {
|
|
|
48
42
|
type: 'number',
|
|
49
43
|
default: 1,
|
|
50
44
|
},
|
|
51
|
-
logOnFailure: {
|
|
52
|
-
type: 'boolean',
|
|
53
|
-
default: true,
|
|
54
|
-
desc: 'Show server logs on health check failure (requires gaeProject, gaeService, gaeVersion)',
|
|
55
|
-
},
|
|
56
|
-
logOnSuccess: {
|
|
57
|
-
type: 'boolean',
|
|
58
|
-
default: false,
|
|
59
|
-
desc: 'Show server logs on health check success (requires gaeProject, gaeService, gaeVersion)',
|
|
60
|
-
},
|
|
61
|
-
gaeProject: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
},
|
|
64
|
-
gaeService: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
},
|
|
67
|
-
gaeVersion: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
},
|
|
70
45
|
authHeader: {
|
|
71
46
|
type: 'string',
|
|
72
47
|
},
|
|
@@ -81,6 +56,7 @@ const inspectOpt: InspectOptions = {
|
|
|
81
56
|
* Requires up to `healthyThreshold` consecutive OK responses to succeed.
|
|
82
57
|
* Fails on up to `unhealthyThreshold` consecutive FAIL responses.
|
|
83
58
|
* Fails after maxTries.
|
|
59
|
+
* Throws on failure.
|
|
84
60
|
*/
|
|
85
61
|
export async function deployHealthCheck(
|
|
86
62
|
url: string,
|
|
@@ -92,11 +68,6 @@ export async function deployHealthCheck(
|
|
|
92
68
|
maxTries = 30,
|
|
93
69
|
timeoutSec = 30,
|
|
94
70
|
intervalSec = 1,
|
|
95
|
-
logOnFailure,
|
|
96
|
-
logOnSuccess,
|
|
97
|
-
gaeProject,
|
|
98
|
-
gaeService,
|
|
99
|
-
gaeVersion,
|
|
100
71
|
authHeader,
|
|
101
72
|
} = opt
|
|
102
73
|
|
|
@@ -116,24 +87,7 @@ export async function deployHealthCheck(
|
|
|
116
87
|
|
|
117
88
|
if (failed) {
|
|
118
89
|
console.log(red(`Health check failed!`))
|
|
119
|
-
|
|
120
|
-
if (logOnFailure) {
|
|
121
|
-
try {
|
|
122
|
-
exec2.spawn(
|
|
123
|
-
`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`,
|
|
124
|
-
)
|
|
125
|
-
} catch {}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
process.exit(1)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (logOnSuccess) {
|
|
132
|
-
try {
|
|
133
|
-
exec2.spawn(
|
|
134
|
-
`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`,
|
|
135
|
-
)
|
|
136
|
-
} catch {}
|
|
90
|
+
throw new Error(`Health check failed: ${doneReason}`)
|
|
137
91
|
}
|
|
138
92
|
|
|
139
93
|
async function makeAttempt(): Promise<void> {
|
package/src/deploy/index.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import type { BackendCfg } from './backend.cfg.util.js'
|
|
2
|
-
import { getBackendCfg } from './backend.cfg.util.js'
|
|
3
|
-
import type { DeployInfo } from './deploy.model.js'
|
|
4
|
-
import { createAppYaml, createDeployInfo } from './deploy.util.js'
|
|
5
|
-
import { deployGae } from './deployGae.js'
|
|
6
1
|
import type { DeployHealthCheckOptions } from './deployHealthCheck.js'
|
|
7
2
|
import { deployHealthCheck } from './deployHealthCheck.js'
|
|
8
|
-
import { deployPrepare } from './deployPrepare.js'
|
|
9
3
|
|
|
10
|
-
export type {
|
|
4
|
+
export type { DeployHealthCheckOptions }
|
|
11
5
|
|
|
12
|
-
export {
|
|
13
|
-
createAppYaml,
|
|
14
|
-
createDeployInfo,
|
|
15
|
-
deployGae,
|
|
16
|
-
deployHealthCheck,
|
|
17
|
-
deployPrepare,
|
|
18
|
-
getBackendCfg,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export * from './deployInfo.util.js'
|
|
6
|
+
export { deployHealthCheck }
|
|
@@ -14,10 +14,10 @@ import type {
|
|
|
14
14
|
BackendRequestHandler,
|
|
15
15
|
} from '../server/server.model.js'
|
|
16
16
|
import { simpleRequestLoggerMiddleware } from '../server/simpleRequestLoggerMiddleware.js'
|
|
17
|
-
import { isGAE } from '../util.js'
|
|
18
17
|
|
|
19
18
|
const isTest = process.env['APP_ENV'] === 'test'
|
|
20
19
|
const isDev = process.env['APP_ENV'] === 'dev'
|
|
20
|
+
const isGAE = !!process.env['GAE_INSTANCE']
|
|
21
21
|
|
|
22
22
|
export async function createDefaultApp(cfg: DefaultAppCfg): Promise<BackendApplication> {
|
|
23
23
|
const { sentryService } = cfg
|
|
@@ -69,7 +69,7 @@ export async function createDefaultApp(cfg: DefaultAppCfg): Promise<BackendAppli
|
|
|
69
69
|
}),
|
|
70
70
|
)
|
|
71
71
|
|
|
72
|
-
if (!isGAE
|
|
72
|
+
if (!isGAE && isTest) {
|
|
73
73
|
// compression is not used in AppEngine, because AppEngine provides it by default
|
|
74
74
|
app.use(compressionMiddleware())
|
|
75
75
|
}
|
|
@@ -2,15 +2,11 @@ import os from 'node:os'
|
|
|
2
2
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
3
3
|
import { _filterNullishValues } from '@naturalcycles/js-lib/object/object.util.js'
|
|
4
4
|
import { memoryUsageFull, processSharedUtil } from '@naturalcycles/nodejs-lib'
|
|
5
|
-
import { getDeployInfo } from '../deploy/deployInfo.util.js'
|
|
6
5
|
import type { BackendRequestHandler } from './server.model.js'
|
|
7
6
|
|
|
8
7
|
const { versions, arch, platform } = process
|
|
9
8
|
const availableParallelismAtStart = os.availableParallelism()
|
|
10
9
|
const {
|
|
11
|
-
GAE_APPLICATION,
|
|
12
|
-
GAE_SERVICE,
|
|
13
|
-
GAE_VERSION,
|
|
14
10
|
GOOGLE_CLOUD_PROJECT,
|
|
15
11
|
K_SERVICE,
|
|
16
12
|
K_REVISION,
|
|
@@ -23,33 +19,21 @@ const {
|
|
|
23
19
|
BUILD_VERSION,
|
|
24
20
|
} = process.env
|
|
25
21
|
|
|
26
|
-
export function serverStatusMiddleware(
|
|
22
|
+
export function serverStatusMiddleware(extra?: any): BackendRequestHandler {
|
|
27
23
|
return async (_req, res) => {
|
|
28
|
-
res.json(getServerStatusData(
|
|
24
|
+
res.json(getServerStatusData(extra))
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
export function getServerStatusData(
|
|
33
|
-
projectDir: string = process.cwd(),
|
|
34
|
-
extra?: any,
|
|
35
|
-
): Record<string, any> {
|
|
36
|
-
let deployBuildTime = DEPLOY_BUILD_TIME
|
|
37
|
-
if (!deployBuildTime) {
|
|
38
|
-
const { ts } = getDeployInfo(projectDir)
|
|
39
|
-
deployBuildTime = localTime(ts).toPretty()
|
|
40
|
-
}
|
|
41
|
-
|
|
28
|
+
export function getServerStatusData(extra?: any): Record<string, any> {
|
|
42
29
|
const availableParallelism = os.availableParallelism()
|
|
43
30
|
|
|
44
31
|
return _filterNullishValues({
|
|
45
32
|
nodeProcessStarted: getStartedStr(),
|
|
46
|
-
|
|
33
|
+
DEPLOY_BUILD_TIME,
|
|
47
34
|
BUILD_VERSION,
|
|
48
35
|
APP_ENV,
|
|
49
36
|
GOOGLE_CLOUD_PROJECT,
|
|
50
|
-
GAE_APPLICATION,
|
|
51
|
-
GAE_SERVICE,
|
|
52
|
-
GAE_VERSION,
|
|
53
37
|
K_SERVICE,
|
|
54
38
|
K_REVISION,
|
|
55
39
|
processInfo: {
|
package/src/util.ts
CHANGED
package/bin/deploy-gae.js
DELETED
package/bin/deploy-prepare.js
DELETED
package/bin/undeploy-gae.js
DELETED
package/dist/bin/deploy-gae.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/bin/deploy-gae.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { _parseArgs } from '@naturalcycles/nodejs-lib/args';
|
|
2
|
-
import { runScript } from '@naturalcycles/nodejs-lib/runScript';
|
|
3
|
-
import { deployGae } from '../deploy/deployGae.js';
|
|
4
|
-
import { deployHealthCheckCliOptions } from '../deploy/deployHealthCheck.js';
|
|
5
|
-
import { deployPrepareCliOptions } from '../deploy/deployPrepare.js';
|
|
6
|
-
runScript(async () => {
|
|
7
|
-
const opt = _parseArgs({
|
|
8
|
-
...deployPrepareCliOptions,
|
|
9
|
-
...deployHealthCheckCliOptions,
|
|
10
|
-
});
|
|
11
|
-
await deployGae(opt);
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
yarn deploy-prepare
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
import { _parseArgs } from '@naturalcycles/nodejs-lib/args';
|
|
7
|
-
import { runScript } from '@naturalcycles/nodejs-lib/runScript';
|
|
8
|
-
import { deployPrepare, deployPrepareCliOptions } from '../deploy/deployPrepare.js';
|
|
9
|
-
runScript(async () => {
|
|
10
|
-
const opt = _parseArgs(deployPrepareCliOptions);
|
|
11
|
-
await deployPrepare(opt);
|
|
12
|
-
});
|
|
13
|
-
// deploy strategy
|
|
14
|
-
// gae project: from config
|
|
15
|
-
// gae service: from config -- branch name
|
|
16
|
-
// gae version: automatic form date
|
|
17
|
-
// yarn build-prod
|
|
18
|
-
// yarn deploy-prepare && ./tmp/deploy/app.yaml && ./tmp/deploy/deployInfo.json && json2env
|
|
19
|
-
//
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/bin/undeploy-gae.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { _parseArgs } from '@naturalcycles/nodejs-lib/args';
|
|
2
|
-
import { runScript } from '@naturalcycles/nodejs-lib/runScript';
|
|
3
|
-
import { undeployGae } from '../deploy/deployGae.js';
|
|
4
|
-
runScript(async () => {
|
|
5
|
-
const { branch } = _parseArgs({
|
|
6
|
-
branch: {
|
|
7
|
-
type: 'string',
|
|
8
|
-
demandOption: true,
|
|
9
|
-
desc: `Because Github Actions delete event happens after the branch is already deleted - you need to pass it manually`,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
await undeployGae(branch);
|
|
13
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { StringMap } from '@naturalcycles/js-lib/types';
|
|
2
|
-
export interface BackendCfg {
|
|
3
|
-
gaeProject: string;
|
|
4
|
-
gaeProjectByBranch?: StringMap;
|
|
5
|
-
/**
|
|
6
|
-
* @example default
|
|
7
|
-
*/
|
|
8
|
-
gaeService: string;
|
|
9
|
-
gaeServiceByBranch?: StringMap;
|
|
10
|
-
/**
|
|
11
|
-
* List of file patterns to include in deployment.
|
|
12
|
-
*/
|
|
13
|
-
files?: string[];
|
|
14
|
-
appEnvDefault: string;
|
|
15
|
-
appEnvByBranch?: StringMap;
|
|
16
|
-
/**
|
|
17
|
-
* List of branches to use timestamps in gae version names (to keep previous versions).
|
|
18
|
-
*/
|
|
19
|
-
branchesWithTimestampVersions?: string[];
|
|
20
|
-
/**
|
|
21
|
-
* If true - branch names are not passed into deployed urls as is, but are hashed.
|
|
22
|
-
*/
|
|
23
|
-
hashedBranches?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Comma-separated list of env variables that will be passed to app.yaml from process.env
|
|
26
|
-
*/
|
|
27
|
-
appYamlPassEnv?: string;
|
|
28
|
-
}
|
|
29
|
-
export declare const backendCfgSchema: any;
|
|
30
|
-
export declare function getBackendCfg(projectDir?: string): BackendCfg;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { j } from '@naturalcycles/nodejs-lib/ajv';
|
|
2
|
-
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
3
|
-
import { yaml2 } from '@naturalcycles/nodejs-lib/yaml2';
|
|
4
|
-
export const backendCfgSchema = j.object({
|
|
5
|
-
gaeProject: j.string(),
|
|
6
|
-
gaeProjectByBranch: j.object.stringMap(j.string()).optional(),
|
|
7
|
-
gaeService: j.string(),
|
|
8
|
-
gaeServiceByBranch: j.object.stringMap(j.string()).optional(),
|
|
9
|
-
files: j.array(j.string()).optional(),
|
|
10
|
-
appEnvDefault: j.string(),
|
|
11
|
-
appEnvByBranch: j.object.stringMap(j.string()).optional(),
|
|
12
|
-
branchesWithTimestampVersions: j.array(j.string()).optional(),
|
|
13
|
-
hashedBranches: j.boolean().optional(),
|
|
14
|
-
appYamlPassEnv: j.string().optional(),
|
|
15
|
-
});
|
|
16
|
-
export function getBackendCfg(projectDir = '.') {
|
|
17
|
-
const backendCfgYamlPath = `${projectDir}/backend.cfg.yaml`;
|
|
18
|
-
fs2.requireFileToExist(backendCfgYamlPath);
|
|
19
|
-
const backendCfg = {
|
|
20
|
-
...yaml2.readYaml(backendCfgYamlPath),
|
|
21
|
-
};
|
|
22
|
-
return backendCfgSchema.validate(backendCfg);
|
|
23
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { UnixTimestamp } from '@naturalcycles/js-lib/types';
|
|
2
|
-
export interface DeployInfo {
|
|
3
|
-
gaeProject: string;
|
|
4
|
-
gaeService: string;
|
|
5
|
-
gaeVersion: string;
|
|
6
|
-
versionUrl: string;
|
|
7
|
-
serviceUrl: string;
|
|
8
|
-
gitRev: string;
|
|
9
|
-
gitBranch: string;
|
|
10
|
-
/**
|
|
11
|
-
* Unix timestamp of deployInfo.json being generated.
|
|
12
|
-
*/
|
|
13
|
-
ts: UnixTimestamp;
|
|
14
|
-
}
|
|
15
|
-
export interface AppYaml extends Record<string, any> {
|
|
16
|
-
runtime: string;
|
|
17
|
-
service: string;
|
|
18
|
-
inbound_services?: string[];
|
|
19
|
-
instance_class?: string;
|
|
20
|
-
automatic_scaling?: {
|
|
21
|
-
min_instances?: number;
|
|
22
|
-
max_instances?: number;
|
|
23
|
-
};
|
|
24
|
-
env_variables: {
|
|
25
|
-
APP_ENV: string;
|
|
26
|
-
DEBUG: string;
|
|
27
|
-
[k: string]: string;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { BackendCfg } from './backend.cfg.util.js';
|
|
2
|
-
import type { AppYaml, DeployInfo } from './deploy.model.js';
|
|
3
|
-
export declare function createAndSaveDeployInfo(backendCfg: BackendCfg, targetDir: string): Promise<DeployInfo>;
|
|
4
|
-
export declare function createDeployInfo(backendCfg: BackendCfg, overrideBranch?: string): Promise<DeployInfo>;
|
|
5
|
-
export declare function createAndSaveAppYaml(backendCfg: BackendCfg, deployInfo: DeployInfo, projectDir: string, targetDir: string, appYamlPassEnv?: string): AppYaml;
|
|
6
|
-
export declare function createAppYaml(backendCfg: BackendCfg, deployInfo: DeployInfo, projectDir: string, appYamlPassEnv?: string): AppYaml;
|
|
7
|
-
export declare function validateGAEServiceName(serviceName: string): string;
|