@catladder/pipeline 3.9.3 → 3.10.0

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 = "v3-9-3-1d2f2148" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v3-10-0-58aa7394" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -56,7 +56,7 @@ exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
56
56
  // FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
57
57
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
58
58
  var getCloudSqlVariables = function (_a) {
59
- var _b, _c;
59
+ var _b, _c, _d;
60
60
  var deployConfigRaw = _a.deployConfigRaw,
61
61
  environmentSlugPrefix = _a.environmentSlugPrefix,
62
62
  env = _a.env,
@@ -70,14 +70,16 @@ var getCloudSqlVariables = function (_a) {
70
70
  value = _b[1];
71
71
  return "&".concat(key, "=").concat(value);
72
72
  }).join("");
73
- return {
73
+ var dbVars = {
74
74
  CLOUD_SQL_INSTANCE_CONNECTION_NAME: deployConfigRaw.cloudSql.instanceConnectionName,
75
75
  DB_NAME: DB_NAME,
76
76
  DB_USER: (_c = deployConfigRaw.cloudSql.dbUser) !== null && _c !== void 0 ? _c : "postgres",
77
- DB_PASSWORD: "$" + (0, context_1.getSecretVarName)(env, componentName, "DB_PASSWORD"),
78
- DATABASE_URL: "".concat((0, database_1.getDatabaseConnectionString)(deployConfigRaw.cloudSql)).concat(additionalQueryParamsString),
79
- DATABASE_JDBC_URL: database_1.DATABASE_JDBC_URL
77
+ DB_PASSWORD: "$" + (0, context_1.getSecretVarName)(env, componentName, "DB_PASSWORD")
80
78
  };
79
+ return __assign(__assign({}, dbVars), {
80
+ DATABASE_URL: (0, database_1.getDatabaseConnectionString)(deployConfigRaw.cloudSql, dbVars).concat(additionalQueryParamsString),
81
+ DATABASE_JDBC_URL: (0, database_1.getDatabaseJdbcUrl)(dbVars, (_d = deployConfigRaw.cloudSql.dbConnectionStringVariablesMode) !== null && _d !== void 0 ? _d : database_1.DEFAULT_DB_VARIABLES_MODE)
82
+ });
81
83
  }
82
84
  return {};
83
85
  };
@@ -1,6 +1,25 @@
1
+ import { type StringOrBashExpression } from "../../../bash";
1
2
  import type { ComponentContext } from "../../../types";
2
3
  import type { DeployConfigCloudRun, DeployConfigCloudRunCloudSql } from "../../types";
3
4
  export declare const getDatabaseDeleteScript: (context: ComponentContext, deployConfig: DeployConfigCloudRun) => string[];
4
5
  export declare const getDatabaseCreateScript: (context: ComponentContext, deployConfig: DeployConfigCloudRun) => string[];
5
- export declare const DATABASE_JDBC_URL = "jdbc:postgresql:///$DB_NAME?cloudSqlInstance=$CLOUD_SQL_INSTANCE_CONNECTION_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=$DB_USER&password=$DB_PASSWORD";
6
- export declare const getDatabaseConnectionString: (config: DeployConfigCloudRunCloudSql) => string;
6
+ export type DBVariables = {
7
+ CLOUD_SQL_INSTANCE_CONNECTION_NAME: StringOrBashExpression;
8
+ DB_NAME: StringOrBashExpression;
9
+ DB_USER: StringOrBashExpression;
10
+ DB_PASSWORD: StringOrBashExpression;
11
+ };
12
+ /**
13
+ * controls how variables in the connection string are handled
14
+ *
15
+ * - 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
+ *
18
+ * 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
+ export type DBVariablesMode = "legacy" | "embedded";
21
+ 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;
@@ -25,7 +25,8 @@ var __read = this && this.__read || function (o, n) {
25
25
  Object.defineProperty(exports, "__esModule", {
26
26
  value: true
27
27
  });
28
- exports.getDatabaseConnectionString = exports.DATABASE_JDBC_URL = exports.getDatabaseCreateScript = exports.getDatabaseDeleteScript = void 0;
28
+ exports.getDatabaseConnectionString = exports.getPrismaDatabaseConnectionString = exports.getRailsDatabaseConnectionString = exports.getDatabaseJdbcUrl = exports.DEFAULT_DB_VARIABLES_MODE = exports.getDatabaseCreateScript = exports.getDatabaseDeleteScript = void 0;
29
+ var bash_1 = require("../../../bash");
29
30
  var gitlab_1 = require("../../../utils/gitlab");
30
31
  var getDatabaseDeleteScript = function (context, deployConfig) {
31
32
  if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
@@ -62,16 +63,36 @@ var getDatabaseCreateScript = function (context, deployConfig) {
62
63
  return (0, gitlab_1.allowFailureInScripts)(["echo \"ensuring Database...\"", "gcloud sql databases create ".concat(DB_NAME, " --instance=").concat(instanceId, " --project ").concat(projectId)]);
63
64
  };
64
65
  exports.getDatabaseCreateScript = getDatabaseCreateScript;
65
- exports.DATABASE_JDBC_URL = "jdbc:postgresql:///$DB_NAME?cloudSqlInstance=$CLOUD_SQL_INSTANCE_CONNECTION_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=$DB_USER&password=$DB_PASSWORD";
66
- var getDatabaseConnectionString = function (config) {
66
+ exports.DEFAULT_DB_VARIABLES_MODE = "legacy";
67
+ var getVariableOrValue = function (key, variables, mode) {
68
+ return mode === "legacy" ? "$".concat(key) : variables[key];
69
+ };
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);
73
+ };
74
+ 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);
78
+ };
79
+ 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);
83
+ };
84
+ exports.getPrismaDatabaseConnectionString = getPrismaDatabaseConnectionString;
85
+ var getDatabaseConnectionString = function (config, variables) {
86
+ var _a;
87
+ var mode = (_a = config.dbConnectionStringVariablesMode) !== null && _a !== void 0 ? _a : exports.DEFAULT_DB_VARIABLES_MODE;
67
88
  switch (config.dbConnectionStringFormat) {
68
89
  case "jdbc":
69
- return exports.DATABASE_JDBC_URL;
90
+ return (0, exports.getDatabaseJdbcUrl)(variables, mode);
70
91
  case "rails":
71
- return "postgresql://$DB_USER:$DB_PASSWORD@".concat(encodeURIComponent("/cloudsql/".concat(config.instanceConnectionName)), "/$DB_NAME?");
92
+ return (0, exports.getRailsDatabaseConnectionString)(variables, mode);
72
93
  default:
73
94
  // prisma
74
- return "postgresql://$DB_USER:$DB_PASSWORD@localhost/$DB_NAME?host=/cloudsql/$CLOUD_SQL_INSTANCE_CONNECTION_NAME";
95
+ return (0, exports.getPrismaDatabaseConnectionString)(variables, mode);
75
96
  }
76
97
  };
77
98
  exports.getDatabaseConnectionString = getDatabaseConnectionString;
@@ -1,3 +1,4 @@
1
+ import type { DBVariablesMode } from "../cloudRun/utils/database";
1
2
  import type { DeployConfigBase } from "./base";
2
3
  export type Gcloudregion = "asia-east1" | "asia-northeast1" | "asia-northeast2" | "europe-north1" | "europe-southwest1" | "europe-west1" | "europe-west4" | "europe-west8" | "europe-west9" | "me-west1" | "us-central1" | "us-east1" | "us-east4" | "us-east5" | "us-south1" | "us-west1" | "asia-east2" | "asia-northeast3" | "asia-southeast1" | "asia-southeast2" | "asia-south1" | "asia-south2" | "australia-southeast1" | "australia-southeast2" | "europe-central2" | "europe-west2" | "europe-west3" | "europe-west6" | "northamerica-northeast1" | "northamerica-northeast2" | "southamerica-east1" | "southamerica-west1" | "us-west2" | "us-west3" | "us-west4";
3
4
  export type DeployConfigCloudRunCloudSql = {
@@ -36,6 +37,15 @@ export type DeployConfigCloudRunCloudSql = {
36
37
  * defaults to prisma
37
38
  */
38
39
  dbConnectionStringFormat?: "prisma" | "rails" | "jdbc";
40
+ /**
41
+ * controls how variables in the connection string are handled
42
+ *
43
+ * - environment: variables like $DB_USER will be kept as environment variables to be replaced at runtime (default)
44
+ * - embedded: variables will be replaced with their actual values in the connection string
45
+ *
46
+ * @default "environment"
47
+ */
48
+ dbConnectionStringVariablesMode?: DBVariablesMode;
39
49
  /**
40
50
  * add additional query params to the database connection string
41
51
  */