@catladder/pipeline 0.0.0-refactor-env-context-82b68348 → 0.0.0-refactor-env-context-834a2b56
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 +1 -1
- package/dist/bundles/catladder-gitlab/index.js +124 -80
- package/dist/constants.js +1 -1
- package/dist/context/getEnvConfig.d.ts +2 -9
- package/dist/context/getEnvironment.js +6 -6
- 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 +3 -3
- package/dist/deploy/index.js +4 -17
- 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/package.json +1 -1
- package/src/build/index.ts +1 -1
- package/src/context/getEnvConfig.ts +2 -2
- package/src/context/getEnvironment.ts +5 -5
- package/src/deploy/cloudRun/deployJob.ts +75 -24
- package/src/deploy/cloudRun/index.ts +12 -23
- package/src/deploy/index.ts +5 -5
- package/src/deploy/types/googleCloudRun.ts +25 -23
package/dist/build/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from "./types";
|
|
|
6
6
|
export * from "./node";
|
|
7
7
|
export declare type BuildTypes = { [type in BuildConfigType]: {
|
|
8
8
|
jobs: (context: Context) => CatladderJob[];
|
|
9
|
-
defaults: (
|
|
9
|
+
defaults: (envContext: EnvironmentContext<BuildConfigType, any>) => Partial<Extract<BuildConfig, {
|
|
10
10
|
type: type;
|
|
11
11
|
}>>;
|
|
12
12
|
} };
|
|
@@ -28177,7 +28177,7 @@ exports.readConfigSync = readConfigSync;
|
|
|
28177
28177
|
|
|
28178
28178
|
exports.__esModule = true;
|
|
28179
28179
|
exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
|
|
28180
|
-
exports.PIPELINE_IMAGE_TAG = "refactor-env-context-
|
|
28180
|
+
exports.PIPELINE_IMAGE_TAG = "refactor-env-context-834a2b56" || 0;
|
|
28181
28181
|
exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || 0;
|
|
28182
28182
|
|
|
28183
28183
|
/***/ }),
|
|
@@ -28396,7 +28396,7 @@ var getEnvironmentVariables_1 = __nccwpck_require__(2292);
|
|
|
28396
28396
|
|
|
28397
28397
|
var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
28398
28398
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
28399
|
-
var _a, envVars, secretEnvVarKeys, host, url,
|
|
28399
|
+
var _a, envVars, secretEnvVarKeys, host, url, envContext, envType;
|
|
28400
28400
|
|
|
28401
28401
|
return __generator(this, function (_b) {
|
|
28402
28402
|
switch (_b.label) {
|
|
@@ -28407,8 +28407,8 @@ var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
|
28407
28407
|
|
|
28408
28408
|
case 1:
|
|
28409
28409
|
_a = _b.sent(), envVars = _a.envVars, secretEnvVarKeys = _a.secretEnvVarKeys, host = _a.host, url = _a.url;
|
|
28410
|
-
|
|
28411
|
-
envType =
|
|
28410
|
+
envContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
|
|
28411
|
+
envType = envContext.envType;
|
|
28412
28412
|
return [2
|
|
28413
28413
|
/*return*/
|
|
28414
28414
|
, {
|
|
@@ -28416,11 +28416,11 @@ var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
|
28416
28416
|
host: host,
|
|
28417
28417
|
url: url,
|
|
28418
28418
|
gitlabEnvironment: {
|
|
28419
|
-
name:
|
|
28419
|
+
name: envContext.gitlabEnvironmentName,
|
|
28420
28420
|
url: url
|
|
28421
28421
|
},
|
|
28422
|
-
fullName:
|
|
28423
|
-
slug:
|
|
28422
|
+
fullName: envContext.fullName,
|
|
28423
|
+
slug: envContext.environmentSlug,
|
|
28424
28424
|
shortName: env,
|
|
28425
28425
|
envVars: envVars,
|
|
28426
28426
|
secretEnvVarKeys: secretEnvVarKeys
|
|
@@ -29649,13 +29649,15 @@ var types_1 = __nccwpck_require__(4436);
|
|
|
29649
29649
|
var gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(818);
|
|
29650
29650
|
|
|
29651
29651
|
var createGoogleCloudRunDeployJobs = function (context) {
|
|
29652
|
+
var _a, _b;
|
|
29653
|
+
|
|
29652
29654
|
var deployConfig = context.componentConfig.deploy;
|
|
29653
29655
|
|
|
29654
29656
|
if (deployConfig === false) {
|
|
29655
29657
|
return [];
|
|
29656
29658
|
}
|
|
29657
29659
|
|
|
29658
|
-
if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun"
|
|
29660
|
+
if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
|
|
29659
29661
|
// should not happen
|
|
29660
29662
|
throw new Error("deploy config is wrong");
|
|
29661
29663
|
}
|
|
@@ -29676,44 +29678,76 @@ var createGoogleCloudRunDeployJobs = function (context) {
|
|
|
29676
29678
|
return "".concat(key, "=").concat(value);
|
|
29677
29679
|
}).join(",");
|
|
29678
29680
|
var commonArgs = "--project ".concat(deployConfig.projectId, " --region=").concat(deployConfig.region);
|
|
29681
|
+
var commonDeployArgs = "--image ".concat(gcloudImageName, " ").concat(commonArgs, " --labels ").concat(labelsString);
|
|
29682
|
+
var serviceName = context.environment.fullName.toLowerCase();
|
|
29679
29683
|
|
|
29680
|
-
var
|
|
29684
|
+
var getServiceDeployScript = function (service) {
|
|
29681
29685
|
var _a;
|
|
29682
29686
|
|
|
29683
|
-
var
|
|
29684
|
-
var command = (_a = deployConfig.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand;
|
|
29687
|
+
var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand : undefined;
|
|
29685
29688
|
var commandArg = command ? "--command=\"".concat(command.split(" ").join(","), "\"") : "";
|
|
29686
|
-
|
|
29689
|
+
return "gcloud run deploy ".concat(serviceName, " ").concat(commandArg, " ").concat(commonDeployArgs, " --env-vars-file=____envvars.yaml --allow-unauthenticated");
|
|
29690
|
+
};
|
|
29687
29691
|
|
|
29688
|
-
|
|
29689
|
-
|
|
29690
|
-
|
|
29692
|
+
var getJobDeployScripts = function (jobName, job) {
|
|
29693
|
+
// due to some oversight from google, jobs create does not accept `--env-vars-file` 🤦
|
|
29694
|
+
// lucky, update on the other hand accepts it... so let's just imediatly update it
|
|
29695
|
+
// also we cannot upsert a job, so we have to create it and catch the error and then update
|
|
29696
|
+
var args = "".concat(jobName, " --command=\"").concat(job.command.split(" ").join(","), "\" ").concat(commonDeployArgs);
|
|
29697
|
+
return ["set +e", "gcloud beta run jobs create ".concat(args), "set -e", "gcloud beta run jobs update ".concat(args, " --env-vars-file=____envvars.yaml")];
|
|
29698
|
+
};
|
|
29691
29699
|
|
|
29692
|
-
|
|
29693
|
-
|
|
29694
|
-
}
|
|
29700
|
+
var getJobRunScript = function (jobName) {
|
|
29701
|
+
return "gcloud beta run jobs execute ".concat(jobName, " ").concat(commonArgs);
|
|
29695
29702
|
};
|
|
29696
29703
|
|
|
29697
|
-
var
|
|
29698
|
-
|
|
29699
|
-
|
|
29704
|
+
var getFullJobName = function (name) {
|
|
29705
|
+
return context.environment.fullName.toLowerCase() + "-" + name;
|
|
29706
|
+
};
|
|
29700
29707
|
|
|
29701
|
-
|
|
29702
|
-
|
|
29703
|
-
|
|
29708
|
+
var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
|
|
29709
|
+
var _b = __read(_a, 2),
|
|
29710
|
+
name = _b[0],
|
|
29711
|
+
job = _b[1];
|
|
29704
29712
|
|
|
29705
|
-
|
|
29706
|
-
|
|
29707
|
-
|
|
29708
|
-
|
|
29713
|
+
return [getFullJobName(name), job];
|
|
29714
|
+
});
|
|
29715
|
+
|
|
29716
|
+
var cloudRunDeployScripts = __spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml"], __read(jobsWithNames.map(function (_a) {
|
|
29717
|
+
var _b = __read(_a, 2),
|
|
29718
|
+
name = _b[0],
|
|
29719
|
+
job = _b[1];
|
|
29720
|
+
|
|
29721
|
+
return getJobDeployScripts(name, job);
|
|
29722
|
+
}).flat()), false), __read(deployConfig.service !== false ? [getServiceDeployScript(deployConfig.service)] : []), false), __read(jobsWithNames.filter(function (_a) {
|
|
29723
|
+
var _b = __read(_a, 2),
|
|
29724
|
+
name = _b[0],
|
|
29725
|
+
job = _b[1];
|
|
29726
|
+
|
|
29727
|
+
return job.when === "postDeploy";
|
|
29728
|
+
}).map(function (_a) {
|
|
29729
|
+
var _b = __read(_a, 2),
|
|
29730
|
+
name = _b[0],
|
|
29731
|
+
job = _b[1];
|
|
29732
|
+
|
|
29733
|
+
return getJobRunScript(name);
|
|
29734
|
+
})), false), ["docker image rm ".concat(gcloudImageName)], false);
|
|
29735
|
+
|
|
29736
|
+
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) {
|
|
29737
|
+
var _b = __read(_a, 2),
|
|
29738
|
+
jobName = _b[0],
|
|
29739
|
+
job = _b[1];
|
|
29740
|
+
|
|
29741
|
+
return "gcloud beta run jobs delete ".concat(jobName);
|
|
29742
|
+
})), false);
|
|
29709
29743
|
|
|
29710
|
-
var cloudRunDeploy = ["echo \"$ENV_VARS\" > ____envvars.yaml", getDeployCommand(), "docker image rm ".concat(gcloudImageName)];
|
|
29711
29744
|
var baseStopJob = (0, base_1.getBaseDeploymentStopJob)(context);
|
|
29712
29745
|
return [(0, lodash_1.merge)({}, baseDeploymentJob, (0, docker_1.getDockerJobBaseProps)(context), {
|
|
29713
29746
|
artifacts: {
|
|
29714
29747
|
paths: ["____envvars.yaml"]
|
|
29715
29748
|
},
|
|
29716
29749
|
variables: {
|
|
29750
|
+
CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
|
|
29717
29751
|
ENV_VARS: (0, js_yaml_1.dump)(allEnvVars, {
|
|
29718
29752
|
lineWidth: -1,
|
|
29719
29753
|
quotingType: "'",
|
|
@@ -29721,10 +29755,13 @@ var createGoogleCloudRunDeployJobs = function (context) {
|
|
|
29721
29755
|
})
|
|
29722
29756
|
},
|
|
29723
29757
|
image: (0, runner_1.getRunnerImage)("gcloud"),
|
|
29724
|
-
script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(
|
|
29758
|
+
script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(cloudRunDeployScripts), false)
|
|
29725
29759
|
}), (0, lodash_1.merge)({}, baseStopJob, {
|
|
29726
29760
|
image: (0, runner_1.getRunnerImage)("gcloud"),
|
|
29727
|
-
|
|
29761
|
+
variables: {
|
|
29762
|
+
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
|
|
29763
|
+
},
|
|
29764
|
+
script: __spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), __read(cloudRunStopScripts), false)
|
|
29728
29765
|
})];
|
|
29729
29766
|
};
|
|
29730
29767
|
|
|
@@ -29733,13 +29770,52 @@ exports.createGoogleCloudRunDeployJobs = createGoogleCloudRunDeployJobs;
|
|
|
29733
29770
|
/***/ }),
|
|
29734
29771
|
|
|
29735
29772
|
/***/ 8718:
|
|
29736
|
-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__)
|
|
29773
|
+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
|
29737
29774
|
|
|
29738
29775
|
"use strict";
|
|
29739
29776
|
|
|
29740
29777
|
|
|
29778
|
+
var __assign = this && this.__assign || function () {
|
|
29779
|
+
__assign = Object.assign || function (t) {
|
|
29780
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29781
|
+
s = arguments[i];
|
|
29782
|
+
|
|
29783
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
29784
|
+
}
|
|
29785
|
+
|
|
29786
|
+
return t;
|
|
29787
|
+
};
|
|
29788
|
+
|
|
29789
|
+
return __assign.apply(this, arguments);
|
|
29790
|
+
};
|
|
29791
|
+
|
|
29792
|
+
var __read = this && this.__read || function (o, n) {
|
|
29793
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29794
|
+
if (!m) return o;
|
|
29795
|
+
var i = m.call(o),
|
|
29796
|
+
r,
|
|
29797
|
+
ar = [],
|
|
29798
|
+
e;
|
|
29799
|
+
|
|
29800
|
+
try {
|
|
29801
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
29802
|
+
} catch (error) {
|
|
29803
|
+
e = {
|
|
29804
|
+
error: error
|
|
29805
|
+
};
|
|
29806
|
+
} finally {
|
|
29807
|
+
try {
|
|
29808
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29809
|
+
} finally {
|
|
29810
|
+
if (e) throw e.error;
|
|
29811
|
+
}
|
|
29812
|
+
}
|
|
29813
|
+
|
|
29814
|
+
return ar;
|
|
29815
|
+
};
|
|
29816
|
+
|
|
29741
29817
|
exports.__esModule = true;
|
|
29742
|
-
exports.
|
|
29818
|
+
exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
|
|
29743
29819
|
|
|
29744
29820
|
var context_1 = __nccwpck_require__(7123);
|
|
29745
29821
|
|
|
@@ -29758,40 +29834,21 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
|
|
|
29758
29834
|
getAdditionalEnvVars: function (_a) {
|
|
29759
29835
|
var fullName = _a.fullName,
|
|
29760
29836
|
env = _a.env,
|
|
29761
|
-
componentName = _a.componentName
|
|
29837
|
+
componentName = _a.componentName,
|
|
29838
|
+
deployConfigRaw = _a.deployConfigRaw;
|
|
29762
29839
|
var HOST_CANONICAL = fullName.toLowerCase() + "-" + process.env[(0, context_1.getSecretVarName)(env, componentName, exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)];
|
|
29763
|
-
|
|
29764
|
-
|
|
29765
|
-
|
|
29766
|
-
|
|
29767
|
-
};
|
|
29768
|
-
exports.GCLOUD_RUN_JOB_DEPLOY_TYPE = {
|
|
29769
|
-
jobs: deployJob_1.createGoogleCloudRunDeployJobs,
|
|
29770
|
-
defaults: function () {
|
|
29771
|
-
return {};
|
|
29772
|
-
},
|
|
29773
|
-
additionalSecretKeys: function () {
|
|
29774
|
-
return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
|
|
29775
|
-
},
|
|
29776
|
-
getAdditionalEnvVars: function (_a) {
|
|
29777
|
-
var deployConfigRaw = _a.deployConfigRaw,
|
|
29778
|
-
fullName = _a.fullName;
|
|
29779
|
-
|
|
29780
|
-
if (!deployConfigRaw) {
|
|
29781
|
-
return {};
|
|
29782
|
-
}
|
|
29840
|
+
var jobTriggers = deployConfigRaw && deployConfigRaw.jobs ? Object.fromEntries(Object.entries(deployConfigRaw.jobs).map(function (_a) {
|
|
29841
|
+
var _b = __read(_a, 2),
|
|
29842
|
+
name = _b[0],
|
|
29843
|
+
job = _b[1];
|
|
29783
29844
|
|
|
29784
|
-
|
|
29785
|
-
|
|
29786
|
-
return {
|
|
29787
|
-
|
|
29788
|
-
};
|
|
29845
|
+
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")];
|
|
29846
|
+
})) : {};
|
|
29847
|
+
return __assign({
|
|
29848
|
+
HOST_CANONICAL: HOST_CANONICAL
|
|
29849
|
+
}, jobTriggers);
|
|
29789
29850
|
}
|
|
29790
29851
|
};
|
|
29791
|
-
exports.GCLOUD_RUN_DEPLOY_TYPES = {
|
|
29792
|
-
"google-cloudrun": exports.GCLOUD_RUN_DEPLOY_TYPE,
|
|
29793
|
-
"google-cloudrun-job": exports.GCLOUD_RUN_JOB_DEPLOY_TYPE
|
|
29794
|
-
};
|
|
29795
29852
|
|
|
29796
29853
|
/***/ }),
|
|
29797
29854
|
|
|
@@ -30026,20 +30083,6 @@ exports.DOCKER_TAG_DEPLOY_TYPE = {
|
|
|
30026
30083
|
"use strict";
|
|
30027
30084
|
|
|
30028
30085
|
|
|
30029
|
-
var __assign = this && this.__assign || function () {
|
|
30030
|
-
__assign = Object.assign || function (t) {
|
|
30031
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
30032
|
-
s = arguments[i];
|
|
30033
|
-
|
|
30034
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
30035
|
-
}
|
|
30036
|
-
|
|
30037
|
-
return t;
|
|
30038
|
-
};
|
|
30039
|
-
|
|
30040
|
-
return __assign.apply(this, arguments);
|
|
30041
|
-
};
|
|
30042
|
-
|
|
30043
30086
|
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
30044
30087
|
if (k2 === undefined) k2 = k;
|
|
30045
30088
|
Object.defineProperty(o, k2, {
|
|
@@ -30078,11 +30121,12 @@ __exportStar(__nccwpck_require__(4436), exports);
|
|
|
30078
30121
|
|
|
30079
30122
|
__exportStar(__nccwpck_require__(5860), exports);
|
|
30080
30123
|
|
|
30081
|
-
exports.DEPLOY_TYPES =
|
|
30124
|
+
exports.DEPLOY_TYPES = {
|
|
30082
30125
|
kubernetes: kubernetes_1.KUBERNETES_DEPLOY_TYPE,
|
|
30083
30126
|
custom: custom_1.CUSTOM_DEPLOY_TYPE,
|
|
30084
|
-
dockerTag: dockerTag_1.DOCKER_TAG_DEPLOY_TYPE
|
|
30085
|
-
|
|
30127
|
+
dockerTag: dockerTag_1.DOCKER_TAG_DEPLOY_TYPE,
|
|
30128
|
+
"google-cloudrun": cloudRun_1.GCLOUD_RUN_DEPLOY_TYPE
|
|
30129
|
+
};
|
|
30086
30130
|
|
|
30087
30131
|
/***/ }),
|
|
30088
30132
|
|
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 = "refactor-env-context-
|
|
5
|
+
exports.PIPELINE_IMAGE_TAG = "refactor-env-context-834a2b56" || "";
|
|
6
6
|
exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
|
|
@@ -1,9 +1,2 @@
|
|
|
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>;
|
|
1
|
+
import type { Config, EnvConfigWithComponent } from "../types/config";
|
|
2
|
+
export declare const getEnvConfig: (config: Config, componentName: string, env: string) => EnvConfigWithComponent;
|
|
@@ -150,7 +150,7 @@ var getEnvironmentVariables_1 = require("./getEnvironmentVariables");
|
|
|
150
150
|
|
|
151
151
|
var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
152
152
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
-
var _a, envVars, secretEnvVarKeys, host, url,
|
|
153
|
+
var _a, envVars, secretEnvVarKeys, host, url, envContext, envType;
|
|
154
154
|
|
|
155
155
|
return __generator(this, function (_b) {
|
|
156
156
|
switch (_b.label) {
|
|
@@ -161,8 +161,8 @@ var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
|
161
161
|
|
|
162
162
|
case 1:
|
|
163
163
|
_a = _b.sent(), envVars = _a.envVars, secretEnvVarKeys = _a.secretEnvVarKeys, host = _a.host, url = _a.url;
|
|
164
|
-
|
|
165
|
-
envType =
|
|
164
|
+
envContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
|
|
165
|
+
envType = envContext.envType;
|
|
166
166
|
return [2
|
|
167
167
|
/*return*/
|
|
168
168
|
, {
|
|
@@ -170,11 +170,11 @@ var getEnvironment = function (config, componentName, env, commitInfo) {
|
|
|
170
170
|
host: host,
|
|
171
171
|
url: url,
|
|
172
172
|
gitlabEnvironment: {
|
|
173
|
-
name:
|
|
173
|
+
name: envContext.gitlabEnvironmentName,
|
|
174
174
|
url: url
|
|
175
175
|
},
|
|
176
|
-
fullName:
|
|
177
|
-
slug:
|
|
176
|
+
fullName: envContext.fullName,
|
|
177
|
+
slug: envContext.environmentSlug,
|
|
178
178
|
shortName: env,
|
|
179
179
|
envVars: envVars,
|
|
180
180
|
secretEnvVarKeys: secretEnvVarKeys
|
|
@@ -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 deployConfigRaw = _a.deployConfigRaw,
|
|
40
|
-
fullName = _a.fullName;
|
|
41
|
-
|
|
42
|
-
if (!deployConfigRaw) {
|
|
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
|
@@ -9,9 +9,9 @@ export * from "./types";
|
|
|
9
9
|
export * from "./utils";
|
|
10
10
|
export declare type DeployTypeDefinition<T extends DeployConfigType> = {
|
|
11
11
|
jobs: (context: Context) => CatladderJob[];
|
|
12
|
-
defaults: (
|
|
13
|
-
additionalSecretKeys: (
|
|
14
|
-
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>;
|
|
15
15
|
};
|
|
16
16
|
export declare type DeployTypes = { [T in DeployConfigType]: DeployTypeDefinition<T> };
|
|
17
17
|
export declare const DEPLOY_TYPES: DeployTypes;
|