@catladder/pipeline 1.54.0 → 1.55.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/build/index.d.ts +2 -1
- package/dist/build/types.d.ts +3 -0
- package/dist/bundles/catladder-gitlab/index.js +3 -3
- package/dist/constants.js +1 -1
- package/dist/context/getEnvConfig.d.ts +2 -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 +2 -4
- package/dist/context/getEnvironment.js +15 -195
- 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/index.d.ts +1 -0
- package/dist/context/index.js +12 -16
- package/dist/deploy/cloudRun/deployJob.js +61 -24
- package/dist/deploy/cloudRun/index.d.ts +1 -6
- package/dist/deploy/cloudRun/index.js +51 -31
- package/dist/deploy/index.d.ts +7 -20
- package/dist/deploy/index.js +8 -21
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -3
- package/dist/deploy/kubernetes/additionalSecretKeys.js +5 -5
- package/dist/deploy/kubernetes/index.js +2 -2
- package/dist/deploy/types/googleCloudRun.d.ts +27 -23
- package/dist/deploy/types/index.d.ts +2 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/environmentContext.d.ts +22 -0
- package/dist/types/environmentContext.js +3 -0
- package/package.json +1 -1
- package/src/build/index.ts +4 -1
- package/src/build/types.ts +6 -0
- package/src/context/getEnvConfig.ts +21 -0
- package/src/context/getEnvType.ts +17 -0
- package/src/context/getEnvironment.ts +16 -164
- package/src/context/getEnvironmentContext.ts +57 -0
- package/src/context/getEnvironmentVariables.ts +152 -0
- package/src/context/index.ts +17 -14
- package/src/deploy/cloudRun/deployJob.ts +75 -24
- package/src/deploy/cloudRun/index.ts +12 -23
- package/src/deploy/index.ts +11 -23
- package/src/deploy/kubernetes/additionalSecretKeys.ts +7 -7
- package/src/deploy/kubernetes/index.ts +2 -2
- package/src/deploy/types/googleCloudRun.ts +25 -23
- package/src/types/config.ts +2 -0
- package/src/types/environmentContext.ts +26 -0
|
@@ -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, otherComponentName, env, 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;
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Config } from "../types/config";
|
|
2
2
|
import type { CommitInfo, Context } from "../types/context";
|
|
3
3
|
export * from "./getEnvironment";
|
|
4
|
+
export * from "./getEnvironmentVariables";
|
|
4
5
|
export declare const createContext: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, packageManagerInfo?: import("../types/context").YarnPackageManagerInfo | undefined) => Promise<Context>;
|
package/dist/context/index.js
CHANGED
|
@@ -169,34 +169,30 @@ var utils_1 = require("../utils");
|
|
|
169
169
|
|
|
170
170
|
var getEnvironment_1 = require("./getEnvironment");
|
|
171
171
|
|
|
172
|
+
var getEnvironmentContext_1 = require("./getEnvironmentContext");
|
|
173
|
+
|
|
172
174
|
__exportStar(require("./getEnvironment"), exports);
|
|
173
175
|
|
|
176
|
+
__exportStar(require("./getEnvironmentVariables"), exports);
|
|
177
|
+
|
|
174
178
|
var createContext = function (config, componentName, env, commitInfo, packageManagerInfo) {
|
|
175
179
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
176
|
-
var
|
|
180
|
+
var envContext, componentConfigWithoutDefaults, defaults, componentConfig;
|
|
177
181
|
|
|
178
182
|
var _a;
|
|
179
183
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return __generator(this, function (_d) {
|
|
183
|
-
switch (_d.label) {
|
|
184
|
+
return __generator(this, function (_b) {
|
|
185
|
+
switch (_b.label) {
|
|
184
186
|
case 0:
|
|
185
187
|
if (!/^[a-z0-9-]+$/.test(componentName)) {
|
|
186
188
|
throw new Error("componentName may only contain lower case letters, numbers and -");
|
|
187
189
|
}
|
|
188
190
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (!rawConfig) {
|
|
192
|
-
throw new Error("unknown component " + componentName);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
envConfig = (_c = (_b = rawConfig.env) === null || _b === void 0 ? void 0 : _b[env]) !== null && _c !== void 0 ? _c : {};
|
|
196
|
-
componentConfigWithoutDefaults = (0, utils_1.mergeWithMergingArrays)(rawConfig, envConfig);
|
|
191
|
+
envContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
|
|
192
|
+
componentConfigWithoutDefaults = envContext.envConfigRaw;
|
|
197
193
|
defaults = componentConfigWithoutDefaults.deploy ? {
|
|
198
|
-
build: build_1.BUILD_TYPES[componentConfigWithoutDefaults.build.type].defaults(),
|
|
199
|
-
deploy: deploy_1.DEPLOY_TYPES[componentConfigWithoutDefaults.deploy.type].defaults()
|
|
194
|
+
build: build_1.BUILD_TYPES[componentConfigWithoutDefaults.build.type].defaults(envContext),
|
|
195
|
+
deploy: deploy_1.DEPLOY_TYPES[componentConfigWithoutDefaults.deploy.type].defaults(envContext)
|
|
200
196
|
} : {
|
|
201
197
|
build: {},
|
|
202
198
|
deploy: {}
|
|
@@ -214,7 +210,7 @@ var createContext = function (config, componentName, env, commitInfo, packageMan
|
|
|
214
210
|
case 1:
|
|
215
211
|
return [2
|
|
216
212
|
/*return*/
|
|
217
|
-
, (_a.environment =
|
|
213
|
+
, (_a.environment = _b.sent(), _a.commitInfo = commitInfo, _a.packageManagerInfo = packageManagerInfo, _a)];
|
|
218
214
|
}
|
|
219
215
|
});
|
|
220
216
|
});
|
|
@@ -57,13 +57,15 @@ var types_1 = require("../types");
|
|
|
57
57
|
var gcloudServiceAccountLoginCommands_1 = require("./utils/gcloudServiceAccountLoginCommands");
|
|
58
58
|
|
|
59
59
|
var createGoogleCloudRunDeployJobs = function (context) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
|
|
60
62
|
var deployConfig = context.componentConfig.deploy;
|
|
61
63
|
|
|
62
64
|
if (deployConfig === false) {
|
|
63
65
|
return [];
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun"
|
|
68
|
+
if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
|
|
67
69
|
// should not happen
|
|
68
70
|
throw new Error("deploy config is wrong");
|
|
69
71
|
}
|
|
@@ -84,44 +86,76 @@ var createGoogleCloudRunDeployJobs = function (context) {
|
|
|
84
86
|
return "".concat(key, "=").concat(value);
|
|
85
87
|
}).join(",");
|
|
86
88
|
var commonArgs = "--project ".concat(deployConfig.projectId, " --region=").concat(deployConfig.region);
|
|
89
|
+
var commonDeployArgs = "--image ".concat(gcloudImageName, " ").concat(commonArgs, " --labels ").concat(labelsString);
|
|
90
|
+
var serviceName = context.environment.fullName.toLowerCase();
|
|
87
91
|
|
|
88
|
-
var
|
|
92
|
+
var getServiceDeployScript = function (service) {
|
|
89
93
|
var _a;
|
|
90
94
|
|
|
91
|
-
var
|
|
92
|
-
var command = (_a = deployConfig.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand;
|
|
95
|
+
var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand : undefined;
|
|
93
96
|
var commandArg = command ? "--command=\"".concat(command.split(" ").join(","), "\"") : "";
|
|
94
|
-
|
|
97
|
+
return "gcloud run deploy ".concat(serviceName, " ").concat(commandArg, " ").concat(commonDeployArgs, " --env-vars-file=____envvars.yaml --allow-unauthenticated");
|
|
98
|
+
};
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
var getJobDeployScripts = function (jobName, job) {
|
|
101
|
+
// due to some oversight from google, jobs create does not accept `--env-vars-file` 🤦
|
|
102
|
+
// lucky, update on the other hand accepts it... so let's just imediatly update it
|
|
103
|
+
// also we cannot upsert a job, so we have to create it and catch the error and then update
|
|
104
|
+
var args = "".concat(jobName, " --command=\"").concat(job.command.split(" ").join(","), "\" ").concat(commonDeployArgs);
|
|
105
|
+
return ["set +e", "gcloud beta run jobs create ".concat(args), "set -e", "gcloud beta run jobs update ".concat(args, " --env-vars-file=____envvars.yaml")];
|
|
106
|
+
};
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
108
|
+
var getJobRunScript = function (jobName) {
|
|
109
|
+
return "gcloud beta run jobs execute ".concat(jobName, " ").concat(commonArgs);
|
|
103
110
|
};
|
|
104
111
|
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
var getFullJobName = function (name) {
|
|
113
|
+
return context.environment.fullName.toLowerCase() + "-" + name;
|
|
114
|
+
};
|
|
108
115
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
117
|
+
var _b = __read(_a, 2),
|
|
118
|
+
name = _b[0],
|
|
119
|
+
job = _b[1];
|
|
112
120
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
return [getFullJobName(name), job];
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
var cloudRunDeployScripts = __spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml"], __read(jobsWithNames.map(function (_a) {
|
|
125
|
+
var _b = __read(_a, 2),
|
|
126
|
+
name = _b[0],
|
|
127
|
+
job = _b[1];
|
|
128
|
+
|
|
129
|
+
return getJobDeployScripts(name, job);
|
|
130
|
+
}).flat()), false), __read(deployConfig.service !== false ? [getServiceDeployScript(deployConfig.service)] : []), false), __read(jobsWithNames.filter(function (_a) {
|
|
131
|
+
var _b = __read(_a, 2),
|
|
132
|
+
name = _b[0],
|
|
133
|
+
job = _b[1];
|
|
134
|
+
|
|
135
|
+
return job.when === "postDeploy";
|
|
136
|
+
}).map(function (_a) {
|
|
137
|
+
var _b = __read(_a, 2),
|
|
138
|
+
name = _b[0],
|
|
139
|
+
job = _b[1];
|
|
140
|
+
|
|
141
|
+
return getJobRunScript(name);
|
|
142
|
+
})), false), ["docker image rm ".concat(gcloudImageName)], false);
|
|
143
|
+
|
|
144
|
+
var cloudRunStopScripts = __spreadArray(__spreadArray([], __read(deployConfig.service !== false ? ["gcloud run services delete ".concat(serviceName)] : []), false), __read(Object.entries((_b = deployConfig.jobs) !== null && _b !== void 0 ? _b : {}).map(function (_a) {
|
|
145
|
+
var _b = __read(_a, 2),
|
|
146
|
+
jobName = _b[0],
|
|
147
|
+
job = _b[1];
|
|
148
|
+
|
|
149
|
+
return "gcloud beta run jobs delete ".concat(jobName);
|
|
150
|
+
})), false);
|
|
117
151
|
|
|
118
|
-
var cloudRunDeploy = ["echo \"$ENV_VARS\" > ____envvars.yaml", getDeployCommand(), "docker image rm ".concat(gcloudImageName)];
|
|
119
152
|
var baseStopJob = (0, base_1.getBaseDeploymentStopJob)(context);
|
|
120
153
|
return [(0, lodash_1.merge)({}, baseDeploymentJob, (0, docker_1.getDockerJobBaseProps)(context), {
|
|
121
154
|
artifacts: {
|
|
122
155
|
paths: ["____envvars.yaml"]
|
|
123
156
|
},
|
|
124
157
|
variables: {
|
|
158
|
+
CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
|
|
125
159
|
ENV_VARS: (0, js_yaml_1.dump)(allEnvVars, {
|
|
126
160
|
lineWidth: -1,
|
|
127
161
|
quotingType: "'",
|
|
@@ -129,10 +163,13 @@ var createGoogleCloudRunDeployJobs = function (context) {
|
|
|
129
163
|
})
|
|
130
164
|
},
|
|
131
165
|
image: (0, runner_1.getRunnerImage)("gcloud"),
|
|
132
|
-
script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(
|
|
166
|
+
script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(cloudRunDeployScripts), false)
|
|
133
167
|
}), (0, lodash_1.merge)({}, baseStopJob, {
|
|
134
168
|
image: (0, runner_1.getRunnerImage)("gcloud"),
|
|
135
|
-
|
|
169
|
+
variables: {
|
|
170
|
+
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
|
|
171
|
+
},
|
|
172
|
+
script: __spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), __read(cloudRunStopScripts), false)
|
|
136
173
|
})];
|
|
137
174
|
};
|
|
138
175
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { DeployTypeDefinition } from "..";
|
|
2
2
|
export declare const GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
|
|
3
3
|
export declare const GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
|
|
4
|
-
export declare const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun">;
|
|
5
|
-
export declare const GCLOUD_RUN_JOB_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun-job">;
|
|
6
|
-
export declare const GCLOUD_RUN_DEPLOY_TYPES: {
|
|
7
|
-
"google-cloudrun": DeployTypeDefinition<"google-cloudrun">;
|
|
8
|
-
"google-cloudrun-job": DeployTypeDefinition<"google-cloudrun-job">;
|
|
9
|
-
};
|
|
4
|
+
export declare const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun">;
|
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
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 __read = this && this.__read || function (o, n) {
|
|
18
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
+
if (!m) return o;
|
|
20
|
+
var i = m.call(o),
|
|
21
|
+
r,
|
|
22
|
+
ar = [],
|
|
23
|
+
e;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
e = {
|
|
29
|
+
error: error
|
|
30
|
+
};
|
|
31
|
+
} finally {
|
|
32
|
+
try {
|
|
33
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
34
|
+
} finally {
|
|
35
|
+
if (e) throw e.error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
|
|
3
42
|
exports.__esModule = true;
|
|
4
|
-
exports.
|
|
43
|
+
exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
|
|
5
44
|
|
|
6
45
|
var context_1 = require("../../context");
|
|
7
46
|
|
|
@@ -20,37 +59,18 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
|
|
|
20
59
|
getAdditionalEnvVars: function (_a) {
|
|
21
60
|
var fullName = _a.fullName,
|
|
22
61
|
env = _a.env,
|
|
23
|
-
componentName = _a.componentName
|
|
62
|
+
componentName = _a.componentName,
|
|
63
|
+
deployConfigRaw = _a.deployConfigRaw;
|
|
24
64
|
var HOST_CANONICAL = fullName.toLowerCase() + "-" + process.env[(0, context_1.getSecretVarName)(env, componentName, exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
exports.GCLOUD_RUN_JOB_DEPLOY_TYPE = {
|
|
31
|
-
jobs: deployJob_1.createGoogleCloudRunDeployJobs,
|
|
32
|
-
defaults: function () {
|
|
33
|
-
return {};
|
|
34
|
-
},
|
|
35
|
-
additionalSecretKeys: function () {
|
|
36
|
-
return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
|
|
37
|
-
},
|
|
38
|
-
getAdditionalEnvVars: function (_a) {
|
|
39
|
-
var deployConfig = _a.deployConfig,
|
|
40
|
-
fullName = _a.fullName;
|
|
41
|
-
|
|
42
|
-
if (!deployConfig) {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
65
|
+
var jobTriggers = deployConfigRaw && deployConfigRaw.jobs ? Object.fromEntries(Object.entries(deployConfigRaw.jobs).map(function (_a) {
|
|
66
|
+
var _b = __read(_a, 2),
|
|
67
|
+
name = _b[0],
|
|
68
|
+
job = _b[1];
|
|
45
69
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
|
|
50
|
-
};
|
|
70
|
+
return ["CLOUD_RUN_JOB_TRIGGER_URL_" + name, "https://".concat(deployConfigRaw.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfigRaw.projectId, "/jobs/").concat(name, ":run")];
|
|
71
|
+
})) : {};
|
|
72
|
+
return __assign({
|
|
73
|
+
HOST_CANONICAL: HOST_CANONICAL
|
|
74
|
+
}, jobTriggers);
|
|
51
75
|
}
|
|
52
|
-
};
|
|
53
|
-
exports.GCLOUD_RUN_DEPLOY_TYPES = {
|
|
54
|
-
"google-cloudrun": exports.GCLOUD_RUN_DEPLOY_TYPE,
|
|
55
|
-
"google-cloudrun-job": exports.GCLOUD_RUN_JOB_DEPLOY_TYPE
|
|
56
76
|
};
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Context } from "../types/context";
|
|
2
|
+
import type { EnvironmentContext } from "../types/environmentContext";
|
|
3
3
|
import type { CatladderJob } from "../types/jobs";
|
|
4
4
|
import type { DeployConfigGeneric, DeployConfigType } from "./types";
|
|
5
|
+
export * from "./cloudRun";
|
|
6
|
+
export * from "./cloudSql";
|
|
5
7
|
export * from "./kubernetes";
|
|
6
8
|
export * from "./types";
|
|
7
9
|
export * from "./utils";
|
|
8
|
-
export declare type EnvVarContext<D extends DeployConfigType> = {
|
|
9
|
-
deployConfig: false | DeployConfigGeneric<D>;
|
|
10
|
-
commitInfo?: CommitInfo;
|
|
11
|
-
env: string;
|
|
12
|
-
envType: EnvType;
|
|
13
|
-
componentName: string;
|
|
14
|
-
fullName: string;
|
|
15
|
-
/**
|
|
16
|
-
* the full catladder config
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
fullConfig: Config;
|
|
20
|
-
};
|
|
21
10
|
export declare type DeployTypeDefinition<T extends DeployConfigType> = {
|
|
22
11
|
jobs: (context: Context) => CatladderJob[];
|
|
23
|
-
defaults: () => Partial<DeployConfigGeneric<T>>;
|
|
24
|
-
additionalSecretKeys: (
|
|
25
|
-
getAdditionalEnvVars: (
|
|
12
|
+
defaults: (envContext: EnvironmentContext<any, T>) => Partial<DeployConfigGeneric<T>>;
|
|
13
|
+
additionalSecretKeys: (envContext: EnvironmentContext<any, T>) => string[];
|
|
14
|
+
getAdditionalEnvVars: (envContext: EnvironmentContext<any, T>) => Record<string, string | undefined | null>;
|
|
26
15
|
};
|
|
27
|
-
export * from "./cloudSql";
|
|
28
|
-
export * from "./cloudRun";
|
|
29
16
|
export declare type DeployTypes = { [T in DeployConfigType]: DeployTypeDefinition<T> };
|
|
30
17
|
export declare const DEPLOY_TYPES: DeployTypes;
|