@catladder/pipeline 4.6.4 → 4.7.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.
Files changed (44) hide show
  1. package/dist/constants.js +1 -1
  2. package/dist/context/getEnvironmentVariables.js +6 -5
  3. package/dist/deploy/cloudRun/index.js +14 -2
  4. package/dist/deploy/cloudRun/utils/database.d.ts +6 -5
  5. package/dist/deploy/cloudRun/utils/database.js +22 -15
  6. package/dist/deploy/index.d.ts +7 -2
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/pipeline/createJobsForComponent.js +5 -4
  10. package/dist/tsconfig.tsbuildinfo +1 -1
  11. package/dist/types/config.d.ts +8 -0
  12. package/dist/variables/VariableValueContainingReferences.d.ts +6 -0
  13. package/dist/variables/VariableValueContainingReferences.js +21 -0
  14. package/dist/variables/resolveAllReferences.d.ts +1 -2
  15. package/dist/variables/resolveAllReferences.js +7 -8
  16. package/dist/variables/resolveAllReferencesOnce.d.ts +1 -4
  17. package/dist/variables/resolveAllReferencesOnce.js +3 -3
  18. package/dist/verify/createVerifyJobs.d.ts +4 -0
  19. package/dist/verify/createVerifyJobs.js +229 -0
  20. package/dist/verify/index.d.ts +2 -0
  21. package/dist/verify/index.js +26 -0
  22. package/dist/verify/types.d.ts +16 -0
  23. package/dist/verify/types.js +5 -0
  24. package/examples/__snapshots__/cloud-run-verify.test.ts.snap +3061 -0
  25. package/examples/__snapshots__/cloud-run-with-sql-multiple-dbs.test.ts.snap +35 -35
  26. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +64 -64
  27. package/examples/cloud-run-verify.test.ts +12 -0
  28. package/examples/cloud-run-verify.ts +50 -0
  29. package/examples/cloud-run-with-sql-reuse-db.ts +4 -0
  30. package/package.json +1 -1
  31. package/src/context/getEnvironmentVariables.ts +19 -10
  32. package/src/deploy/cloudRun/index.ts +25 -1
  33. package/src/deploy/cloudRun/utils/database.ts +54 -22
  34. package/src/deploy/index.ts +7 -2
  35. package/src/index.ts +1 -0
  36. package/src/pipeline/createJobsForComponent.ts +4 -2
  37. package/src/types/config.ts +9 -0
  38. package/src/variables/VariableValueContainingReferences.ts +11 -0
  39. package/src/variables/__tests__/resolveAllReferences.test.ts +49 -0
  40. package/src/variables/resolveAllReferences.ts +18 -14
  41. package/src/variables/resolveAllReferencesOnce.ts +17 -12
  42. package/src/verify/createVerifyJobs.ts +81 -0
  43. package/src/verify/index.ts +2 -0
  44. package/src/verify/types.ts +18 -0
package/dist/constants.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
7
- exports.PIPELINE_IMAGE_TAG = "v4-6-4-d6efbf06" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v4-7-1-890e599f" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -182,7 +182,7 @@ var getEnvironmentVariables = function (ctx_1) {
182
182
  args_1[_i - 1] = arguments[_i];
183
183
  }
184
184
  return __awaiter(void 0, __spreadArray([ctx_1], __read(args_1), false), void 0, function (ctx, options) {
185
- var environmentContext, config, env, componentName, envConfigRaw, deployConfigRaw, buildConfigRaw, envType, basePredefinedVariables, predefinedVariables, host, url, devLocalConfig, port, additionalEnvVars, HOSTNAME_INTERNAL, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, publicEnvVarsRawSanitized, publicEnvVarsUnresolved, publicEnvVars, _a, envVars;
185
+ var environmentContext, config, env, componentName, envConfigRaw, deployConfigRaw, buildConfigRaw, envType, basePredefinedVariables, predefinedVariables, host, url, devLocalConfig, port, additionalEnvVars, HOSTNAME_INTERNAL, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, publicEnvVarsRawSanitized, publicEnvVarsUnresolved, mergedEnvVars, resolvedEnvVars, _a, envVars;
186
186
  var _b, _c;
187
187
  var _d, _e, _f, _g, _h, _j, _k, _l;
188
188
  if (options === void 0) {
@@ -238,8 +238,9 @@ var getEnvironmentVariables = function (ctx_1) {
238
238
  componentName: ctx.componentName
239
239
  })];
240
240
  }));
241
+ mergedEnvVars = __assign(__assign(__assign({}, predefinedVariables), secretEnvVars), publicEnvVarsUnresolved);
241
242
  if (!((_l = options.shouldResolveReferences) !== null && _l !== void 0 ? _l : true)) return [3 /*break*/, 2];
242
- return [4 /*yield*/, (0, resolveAllReferences_1.resolveAllReferences)(publicEnvVarsUnresolved, function (otherComponentName) {
243
+ return [4 /*yield*/, (0, resolveAllReferences_1.resolveAllReferences)(mergedEnvVars, function (otherComponentName) {
243
244
  return __awaiter(void 0, void 0, void 0, function () {
244
245
  var otherEnvVars;
245
246
  return __generator(this, function (_a) {
@@ -261,11 +262,11 @@ var getEnvironmentVariables = function (ctx_1) {
261
262
  _a = _m.sent();
262
263
  return [3 /*break*/, 3];
263
264
  case 2:
264
- _a = publicEnvVarsUnresolved;
265
+ _a = mergedEnvVars;
265
266
  _m.label = 3;
266
267
  case 3:
267
- publicEnvVars = _a;
268
- envVars = addIndexVar(__assign(__assign(__assign({}, predefinedVariables), secretEnvVars), publicEnvVars));
268
+ resolvedEnvVars = _a;
269
+ envVars = addIndexVar(resolvedEnvVars);
269
270
  _b = {
270
271
  envVars: envVars,
271
272
  secretEnvVarKeys: secretEnvVarKeys
@@ -78,8 +78,8 @@ var getCloudSqlVariables = function (_a) {
78
78
  DB_PASSWORD: "$" + (0, context_1.getSecretVarName)(env, componentName, "DB_PASSWORD")
79
79
  };
80
80
  return __assign(__assign({}, dbVars), {
81
- DATABASE_URL: (0, database_1.getDatabaseConnectionString)(deployConfigRaw.cloudSql, dbVars).concat(additionalQueryParamsString),
82
- DATABASE_JDBC_URL: (0, database_1.getDatabaseJdbcUrl)(dbVars, (_d = deployConfigRaw.cloudSql.dbConnectionStringVariablesMode) !== null && _d !== void 0 ? _d : database_1.DEFAULT_DB_VARIABLES_MODE)
81
+ DATABASE_URL: (0, database_1.getDatabaseConnectionString)(deployConfigRaw.cloudSql, dbVars, componentName).concat(additionalQueryParamsString),
82
+ DATABASE_JDBC_URL: (0, database_1.getDatabaseJdbcUrl)(dbVars, (_d = deployConfigRaw.cloudSql.dbConnectionStringVariablesMode) !== null && _d !== void 0 ? _d : database_1.DEFAULT_DB_VARIABLES_MODE, componentName)
83
83
  });
84
84
  }
85
85
  return {};
@@ -137,5 +137,17 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
137
137
  DEPLOY_CLOUD_RUN_PROJECT_ID: deployConfigRaw ? deployConfigRaw.projectId : undefined,
138
138
  DEPLOY_CLOUD_RUN_REGION: deployConfigRaw ? deployConfigRaw.region : undefined
139
139
  });
140
+ },
141
+ verifyJobSetupScript: function (context) {
142
+ var _a;
143
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
144
+ var service = deployConfig === null || deployConfig === void 0 ? void 0 : deployConfig.service;
145
+ var serviceConfig = typeof service === "object" ? service : undefined;
146
+ if ((serviceConfig === null || serviceConfig === void 0 ? void 0 : serviceConfig.allowUnauthenticated) !== false) {
147
+ return [];
148
+ }
149
+ // the service requires IAM auth: provide application default credentials
150
+ // so the verify command can fetch identity tokens for the deployed service
151
+ return (0, gitlab_1.collapseableSection)("verifygcloudauth", "Setup google application credentials")(["echo \"$".concat(exports.GCLOUD_DEPLOY_CREDENTIALS_KEY, "\" > \"$CI_PROJECT_DIR/.gcloud-sa.json\""), "export GOOGLE_APPLICATION_CREDENTIALS=\"$CI_PROJECT_DIR/.gcloud-sa.json\""]);
140
152
  }
141
153
  };
@@ -1,5 +1,6 @@
1
1
  import { type StringOrBashExpression } from "../../../bash";
2
2
  import type { ComponentContext } from "../../../types";
3
+ import type { VariableValue } from "../../../variables/VariableValue";
3
4
  import type { DeployConfigCloudRun, DeployConfigCloudRunCloudSql } from "../../types";
4
5
  export declare const getDatabaseDeleteScript: (context: ComponentContext, deployConfig: DeployConfigCloudRun) => string[];
5
6
  export declare const getDatabaseCreateScript: (context: ComponentContext, deployConfig: DeployConfigCloudRun) => string[];
@@ -13,13 +14,13 @@ export type DBVariables = {
13
14
  * controls how variables in the connection string are handled
14
15
  *
15
16
  * - legacy: variables like $DB_USER will be kept as environment variables to be replaced at runtime (default). It is not using BashExpressions as this was not the case in the past.
16
- * - embedded: variables will be replaced with their actual values in the connection string
17
+ * - embedded: variables will be replaced with the component's final values in the connection string. This makes the connection string usable from other components (e.g. via ${otherComponent:DATABASE_URL}) and respects overrides of DB_USER, DB_PASSWORD, etc. in vars.public (e.g. DB_PASSWORD: "${otherComponent:DB_PASSWORD}" when reusing another component's database)
17
18
  *
18
19
  * We will remove the legacy mode in the future, as it is confusing. But its unclear whether its a breaking change in some edge cases
19
20
  */
20
21
  export type DBVariablesMode = "legacy" | "embedded";
21
22
  export declare const DEFAULT_DB_VARIABLES_MODE: DBVariablesMode;
22
- export declare const getDatabaseJdbcUrl: (variables: DBVariables, mode: DBVariablesMode) => StringOrBashExpression;
23
- export declare const getRailsDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode) => StringOrBashExpression;
24
- export declare const getPrismaDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode) => StringOrBashExpression;
25
- export declare const getDatabaseConnectionString: (config: DeployConfigCloudRunCloudSql, variables: DBVariables) => StringOrBashExpression;
23
+ export declare const getDatabaseJdbcUrl: (variables: DBVariables, mode: DBVariablesMode, componentName: string) => VariableValue;
24
+ export declare const getRailsDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode, componentName: string) => VariableValue;
25
+ export declare const getPrismaDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode, componentName: string) => VariableValue;
26
+ export declare const getDatabaseConnectionString: (config: DeployConfigCloudRunCloudSql, variables: DBVariables, componentName: string) => VariableValue;
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "__esModule", {
28
28
  exports.getDatabaseConnectionString = exports.getPrismaDatabaseConnectionString = exports.getRailsDatabaseConnectionString = exports.getDatabaseJdbcUrl = exports.DEFAULT_DB_VARIABLES_MODE = exports.getDatabaseCreateScript = exports.getDatabaseDeleteScript = void 0;
29
29
  var bash_1 = require("../../../bash");
30
30
  var gitlab_1 = require("../../../utils/gitlab");
31
+ var VariableValueContainingReferences_1 = require("../../../variables/VariableValueContainingReferences");
31
32
  var getDatabaseDeleteScript = function (context, deployConfig) {
32
33
  if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
33
34
  throw new Error("not possible");
@@ -64,35 +65,41 @@ var getDatabaseCreateScript = function (context, deployConfig) {
64
65
  };
65
66
  exports.getDatabaseCreateScript = getDatabaseCreateScript;
66
67
  exports.DEFAULT_DB_VARIABLES_MODE = "legacy";
67
- var getVariableOrValue = function (key, variables, mode) {
68
- return mode === "legacy" ? "$".concat(key) : variables[key];
68
+ var getVariableOrValue = function (key, mode, componentName) {
69
+ // in embedded mode we reference the component's own env var, which gets
70
+ // resolved to its final value (including vars.public overrides) after all
71
+ // env vars have been merged
72
+ return mode === "legacy" ? "$".concat(key) : new VariableValueContainingReferences_1.VariableReference(componentName, key);
69
73
  };
70
- var getDatabaseJdbcUrl = function (variables, mode) {
71
- var parts = ["jdbc:postgresql:///", getVariableOrValue("DB_NAME", variables, mode), "?cloudSqlInstance=", getVariableOrValue("CLOUD_SQL_INSTANCE_CONNECTION_NAME", variables, mode), "&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=", getVariableOrValue("DB_USER", variables, mode), "&password=", getVariableOrValue("DB_PASSWORD", variables, mode)];
72
- return (0, bash_1.joinBashExpressions)(parts);
74
+ var joinDbUrlParts = function (parts, mode) {
75
+ return mode === "legacy" ? (0, bash_1.joinBashExpressions)(parts) : new VariableValueContainingReferences_1.VariableValueContainingReferences(parts);
76
+ };
77
+ var getDatabaseJdbcUrl = function (variables, mode, componentName) {
78
+ var parts = ["jdbc:postgresql:///", getVariableOrValue("DB_NAME", mode, componentName), "?cloudSqlInstance=", getVariableOrValue("CLOUD_SQL_INSTANCE_CONNECTION_NAME", mode, componentName), "&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=", getVariableOrValue("DB_USER", mode, componentName), "&password=", getVariableOrValue("DB_PASSWORD", mode, componentName)];
79
+ return joinDbUrlParts(parts, mode);
73
80
  };
74
81
  exports.getDatabaseJdbcUrl = getDatabaseJdbcUrl;
75
- var getRailsDatabaseConnectionString = function (variables, mode) {
76
- var parts = ["postgresql://", getVariableOrValue("DB_USER", variables, mode), ":", getVariableOrValue("DB_PASSWORD", variables, mode), "@", encodeURIComponent("/cloudsql/".concat(variables.CLOUD_SQL_INSTANCE_CONNECTION_NAME)), "/", getVariableOrValue("DB_NAME", variables, mode), "?"];
77
- return (0, bash_1.joinBashExpressions)(parts);
82
+ var getRailsDatabaseConnectionString = function (variables, mode, componentName) {
83
+ var parts = ["postgresql://", getVariableOrValue("DB_USER", mode, componentName), ":", getVariableOrValue("DB_PASSWORD", mode, componentName), "@", encodeURIComponent("/cloudsql/".concat(variables.CLOUD_SQL_INSTANCE_CONNECTION_NAME)), "/", getVariableOrValue("DB_NAME", mode, componentName), "?"];
84
+ return joinDbUrlParts(parts, mode);
78
85
  };
79
86
  exports.getRailsDatabaseConnectionString = getRailsDatabaseConnectionString;
80
- var getPrismaDatabaseConnectionString = function (variables, mode) {
81
- var parts = ["postgresql://", getVariableOrValue("DB_USER", variables, mode), ":", getVariableOrValue("DB_PASSWORD", variables, mode), "@localhost/", getVariableOrValue("DB_NAME", variables, mode), "?host=/cloudsql/", getVariableOrValue("CLOUD_SQL_INSTANCE_CONNECTION_NAME", variables, mode)];
82
- return (0, bash_1.joinBashExpressions)(parts);
87
+ var getPrismaDatabaseConnectionString = function (variables, mode, componentName) {
88
+ var parts = ["postgresql://", getVariableOrValue("DB_USER", mode, componentName), ":", getVariableOrValue("DB_PASSWORD", mode, componentName), "@localhost/", getVariableOrValue("DB_NAME", mode, componentName), "?host=/cloudsql/", getVariableOrValue("CLOUD_SQL_INSTANCE_CONNECTION_NAME", mode, componentName)];
89
+ return joinDbUrlParts(parts, mode);
83
90
  };
84
91
  exports.getPrismaDatabaseConnectionString = getPrismaDatabaseConnectionString;
85
- var getDatabaseConnectionString = function (config, variables) {
92
+ var getDatabaseConnectionString = function (config, variables, componentName) {
86
93
  var _a;
87
94
  var mode = (_a = config.dbConnectionStringVariablesMode) !== null && _a !== void 0 ? _a : exports.DEFAULT_DB_VARIABLES_MODE;
88
95
  switch (config.dbConnectionStringFormat) {
89
96
  case "jdbc":
90
- return (0, exports.getDatabaseJdbcUrl)(variables, mode);
97
+ return (0, exports.getDatabaseJdbcUrl)(variables, mode, componentName);
91
98
  case "rails":
92
- return (0, exports.getRailsDatabaseConnectionString)(variables, mode);
99
+ return (0, exports.getRailsDatabaseConnectionString)(variables, mode, componentName);
93
100
  default:
94
101
  // prisma
95
- return (0, exports.getPrismaDatabaseConnectionString)(variables, mode);
102
+ return (0, exports.getPrismaDatabaseConnectionString)(variables, mode, componentName);
96
103
  }
97
104
  };
98
105
  exports.getDatabaseConnectionString = getDatabaseConnectionString;
@@ -1,9 +1,9 @@
1
1
  import type { BuildConfig, SecretEnvVar } from "..";
2
- import type { BashExpression } from "../bash/BashExpression";
3
2
  import type { ComponentContext } from "../types/context";
4
3
  import type { EnvironmentContext } from "../types/environmentContext";
5
4
  import type { CatladderJob } from "../types/jobs";
6
5
  import type { PartialDeep } from "../types/utils";
6
+ import type { VariableValue } from "../variables/VariableValue";
7
7
  import type { DeployConfig, DeployConfigGeneric, DeployConfigType } from "./types";
8
8
  export * from "./cloudRun";
9
9
  export * from "./kubernetes";
@@ -13,7 +13,12 @@ export type DeployTypeDefinition<D extends DeployConfig> = {
13
13
  jobs: (context: ComponentContext) => CatladderJob[] | Promise<CatladderJob[]>;
14
14
  defaults: (envContext: EnvironmentContext<BuildConfig, D>) => PartialDeep<D>;
15
15
  additionalSecretKeys: (envContext: EnvironmentContext<BuildConfig, D>) => SecretEnvVar[];
16
- getAdditionalEnvVars: (envContext: EnvironmentContext<BuildConfig, D>) => Record<string, string | BashExpression | undefined | null>;
16
+ getAdditionalEnvVars: (envContext: EnvironmentContext<BuildConfig, D>) => Record<string, VariableValue | undefined | null>;
17
+ /**
18
+ * script lines the deploy type contributes to the start of the verify job,
19
+ * e.g. to authenticate against a non-public service
20
+ */
21
+ verifyJobSetupScript?: (context: ComponentContext) => string[];
17
22
  };
18
23
  export type DeployTypes = { [T in DeployConfigType]: DeployTypeDefinition<DeployConfigGeneric<T>> };
19
24
  export declare const DEPLOY_TYPES: DeployTypes;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./config";
6
6
  export * from "./context";
7
7
  export * from "./build";
8
8
  export * from "./deploy";
9
+ export * from "./verify";
9
10
  export * from "./utils/writeFiles";
10
11
  export * from "./utils/measureTime";
11
12
  export * from "./variables/VariableValue";
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __exportStar(require("./config"), exports);
30
30
  __exportStar(require("./context"), exports);
31
31
  __exportStar(require("./build"), exports);
32
32
  __exportStar(require("./deploy"), exports);
33
+ __exportStar(require("./verify"), exports);
33
34
  __exportStar(require("./utils/writeFiles"), exports);
34
35
  __exportStar(require("./utils/measureTime"), exports);
35
36
  __exportStar(require("./variables/VariableValue"), exports);
@@ -170,6 +170,7 @@ Object.defineProperty(exports, "__esModule", {
170
170
  exports.createJobsForComponentContext = void 0;
171
171
  var build_1 = require("../build");
172
172
  var deploy_1 = require("../deploy");
173
+ var createVerifyJobs_1 = require("../verify/createVerifyJobs");
173
174
  var injectDefaultVarsInCustomJobs = function (context, jobs) {
174
175
  return jobs.map(function (_a) {
175
176
  var _b;
@@ -189,15 +190,15 @@ var getCustomJobs = function (context) {
189
190
  };
190
191
  var createJobsForComponentContext = function (context) {
191
192
  return __awaiter(void 0, void 0, void 0, function () {
192
- var _a, buildJobs, deployJobs, customJobs;
193
+ var _a, buildJobs, deployJobs, verifyJobs, customJobs;
193
194
  return __generator(this, function (_b) {
194
195
  switch (_b.label) {
195
196
  case 0:
196
- return [4 /*yield*/, Promise.all([context.build.type !== "disabled" ? build_1.BUILD_TYPES[context.build.buildType].jobs(context) : [], context.componentConfig.deploy !== false ? deploy_1.DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context) : []])];
197
+ return [4 /*yield*/, Promise.all([context.build.type !== "disabled" ? build_1.BUILD_TYPES[context.build.buildType].jobs(context) : [], context.componentConfig.deploy !== false ? deploy_1.DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context) : [], (0, createVerifyJobs_1.createVerifyJobs)(context)])];
197
198
  case 1:
198
- _a = __read.apply(void 0, [_b.sent(), 2]), buildJobs = _a[0], deployJobs = _a[1];
199
+ _a = __read.apply(void 0, [_b.sent(), 3]), buildJobs = _a[0], deployJobs = _a[1], verifyJobs = _a[2];
199
200
  customJobs = getCustomJobs(context);
200
- return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(buildJobs), false), __read(deployJobs), false), __read(customJobs), false)];
201
+ return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(buildJobs), false), __read(deployJobs), false), __read(verifyJobs), false), __read(customJobs), false)];
201
202
  }
202
203
  });
203
204
  });