@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 +1 -1
- package/dist/context/getEnvironmentVariables.js +6 -5
- package/dist/deploy/cloudRun/index.js +2 -2
- package/dist/deploy/cloudRun/utils/database.d.ts +6 -5
- package/dist/deploy/cloudRun/utils/database.js +22 -15
- package/dist/deploy/index.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/variables/VariableValueContainingReferences.d.ts +6 -0
- package/dist/variables/VariableValueContainingReferences.js +21 -0
- package/dist/variables/resolveAllReferences.d.ts +1 -2
- package/dist/variables/resolveAllReferences.js +7 -8
- package/dist/variables/resolveAllReferencesOnce.d.ts +1 -4
- package/dist/variables/resolveAllReferencesOnce.js +3 -3
- package/examples/__snapshots__/cloud-run-with-sql-multiple-dbs.test.ts.snap +35 -35
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +64 -64
- package/examples/cloud-run-with-sql-reuse-db.ts +4 -0
- package/package.json +1 -1
- package/src/context/getEnvironmentVariables.ts +19 -10
- package/src/deploy/cloudRun/index.ts +2 -0
- package/src/deploy/cloudRun/utils/database.ts +54 -22
- package/src/deploy/index.ts +2 -2
- package/src/variables/VariableValueContainingReferences.ts +11 -0
- package/src/variables/__tests__/resolveAllReferences.test.ts +49 -0
- package/src/variables/resolveAllReferences.ts +18 -14
- package/src/variables/resolveAllReferencesOnce.ts +17 -12
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-
|
|
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,
|
|
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)(
|
|
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 =
|
|
265
|
+
_a = mergedEnvVars;
|
|
265
266
|
_m.label = 3;
|
|
266
267
|
case 3:
|
|
267
|
-
|
|
268
|
-
envVars = addIndexVar(
|
|
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
|
|
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) =>
|
|
23
|
-
export declare const getRailsDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode) =>
|
|
24
|
-
export declare const getPrismaDatabaseConnectionString: (variables: DBVariables, mode: DBVariablesMode) =>
|
|
25
|
-
export declare const getDatabaseConnectionString: (config: DeployConfigCloudRunCloudSql, variables: DBVariables) =>
|
|
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,
|
|
68
|
-
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
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",
|
|
77
|
-
return (
|
|
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",
|
|
82
|
-
return (
|
|
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;
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -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,
|
|
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
|