@naturalcycles/backend-lib 5.8.0 → 5.8.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/deploy/deployGae.js +5 -5
- package/dist/deploy/deployHealthCheck.js +2 -2
- package/dist/env/env.shared.service.d.ts +2 -5
- package/dist/env/env.shared.service.js +2 -2
- package/package.json +1 -1
- package/src/deploy/deployGae.ts +6 -14
- package/src/deploy/deployHealthCheck.ts +3 -7
- package/src/env/env.shared.service.ts +8 -7
package/dist/deploy/deployGae.js
CHANGED
|
@@ -11,7 +11,7 @@ const deployPrepare_1 = require("./deployPrepare");
|
|
|
11
11
|
async function deployGae(opt = {}) {
|
|
12
12
|
const { logOnFailure, logOnSuccess } = opt;
|
|
13
13
|
// 1. build
|
|
14
|
-
|
|
14
|
+
nodejs_lib_1.exec2.spawn('yarn build');
|
|
15
15
|
// 2. deploy-prepare
|
|
16
16
|
const deployInfo = await (0, deployPrepare_1.deployPrepare)();
|
|
17
17
|
const targetDir = './tmp/deploy';
|
|
@@ -24,7 +24,7 @@ async function deployGae(opt = {}) {
|
|
|
24
24
|
});
|
|
25
25
|
await (0, js_lib_1.pRetry)(async () => {
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
nodejs_lib_1.exec2.spawn(`gcloud app deploy ${appYamlPath} --project ${gaeProject} --version ${gaeVersion} --quiet --no-promote`);
|
|
28
28
|
}
|
|
29
29
|
catch (err) {
|
|
30
30
|
if (logOnFailure) {
|
|
@@ -47,7 +47,7 @@ async function deployGae(opt = {}) {
|
|
|
47
47
|
if (gaeVersion !== '1') {
|
|
48
48
|
// Rollout (promote versionUrl to serviceUrl)
|
|
49
49
|
// gcloud app services set-traffic $deployInfo_gaeService --project $deployInfo_gaeProject --splits $deployInfo_gaeVersion=1 --quiet
|
|
50
|
-
|
|
50
|
+
nodejs_lib_1.exec2.spawn(`gcloud app services set-traffic ${gaeService} --project ${gaeProject} --splits ${gaeVersion}=1 --quiet`);
|
|
51
51
|
// Health check (serviceUrl)
|
|
52
52
|
// yarn deploy-health-check --url $deployInfo_serviceUrl --repeat 3 --timeoutSec 60 --intervalSec 2
|
|
53
53
|
await (0, deployHealthCheck_1.deployHealthCheck)(serviceUrl, opt);
|
|
@@ -71,12 +71,12 @@ async function undeployGae(branch) {
|
|
|
71
71
|
// return
|
|
72
72
|
// }
|
|
73
73
|
console.log(`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`);
|
|
74
|
-
|
|
74
|
+
nodejs_lib_1.exec2.spawn(`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`);
|
|
75
75
|
(0, nodejs_lib_1.appendToGithubSummary)(`removed ${gaeProject}/${gaeService}/${gaeVersion}`);
|
|
76
76
|
}
|
|
77
77
|
function logs(gaeProject, gaeService, gaeVersion) {
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
nodejs_lib_1.exec2.spawn(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`);
|
|
80
80
|
}
|
|
81
81
|
catch { }
|
|
82
82
|
}
|
|
@@ -73,7 +73,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
73
73
|
console.log((0, nodejs_lib_1.red)(`Health check failed!`));
|
|
74
74
|
if (logOnFailure) {
|
|
75
75
|
try {
|
|
76
|
-
|
|
76
|
+
nodejs_lib_1.exec2.spawn(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`);
|
|
77
77
|
}
|
|
78
78
|
catch { }
|
|
79
79
|
}
|
|
@@ -81,7 +81,7 @@ async function deployHealthCheck(url, opt = {}) {
|
|
|
81
81
|
}
|
|
82
82
|
if (logOnSuccess) {
|
|
83
83
|
try {
|
|
84
|
-
|
|
84
|
+
nodejs_lib_1.exec2.spawn(`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`);
|
|
85
85
|
}
|
|
86
86
|
catch { }
|
|
87
87
|
}
|
|
@@ -3,14 +3,11 @@ export interface BaseEnv {
|
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
5
5
|
export interface EnvSharedServiceCfg<ENV> {
|
|
6
|
-
|
|
7
|
-
* Dir with ${envName}.env.ts files
|
|
8
|
-
*/
|
|
9
|
-
envMap: StringMap<ENV>;
|
|
6
|
+
environments: ENV[];
|
|
10
7
|
}
|
|
11
8
|
export declare class EnvSharedService<ENV extends BaseEnv> {
|
|
12
|
-
cfg: EnvSharedServiceCfg<ENV>;
|
|
13
9
|
constructor(cfg: EnvSharedServiceCfg<ENV>);
|
|
10
|
+
envMap: StringMap<ENV>;
|
|
14
11
|
private env?;
|
|
15
12
|
init(): void;
|
|
16
13
|
getEnv(): ENV;
|
|
@@ -5,7 +5,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
class EnvSharedService {
|
|
7
7
|
constructor(cfg) {
|
|
8
|
-
this.
|
|
8
|
+
this.envMap = (0, js_lib_1._by)(cfg.environments, e => e.name);
|
|
9
9
|
}
|
|
10
10
|
init() {
|
|
11
11
|
this.getEnv();
|
|
@@ -14,7 +14,7 @@ class EnvSharedService {
|
|
|
14
14
|
if (!this.env) {
|
|
15
15
|
const { APP_ENV } = process.env;
|
|
16
16
|
(0, js_lib_1._assert)(APP_ENV, 'APP_ENV should be defined!');
|
|
17
|
-
const env = this.
|
|
17
|
+
const env = this.envMap[APP_ENV];
|
|
18
18
|
(0, js_lib_1._assert)(env, `Environment ${APP_ENV} is not defined`);
|
|
19
19
|
this.env = env;
|
|
20
20
|
console.log(`APP_ENV=${(0, nodejs_lib_1.dimGrey)(APP_ENV)} loaded`);
|
package/package.json
CHANGED
package/src/deploy/deployGae.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _anyToError, _objectAssign, pRetry } from '@naturalcycles/js-lib'
|
|
2
|
-
import { appendToGithubSummary,
|
|
2
|
+
import { appendToGithubSummary, exec2 } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { getBackendCfg } from './backend.cfg.util'
|
|
4
4
|
import { createDeployInfo } from './deploy.util'
|
|
5
5
|
import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
|
|
@@ -12,7 +12,7 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
|
|
|
12
12
|
|
|
13
13
|
// 1. build
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
exec2.spawn('yarn build')
|
|
16
16
|
|
|
17
17
|
// 2. deploy-prepare
|
|
18
18
|
|
|
@@ -31,10 +31,8 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
|
|
|
31
31
|
await pRetry(
|
|
32
32
|
async () => {
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
exec2.spawn(
|
|
35
35
|
`gcloud app deploy ${appYamlPath} --project ${gaeProject} --version ${gaeVersion} --quiet --no-promote`,
|
|
36
|
-
[],
|
|
37
|
-
{ shell: true },
|
|
38
36
|
)
|
|
39
37
|
} catch (err) {
|
|
40
38
|
if (logOnFailure) {
|
|
@@ -61,10 +59,8 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
|
|
|
61
59
|
if (gaeVersion !== '1') {
|
|
62
60
|
// Rollout (promote versionUrl to serviceUrl)
|
|
63
61
|
// gcloud app services set-traffic $deployInfo_gaeService --project $deployInfo_gaeProject --splits $deployInfo_gaeVersion=1 --quiet
|
|
64
|
-
|
|
62
|
+
exec2.spawn(
|
|
65
63
|
`gcloud app services set-traffic ${gaeService} --project ${gaeProject} --splits ${gaeVersion}=1 --quiet`,
|
|
66
|
-
[],
|
|
67
|
-
{ shell: true },
|
|
68
64
|
)
|
|
69
65
|
|
|
70
66
|
// Health check (serviceUrl)
|
|
@@ -99,10 +95,8 @@ export async function undeployGae(branch: string): Promise<void> {
|
|
|
99
95
|
`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`,
|
|
100
96
|
)
|
|
101
97
|
|
|
102
|
-
|
|
98
|
+
exec2.spawn(
|
|
103
99
|
`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`,
|
|
104
|
-
[],
|
|
105
|
-
{ shell: true },
|
|
106
100
|
)
|
|
107
101
|
|
|
108
102
|
appendToGithubSummary(`removed ${gaeProject}/${gaeService}/${gaeVersion}`)
|
|
@@ -110,10 +104,8 @@ export async function undeployGae(branch: string): Promise<void> {
|
|
|
110
104
|
|
|
111
105
|
function logs(gaeProject: string, gaeService: string, gaeVersion: string): void {
|
|
112
106
|
try {
|
|
113
|
-
|
|
107
|
+
exec2.spawn(
|
|
114
108
|
`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`,
|
|
115
|
-
[],
|
|
116
|
-
{ shell: true },
|
|
117
109
|
)
|
|
118
110
|
} catch {}
|
|
119
111
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inspect, InspectOptions } from 'node:util'
|
|
2
2
|
import { _filterFalsyValues, _ms, _since, getFetcher, pDelay } from '@naturalcycles/js-lib'
|
|
3
|
-
import { dimGrey,
|
|
3
|
+
import { dimGrey, exec2, red } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { coloredHttpCode } from '../server/request.log.util'
|
|
5
5
|
|
|
6
6
|
export interface DeployHealthCheckOptions {
|
|
@@ -104,10 +104,8 @@ export async function deployHealthCheck(
|
|
|
104
104
|
|
|
105
105
|
if (logOnFailure) {
|
|
106
106
|
try {
|
|
107
|
-
|
|
107
|
+
exec2.spawn(
|
|
108
108
|
`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`,
|
|
109
|
-
[],
|
|
110
|
-
{ shell: true },
|
|
111
109
|
)
|
|
112
110
|
} catch {}
|
|
113
111
|
}
|
|
@@ -117,10 +115,8 @@ export async function deployHealthCheck(
|
|
|
117
115
|
|
|
118
116
|
if (logOnSuccess) {
|
|
119
117
|
try {
|
|
120
|
-
|
|
118
|
+
exec2.spawn(
|
|
121
119
|
`gcloud app logs read --project ${gaeProject} --service ${gaeService} --version ${gaeVersion}`,
|
|
122
|
-
[],
|
|
123
|
-
{ shell: true },
|
|
124
120
|
)
|
|
125
121
|
} catch {}
|
|
126
122
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _assert, StringMap } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _assert, _by, StringMap } from '@naturalcycles/js-lib'
|
|
2
2
|
import { dimGrey } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
|
|
4
4
|
export interface BaseEnv {
|
|
@@ -6,14 +6,15 @@ export interface BaseEnv {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface EnvSharedServiceCfg<ENV> {
|
|
9
|
-
|
|
10
|
-
* Dir with ${envName}.env.ts files
|
|
11
|
-
*/
|
|
12
|
-
envMap: StringMap<ENV>
|
|
9
|
+
environments: ENV[]
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
export class EnvSharedService<ENV extends BaseEnv> {
|
|
16
|
-
constructor(
|
|
13
|
+
constructor(cfg: EnvSharedServiceCfg<ENV>) {
|
|
14
|
+
this.envMap = _by(cfg.environments, e => e.name)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
envMap: StringMap<ENV>
|
|
17
18
|
|
|
18
19
|
private env?: ENV
|
|
19
20
|
|
|
@@ -26,7 +27,7 @@ export class EnvSharedService<ENV extends BaseEnv> {
|
|
|
26
27
|
const { APP_ENV } = process.env
|
|
27
28
|
_assert(APP_ENV, 'APP_ENV should be defined!')
|
|
28
29
|
|
|
29
|
-
const env = this.
|
|
30
|
+
const env = this.envMap[APP_ENV]
|
|
30
31
|
_assert(env, `Environment ${APP_ENV} is not defined`)
|
|
31
32
|
|
|
32
33
|
this.env = env
|