@catladder/pipeline 4.7.0 → 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.
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-7-0-9922ea65" || "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 {};
@@ -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,7 @@ 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
17
  /**
18
18
  * script lines the deploy type contributes to the start of the verify job,
19
19
  * e.g. to authenticate against a non-public service