@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-refactor-env-context-9e652b63
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/bin/catladder-gitlab.js +1 -1
- package/dist/build/base/createBuildJob.d.ts +2 -2
- package/dist/build/base/getBuildInfo.d.ts +1 -1
- package/dist/build/docker.d.ts +44 -6
- package/dist/build/docker.js +45 -19
- package/dist/build/index.d.ts +6 -5
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/cache.d.ts +2 -2
- package/dist/build/node/index.d.ts +1 -1
- package/dist/build/node/meteor.d.ts +1 -1
- package/dist/build/node/meteor.js +6 -0
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +3 -0
- package/dist/build/node/yarn.d.ts +1 -1
- package/dist/build/node/yarn.js +13 -1
- package/dist/build/types.d.ts +10 -0
- package/dist/bundles/catladder-gitlab/index.js +32457 -0
- package/dist/catladder-gitlab.js +1 -2
- package/dist/config/configruedEnvs.d.ts +1 -1
- package/dist/config/readConfig.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/getEnvConfig.d.ts +9 -0
- package/dist/context/getEnvConfig.js +26 -0
- package/dist/context/getEnvType.d.ts +4 -0
- package/dist/context/getEnvType.js +18 -0
- package/dist/context/getEnvironment.d.ts +3 -0
- package/dist/context/getEnvironment.js +187 -0
- package/dist/context/getEnvironmentContext.d.ts +4 -0
- package/dist/context/getEnvironmentContext.js +36 -0
- package/dist/context/getEnvironmentVariables.d.ts +10 -0
- package/dist/context/getEnvironmentVariables.js +322 -0
- package/dist/context/getLabels.d.ts +8 -0
- package/dist/context/getLabels.js +49 -0
- package/dist/context/index.d.ts +5 -6
- package/dist/context/index.js +176 -181
- package/dist/context/resolveReferences.d.ts +1 -3
- package/dist/context/resolveReferences.js +275 -26
- package/dist/context/resolveReferences.test.js +332 -81
- package/dist/defaults/index.d.ts +1 -1
- package/dist/deploy/base.d.ts +4 -2
- package/dist/deploy/base.js +37 -17
- package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
- package/dist/deploy/cloudRun/deployJob.js +139 -0
- package/dist/deploy/cloudRun/index.d.ts +9 -0
- package/dist/deploy/cloudRun/index.js +56 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +14 -0
- package/dist/deploy/cloudSql/index.d.ts +8 -0
- package/dist/deploy/cloudSql/index.js +30 -0
- package/dist/deploy/custom/deployJob.d.ts +2 -2
- package/dist/deploy/custom/deployJob.js +4 -1
- package/dist/deploy/custom/index.d.ts +2 -1
- package/dist/deploy/custom/index.js +15 -18
- package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
- package/dist/deploy/dockerTag/deployJob.js +33 -0
- package/dist/deploy/dockerTag/index.d.ts +2 -0
- package/dist/deploy/dockerTag/index.js +19 -0
- package/dist/deploy/index.d.ts +12 -8
- package/dist/deploy/index.js +27 -14
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
- package/dist/deploy/kubernetes/additionalSecretKeys.js +33 -0
- package/dist/deploy/kubernetes/cloudsql.d.ts +1 -1
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +13 -66
- package/dist/deploy/kubernetes/index.d.ts +2 -1
- package/dist/deploy/kubernetes/index.js +45 -16
- package/dist/deploy/kubernetes/kubeEnv.d.ts +10 -0
- package/dist/deploy/kubernetes/kubeEnv.js +90 -0
- package/dist/deploy/kubernetes/kubeValues.d.ts +90 -0
- package/dist/deploy/kubernetes/kubeValues.js +96 -0
- package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
- package/dist/deploy/kubernetes/mongodb.js +118 -8
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +21 -21
- package/dist/deploy/types/base.d.ts +15 -0
- package/dist/deploy/types/base.js +3 -0
- package/dist/deploy/types/custom.d.ts +27 -0
- package/dist/deploy/types/custom.js +3 -0
- package/dist/deploy/types/dockerTag.d.ts +10 -0
- package/dist/deploy/types/dockerTag.js +3 -0
- package/dist/deploy/types/googleCloudRun.d.ts +39 -0
- package/dist/deploy/types/googleCloudRun.js +3 -0
- package/dist/deploy/types/index.d.ts +24 -0
- package/dist/deploy/types/index.js +41 -0
- package/dist/deploy/{types.d.ts → types/kubernetes.d.ts} +128 -36
- package/dist/deploy/types/kubernetes.js +3 -0
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/deploy/utils.js +4 -0
- package/dist/pipeline/createChildPipeline.d.ts +2 -2
- package/dist/pipeline/createChildPipeline.js +3 -3
- package/dist/pipeline/createJobs.d.ts +2 -2
- package/dist/pipeline/createJobs.js +63 -25
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +3 -2
- package/dist/pipeline/gitlab/makeGitlabJob.js +2 -1
- package/dist/pipeline/packageManager.d.ts +1 -1
- package/dist/rules/index.d.ts +1 -1
- package/dist/runner/index.d.ts +2 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +7 -6
- package/dist/types/config.js +1 -1
- package/dist/types/context.d.ts +10 -2
- package/dist/types/environmentContext.d.ts +22 -0
- package/dist/types/environmentContext.js +3 -0
- package/dist/types/gitlab-types.d.ts +1 -1
- package/dist/types/jobs.d.ts +8 -3
- package/dist/types/jobs.js +1 -1
- package/dist/types/pipeline.d.ts +1 -1
- package/package.json +15 -11
- package/scripts/bundle +2 -0
- package/src/build/base/createBuildJob.ts +3 -2
- package/src/build/base/getBuildInfo.ts +1 -1
- package/src/build/docker.ts +47 -29
- package/src/build/index.ts +8 -5
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +2 -2
- package/src/build/node/index.ts +1 -1
- package/src/build/node/meteor.ts +8 -2
- package/src/build/node/testJob.ts +4 -2
- package/src/build/node/yarn.ts +21 -10
- package/src/build/tests/storybook.test.ts +1 -1
- package/src/build/types.ts +13 -1
- package/src/catladder-gitlab.ts +4 -2
- package/src/config/configruedEnvs.test.ts +2 -2
- package/src/config/configruedEnvs.ts +5 -4
- package/src/config/readConfig.ts +1 -1
- package/src/context/getEnvConfig.ts +21 -0
- package/src/context/getEnvType.ts +17 -0
- package/src/context/getEnvironment.ts +40 -0
- package/src/context/getEnvironmentContext.ts +57 -0
- package/src/context/getEnvironmentVariables.ts +152 -0
- package/src/context/getLabels.ts +20 -0
- package/src/context/index.ts +25 -191
- package/src/context/resolveReferences.test.ts +15 -15
- package/src/context/resolveReferences.ts +37 -30
- package/src/defaults/index.ts +1 -1
- package/src/deploy/base.ts +43 -19
- package/src/deploy/cloudRun/deployJob.ts +104 -0
- package/src/deploy/cloudRun/index.ts +48 -0
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
- package/src/deploy/cloudSql/index.ts +16 -0
- package/src/deploy/custom/deployJob.ts +10 -3
- package/src/deploy/custom/index.ts +9 -1
- package/src/deploy/dockerTag/deployJob.ts +31 -0
- package/src/deploy/dockerTag/index.ts +9 -0
- package/src/deploy/index.ts +26 -17
- package/src/deploy/kubernetes/additionalSecretKeys.ts +23 -0
- package/src/deploy/kubernetes/cloudsql.ts +2 -1
- package/src/deploy/kubernetes/deployJob.ts +19 -77
- package/src/deploy/kubernetes/index.ts +42 -1
- package/src/deploy/kubernetes/kubeEnv.ts +48 -0
- package/src/deploy/kubernetes/kubeValues.ts +82 -0
- package/src/deploy/kubernetes/mongodb.ts +104 -7
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +1 -1
- package/src/deploy/types/base.ts +17 -0
- package/src/deploy/types/custom.ts +24 -0
- package/src/deploy/types/dockerTag.ts +12 -0
- package/src/deploy/types/googleCloudRun.ts +79 -0
- package/src/deploy/types/index.ts +28 -0
- package/src/deploy/types/kubernetes.ts +281 -0
- package/src/deploy/utils.ts +6 -2
- package/src/pipeline/createChildPipeline.test.ts +1 -1
- package/src/pipeline/createChildPipeline.ts +4 -4
- package/src/pipeline/createJobs.ts +32 -21
- package/src/pipeline/gitlab/makeGitlabJob.ts +3 -2
- package/src/pipeline/packageManager.ts +1 -1
- package/src/rules/index.ts +1 -1
- package/src/runner/index.ts +2 -1
- package/src/types/config.ts +8 -6
- package/src/types/context.ts +14 -2
- package/src/types/environmentContext.ts +26 -0
- package/src/types/gitlab-types.ts +1 -1
- package/src/types/jobs.ts +9 -2
- package/src/types/pipeline.ts +1 -1
- package/tsconfig.json +2 -0
- package/dist/deploy/types.js +0 -16
- package/src/deploy/types.ts +0 -189
package/dist/catladder-gitlab.js
CHANGED
|
@@ -45,8 +45,7 @@ var _b = process.env,
|
|
|
45
45
|
CI_COMMIT_BRANCH = _b.CI_COMMIT_BRANCH,
|
|
46
46
|
CI_DEFAULT_BRANCH = _b.CI_DEFAULT_BRANCH;
|
|
47
47
|
var isDefaultBranch = Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
|
|
48
|
-
var isHotfixBranch =
|
|
49
|
-
|
|
48
|
+
var isHotfixBranch = CI_COMMIT_BRANCH ? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH) : false;
|
|
50
49
|
var isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
51
50
|
var isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
52
51
|
console.info("catladder version ".concat(constants_1.PIPELINE_IMAGE_TAG));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, PipelineTrigger } from "../types";
|
|
1
|
+
import type { Config, PipelineTrigger } from "../types";
|
|
2
2
|
export declare const getAllEnvs: (config: Config, componentName: string) => string[];
|
|
3
3
|
export declare const getAllEnvsInAllComponents: (config: Config) => string[];
|
|
4
4
|
export declare const getAllEnvsByTrigger: (config: Config, componentName: string, trigger: PipelineTrigger) => string[];
|
package/dist/constants.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
|
|
5
|
-
exports.PIPELINE_IMAGE_TAG = "
|
|
5
|
+
exports.PIPELINE_IMAGE_TAG = "refactor-env-context-9e652b63" || "";
|
|
6
6
|
exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from "../types/config";
|
|
2
|
+
export declare const getEnvConfig: (config: Config, componentName: string, env: string) => {
|
|
3
|
+
env?: import("../types/config").Env | undefined;
|
|
4
|
+
dir: string;
|
|
5
|
+
customJobs?: import("../types/jobs").CatladderJob<"test" | "stop" | "setup" | "build" | "deploy" | "verify" | "rollback">[] | ((context: import("..").Context) => import("../types/jobs").CatladderJob<"test" | "stop" | "setup" | "build" | "deploy" | "verify" | "rollback">[]) | undefined;
|
|
6
|
+
} & import("../types/config").DefaultEnvConfig & {
|
|
7
|
+
type?: "dev" | "review" | "stage" | "prod" | "local" | undefined;
|
|
8
|
+
host?: string | undefined;
|
|
9
|
+
} & import("type-fest/source/partial-deep").PartialObjectDeep<import("../types/config").DefaultEnvConfig>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getEnvConfig = void 0;
|
|
5
|
+
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
|
|
8
|
+
var getEnvConfig = function (config, componentName, env) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
|
|
11
|
+
var defaultConfig = config.components[componentName];
|
|
12
|
+
|
|
13
|
+
if (!defaultConfig) {
|
|
14
|
+
throw new Error("unknown component " + componentName);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var envCustomizations = (_b = (_a = defaultConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
|
|
18
|
+
|
|
19
|
+
if (envCustomizations === false) {
|
|
20
|
+
throw new Error("env is disabled: " + env);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (0, utils_1.mergeWithMergingArrays)(defaultConfig, envCustomizations);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.getEnvConfig = getEnvConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getEnvType = void 0;
|
|
5
|
+
|
|
6
|
+
var types_1 = require("../types");
|
|
7
|
+
|
|
8
|
+
var getEnvType = function (env, envConfig) {
|
|
9
|
+
if (envConfig.type) return envConfig.type;
|
|
10
|
+
|
|
11
|
+
if ((0, types_1.isKnowEnvType)(env)) {
|
|
12
|
+
return env;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
throw new Error("unknown env type: " + env);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.getEnvType = getEnvType;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.next(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
36
|
+
var _ = {
|
|
37
|
+
label: 0,
|
|
38
|
+
sent: function () {
|
|
39
|
+
if (t[0] & 1) throw t[1];
|
|
40
|
+
return t[1];
|
|
41
|
+
},
|
|
42
|
+
trys: [],
|
|
43
|
+
ops: []
|
|
44
|
+
},
|
|
45
|
+
f,
|
|
46
|
+
y,
|
|
47
|
+
t,
|
|
48
|
+
g;
|
|
49
|
+
return g = {
|
|
50
|
+
next: verb(0),
|
|
51
|
+
"throw": verb(1),
|
|
52
|
+
"return": verb(2)
|
|
53
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
54
|
+
return this;
|
|
55
|
+
}), g;
|
|
56
|
+
|
|
57
|
+
function verb(n) {
|
|
58
|
+
return function (v) {
|
|
59
|
+
return step([n, v]);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function step(op) {
|
|
64
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
65
|
+
|
|
66
|
+
while (_) try {
|
|
67
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
68
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
69
|
+
|
|
70
|
+
switch (op[0]) {
|
|
71
|
+
case 0:
|
|
72
|
+
case 1:
|
|
73
|
+
t = op;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case 4:
|
|
77
|
+
_.label++;
|
|
78
|
+
return {
|
|
79
|
+
value: op[1],
|
|
80
|
+
done: false
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
case 5:
|
|
84
|
+
_.label++;
|
|
85
|
+
y = op[1];
|
|
86
|
+
op = [0];
|
|
87
|
+
continue;
|
|
88
|
+
|
|
89
|
+
case 7:
|
|
90
|
+
op = _.ops.pop();
|
|
91
|
+
|
|
92
|
+
_.trys.pop();
|
|
93
|
+
|
|
94
|
+
continue;
|
|
95
|
+
|
|
96
|
+
default:
|
|
97
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
98
|
+
_ = 0;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
103
|
+
_.label = op[1];
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
108
|
+
_.label = t[1];
|
|
109
|
+
t = op;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (t && _.label < t[2]) {
|
|
114
|
+
_.label = t[2];
|
|
115
|
+
|
|
116
|
+
_.ops.push(op);
|
|
117
|
+
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (t[2]) _.ops.pop();
|
|
122
|
+
|
|
123
|
+
_.trys.pop();
|
|
124
|
+
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
op = body.call(thisArg, _);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
op = [6, e];
|
|
131
|
+
y = 0;
|
|
132
|
+
} finally {
|
|
133
|
+
f = t = 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (op[0] & 5) throw op[1];
|
|
137
|
+
return {
|
|
138
|
+
value: op[0] ? op[1] : void 0,
|
|
139
|
+
done: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
exports.__esModule = true;
|
|
145
|
+
exports.getEnvironment = void 0;
|
|
146
|
+
|
|
147
|
+
var getEnvironmentContext_1 = require("./getEnvironmentContext");
|
|
148
|
+
|
|
149
|
+
var getEnvironmentVariables_1 = require("./getEnvironmentVariables");
|
|
150
|
+
|
|
151
|
+
var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
152
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
+
var _a, envVars, secretEnvVarKeys, host, url, envVarContext, envType;
|
|
154
|
+
|
|
155
|
+
return __generator(this, function (_b) {
|
|
156
|
+
switch (_b.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
return [4
|
|
159
|
+
/*yield*/
|
|
160
|
+
, (0, getEnvironmentVariables_1.getEnvironmentVariables)(config, componentName, env, commitInfo)];
|
|
161
|
+
|
|
162
|
+
case 1:
|
|
163
|
+
_a = _b.sent(), envVars = _a.envVars, secretEnvVarKeys = _a.secretEnvVarKeys, host = _a.host, url = _a.url;
|
|
164
|
+
envVarContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
|
|
165
|
+
envType = envVarContext.envType;
|
|
166
|
+
return [2
|
|
167
|
+
/*return*/
|
|
168
|
+
, {
|
|
169
|
+
envType: envType,
|
|
170
|
+
host: host,
|
|
171
|
+
url: url,
|
|
172
|
+
gitlabEnvironment: {
|
|
173
|
+
name: envVarContext.gitlabEnvironmentName,
|
|
174
|
+
url: url
|
|
175
|
+
},
|
|
176
|
+
fullName: envVarContext.fullName,
|
|
177
|
+
slug: envVarContext.environmentSlug,
|
|
178
|
+
shortName: env,
|
|
179
|
+
envVars: envVars,
|
|
180
|
+
secretEnvVarKeys: secretEnvVarKeys
|
|
181
|
+
}];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
exports.getEnvironment = getEnvironment;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Config } from "../types/config";
|
|
2
|
+
import type { CommitInfo } from "../types/context";
|
|
3
|
+
import type { EnvironmentContext } from "../types/environmentContext";
|
|
4
|
+
export declare const getEnvironmentContext: (config: Config, env: string, componentName: string, commitInfo?: CommitInfo | undefined) => EnvironmentContext<any, any>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getEnvironmentContext = void 0;
|
|
5
|
+
|
|
6
|
+
var getEnvConfig_1 = require("./getEnvConfig");
|
|
7
|
+
|
|
8
|
+
var getEnvType_1 = require("./getEnvType");
|
|
9
|
+
|
|
10
|
+
var getEnvironmentSlug = function (envConfig, env, componentName, commitInfo) {
|
|
11
|
+
var envType = (0, getEnvType_1.getEnvType)(env, envConfig);
|
|
12
|
+
return envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.reviewSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var getEnvironmentContext = function (config, env, componentName, commitInfo) {
|
|
16
|
+
var envConfigRaw = (0, getEnvConfig_1.getEnvConfig)(config, componentName, env);
|
|
17
|
+
var envType = (0, getEnvType_1.getEnvType)(env, envConfigRaw);
|
|
18
|
+
var environmentSlug = getEnvironmentSlug(envConfigRaw, env, componentName, commitInfo);
|
|
19
|
+
var gitlabEnvironmentName = envType === "review" && commitInfo ? "".concat(env, "/").concat(commitInfo.refName, "/").concat(componentName) : "".concat(env, "/").concat(componentName);
|
|
20
|
+
var fullName = "".concat(config.customerName, "-").concat(config.appName, "-").concat(environmentSlug);
|
|
21
|
+
return {
|
|
22
|
+
envConfigRaw: envConfigRaw,
|
|
23
|
+
deployConfigRaw: envConfigRaw.deploy,
|
|
24
|
+
buildConfigRaw: envConfigRaw.build,
|
|
25
|
+
environmentSlug: environmentSlug,
|
|
26
|
+
gitlabEnvironmentName: gitlabEnvironmentName,
|
|
27
|
+
fullName: fullName,
|
|
28
|
+
envType: envType,
|
|
29
|
+
commitInfo: commitInfo,
|
|
30
|
+
componentName: componentName,
|
|
31
|
+
env: env,
|
|
32
|
+
fullConfig: config
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.getEnvironmentContext = getEnvironmentContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CommitInfo, Context } from "../types";
|
|
2
|
+
import type { Config } from "../types/config";
|
|
3
|
+
export declare const getEnvironmentVariables: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, alreadyVisited?: Record<string, Record<string, boolean>>) => Promise<{
|
|
4
|
+
envVars: Record<string, string>;
|
|
5
|
+
secretEnvVarKeys: string[];
|
|
6
|
+
host: string;
|
|
7
|
+
url: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const getSecretVarName: (env: string, componentName: string, key: string) => string;
|
|
10
|
+
export declare const getSecretVarNameForContext: (context: Context, key: string) => string;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __assign = this && this.__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) {
|
|
19
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.next(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function rejected(value) {
|
|
34
|
+
try {
|
|
35
|
+
step(generator["throw"](value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function step(result) {
|
|
42
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
50
|
+
var _ = {
|
|
51
|
+
label: 0,
|
|
52
|
+
sent: function () {
|
|
53
|
+
if (t[0] & 1) throw t[1];
|
|
54
|
+
return t[1];
|
|
55
|
+
},
|
|
56
|
+
trys: [],
|
|
57
|
+
ops: []
|
|
58
|
+
},
|
|
59
|
+
f,
|
|
60
|
+
y,
|
|
61
|
+
t,
|
|
62
|
+
g;
|
|
63
|
+
return g = {
|
|
64
|
+
next: verb(0),
|
|
65
|
+
"throw": verb(1),
|
|
66
|
+
"return": verb(2)
|
|
67
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
68
|
+
return this;
|
|
69
|
+
}), g;
|
|
70
|
+
|
|
71
|
+
function verb(n) {
|
|
72
|
+
return function (v) {
|
|
73
|
+
return step([n, v]);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function step(op) {
|
|
78
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
79
|
+
|
|
80
|
+
while (_) try {
|
|
81
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
82
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
83
|
+
|
|
84
|
+
switch (op[0]) {
|
|
85
|
+
case 0:
|
|
86
|
+
case 1:
|
|
87
|
+
t = op;
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case 4:
|
|
91
|
+
_.label++;
|
|
92
|
+
return {
|
|
93
|
+
value: op[1],
|
|
94
|
+
done: false
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
case 5:
|
|
98
|
+
_.label++;
|
|
99
|
+
y = op[1];
|
|
100
|
+
op = [0];
|
|
101
|
+
continue;
|
|
102
|
+
|
|
103
|
+
case 7:
|
|
104
|
+
op = _.ops.pop();
|
|
105
|
+
|
|
106
|
+
_.trys.pop();
|
|
107
|
+
|
|
108
|
+
continue;
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
112
|
+
_ = 0;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
117
|
+
_.label = op[1];
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
122
|
+
_.label = t[1];
|
|
123
|
+
t = op;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (t && _.label < t[2]) {
|
|
128
|
+
_.label = t[2];
|
|
129
|
+
|
|
130
|
+
_.ops.push(op);
|
|
131
|
+
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (t[2]) _.ops.pop();
|
|
136
|
+
|
|
137
|
+
_.trys.pop();
|
|
138
|
+
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
op = body.call(thisArg, _);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
op = [6, e];
|
|
145
|
+
y = 0;
|
|
146
|
+
} finally {
|
|
147
|
+
f = t = 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (op[0] & 5) throw op[1];
|
|
151
|
+
return {
|
|
152
|
+
value: op[0] ? op[1] : void 0,
|
|
153
|
+
done: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
var __read = this && this.__read || function (o, n) {
|
|
159
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
160
|
+
if (!m) return o;
|
|
161
|
+
var i = m.call(o),
|
|
162
|
+
r,
|
|
163
|
+
ar = [],
|
|
164
|
+
e;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
e = {
|
|
170
|
+
error: error
|
|
171
|
+
};
|
|
172
|
+
} finally {
|
|
173
|
+
try {
|
|
174
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
175
|
+
} finally {
|
|
176
|
+
if (e) throw e.error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return ar;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
184
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
185
|
+
if (ar || !(i in from)) {
|
|
186
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
187
|
+
ar[i] = from[i];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
exports.__esModule = true;
|
|
194
|
+
exports.getSecretVarNameForContext = exports.getSecretVarName = exports.getEnvironmentVariables = void 0;
|
|
195
|
+
|
|
196
|
+
var lodash_1 = require("lodash");
|
|
197
|
+
|
|
198
|
+
var deploy_1 = require("../deploy");
|
|
199
|
+
|
|
200
|
+
var getEnvironmentContext_1 = require("./getEnvironmentContext");
|
|
201
|
+
|
|
202
|
+
var resolveReferences_1 = require("./resolveReferences");
|
|
203
|
+
|
|
204
|
+
var getEnvironmentVariables = function (config, componentName, env, commitInfo, alreadyVisited // to prevent endless loop
|
|
205
|
+
) {
|
|
206
|
+
if (alreadyVisited === void 0) {
|
|
207
|
+
alreadyVisited = {};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
211
|
+
var environmentContext, envConfigRaw, deployConfigRaw, envType, basePredefinedVariables, predefinedVariables, host, url, devLocalConfig, port, additionalEnvVars, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, legacyFromComponents, publicEnvVarsRawWithLegasyFromComponents, publicEnvVarsRawSanitized, envVarsRaw, envVars;
|
|
212
|
+
|
|
213
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
214
|
+
|
|
215
|
+
return __generator(this, function (_k) {
|
|
216
|
+
switch (_k.label) {
|
|
217
|
+
case 0:
|
|
218
|
+
environmentContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
|
|
219
|
+
envConfigRaw = environmentContext.envConfigRaw, deployConfigRaw = environmentContext.deployConfigRaw, envType = environmentContext.envType;
|
|
220
|
+
basePredefinedVariables = {
|
|
221
|
+
ENV_SHORT: env,
|
|
222
|
+
APP_DIR: envConfigRaw.dir,
|
|
223
|
+
ENV_TYPE: envType
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (envType === "local") {
|
|
227
|
+
devLocalConfig = envConfigRaw;
|
|
228
|
+
port = (_a = devLocalConfig.port) !== null && _a !== void 0 ? _a : 3000;
|
|
229
|
+
host = "localhost:" + port;
|
|
230
|
+
url = "http://" + host;
|
|
231
|
+
predefinedVariables = {
|
|
232
|
+
ENV_SHORT: "local",
|
|
233
|
+
ROOT_URL: url,
|
|
234
|
+
PORT: port.toString()
|
|
235
|
+
};
|
|
236
|
+
} else {
|
|
237
|
+
additionalEnvVars = deployConfigRaw ? deploy_1.DEPLOY_TYPES[deployConfigRaw.type].getAdditionalEnvVars(environmentContext) : {};
|
|
238
|
+
host = (_c = (_b = envConfigRaw === null || envConfigRaw === void 0 ? void 0 : envConfigRaw.host) !== null && _b !== void 0 ? _b : additionalEnvVars.HOST_CANONICAL) !== null && _c !== void 0 ? _c : "unknown-host.example.com";
|
|
239
|
+
url = "https://".concat(host);
|
|
240
|
+
predefinedVariables = __assign(__assign(__assign({}, basePredefinedVariables), {
|
|
241
|
+
HOST: host,
|
|
242
|
+
ROOT_URL: url
|
|
243
|
+
}), additionalEnvVars);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
publicEnvVarsRaw = (_e = (_d = envConfigRaw.vars) === null || _d === void 0 ? void 0 : _d.public) !== null && _e !== void 0 ? _e : {};
|
|
247
|
+
additionalSecretKeys = deployConfigRaw ? deploy_1.DEPLOY_TYPES[deployConfigRaw.type].additionalSecretKeys(environmentContext) : [];
|
|
248
|
+
secretEnvVarKeys = __spreadArray(__spreadArray([], __read((_g = (_f = envConfigRaw.vars) === null || _f === void 0 ? void 0 : _f.secret) !== null && _g !== void 0 ? _g : []), false), __read(additionalSecretKeys), false);
|
|
249
|
+
secretEnvVars = Object.fromEntries(secretEnvVarKeys.map(function (key) {
|
|
250
|
+
return [key, "$".concat((0, exports.getSecretVarName)(env, componentName, key))];
|
|
251
|
+
}));
|
|
252
|
+
legacyFromComponents = (_j = (_h = envConfigRaw.vars) === null || _h === void 0 ? void 0 : _h.fromComponents) !== null && _j !== void 0 ? _j : {};
|
|
253
|
+
publicEnvVarsRawWithLegasyFromComponents = (0, lodash_1.merge)({}, (0, resolveReferences_1.translateLegacyFromComponents)(legacyFromComponents), publicEnvVarsRaw);
|
|
254
|
+
publicEnvVarsRawSanitized = Object.fromEntries(Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(function (_a) {
|
|
255
|
+
var _b = __read(_a, 2),
|
|
256
|
+
key = _b[0],
|
|
257
|
+
value = _b[1];
|
|
258
|
+
|
|
259
|
+
return [key, (0, lodash_1.isObject)(value) ? JSON.stringify(value) : "".concat(value)];
|
|
260
|
+
}));
|
|
261
|
+
envVarsRaw = addIndexVar(__assign(__assign(__assign({}, predefinedVariables), secretEnvVars), publicEnvVarsRawSanitized));
|
|
262
|
+
return [4
|
|
263
|
+
/*yield*/
|
|
264
|
+
, (0, resolveReferences_1.resolveReferences)(envVarsRaw, function (otherComponentName, variableName, alreadyVisited) {
|
|
265
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
+
var otherEnvVars;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
return [4
|
|
271
|
+
/*yield*/
|
|
272
|
+
, (0, exports.getEnvironmentVariables)(config, env, otherComponentName, commitInfo, alreadyVisited)];
|
|
273
|
+
|
|
274
|
+
case 1:
|
|
275
|
+
otherEnvVars = _a.sent().envVars;
|
|
276
|
+
return [2
|
|
277
|
+
/*return*/
|
|
278
|
+
, otherEnvVars[variableName]];
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
}, alreadyVisited)];
|
|
283
|
+
|
|
284
|
+
case 1:
|
|
285
|
+
envVars = _k.sent();
|
|
286
|
+
return [2
|
|
287
|
+
/*return*/
|
|
288
|
+
, {
|
|
289
|
+
envVars: envVars,
|
|
290
|
+
secretEnvVarKeys: secretEnvVarKeys,
|
|
291
|
+
host: host,
|
|
292
|
+
url: url
|
|
293
|
+
}];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
exports.getEnvironmentVariables = getEnvironmentVariables;
|
|
300
|
+
|
|
301
|
+
var sanitizeForEnVar = function (s) {
|
|
302
|
+
return s.replace(/-/g, "_");
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
var getSecretVarName = function (env, componentName, key) {
|
|
306
|
+
return "CL_".concat(sanitizeForEnVar(env), "_").concat(sanitizeForEnVar(componentName), "_").concat(key);
|
|
307
|
+
}; // remove dash from component name
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
exports.getSecretVarName = getSecretVarName;
|
|
311
|
+
|
|
312
|
+
var addIndexVar = function (vars) {
|
|
313
|
+
return __assign(__assign({}, vars), {
|
|
314
|
+
_ALL_ENV_VAR_KEYS: JSON.stringify(Object.keys(vars))
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
var getSecretVarNameForContext = function (context, key) {
|
|
319
|
+
return (0, exports.getSecretVarName)(context.environment.shortName, context.componentName, key);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
exports.getSecretVarNameForContext = getSecretVarNameForContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context } from "../types";
|
|
2
|
+
export declare const getLabels: (context: Context) => {
|
|
3
|
+
"customer-name": string | undefined;
|
|
4
|
+
"app-name": string | undefined;
|
|
5
|
+
"env-type": string | undefined;
|
|
6
|
+
"env-name": string | undefined;
|
|
7
|
+
"build-type": string | undefined;
|
|
8
|
+
};
|