@catladder/pipeline 1.82.2 → 1.83.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.
@@ -0,0 +1,54 @@
1
+ import type { Config, DeployConfigCloudRunCloudSql } from "../src";
2
+ import { createAllPipelines } from "./__utils__/helpers";
3
+
4
+ const CLOUD_SQL: DeployConfigCloudRunCloudSql = {
5
+ type: "unmanaged",
6
+ instanceConnectionName: "projectId:region:instancename",
7
+ dbUser: "my-user",
8
+ };
9
+ const config: Config = {
10
+ appName: "test-app",
11
+ customerName: "pan",
12
+ components: {
13
+ api: {
14
+ dir: "api",
15
+ build: {
16
+ type: "node",
17
+ },
18
+ deploy: {
19
+ type: "google-cloudrun",
20
+ projectId: "google-project-id",
21
+ region: "europe-west6",
22
+ cloudSql: CLOUD_SQL,
23
+ },
24
+ },
25
+ worker: {
26
+ dir: "api",
27
+ build: {
28
+ type: "node",
29
+ buildCommand: "yarn build:worker",
30
+ },
31
+ deploy: {
32
+ type: "google-cloudrun",
33
+ projectId: "google-project-id",
34
+ region: "europe-west6",
35
+ cloudSql: {
36
+ ...CLOUD_SQL,
37
+ // override the db base name to the other component's name
38
+ // if ommited, this defaults to the component's name
39
+ dbBaseName: "api",
40
+ },
41
+ },
42
+ vars: {
43
+ public: {
44
+ // need to reference the password
45
+ DB_PASSWORD: "${api:DB_PASSWORD}",
46
+ },
47
+ },
48
+ },
49
+ },
50
+ };
51
+
52
+ it("matches snapshot", async () => {
53
+ expect(await createAllPipelines(config)).toMatchSnapshot();
54
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catladder/pipeline",
3
- "version": "1.82.2",
3
+ "version": "1.83.0",
4
4
  "scripts": {
5
5
  "build:tsc": "yarn tsc",
6
6
  "build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
@@ -31,6 +31,7 @@ export const getEnvironment = async (
31
31
  url,
32
32
  },
33
33
  fullName: envContext.fullName,
34
+ slugPrefix: envContext.environmentSlugPrefix,
34
35
  slug: envContext.environmentSlug,
35
36
  shortName: env,
36
37
  envVars,
@@ -5,17 +5,16 @@ import type { EnvironmentContext } from "../types/environmentContext";
5
5
  import { getEnvConfig } from "./getEnvConfig";
6
6
  import { getEnvType } from "./getEnvType";
7
7
 
8
- const getEnvironmentSlug = (
8
+ const getEnvironmentSlugPrefix = (
9
9
  envConfig: EnvConfigWithComponent,
10
10
  env: string,
11
- componentName: string,
12
11
  commitInfo?: CommitInfo
13
12
  ) => {
14
13
  const envType = getEnvType(env, envConfig);
15
14
 
16
15
  return envType === "review" && commitInfo
17
- ? `${env}-${commitInfo.reviewSlug}-${componentName}`
18
- : `${env}-${componentName}`;
16
+ ? `${env}-${commitInfo.reviewSlug}`
17
+ : `${env}`;
19
18
  };
20
19
 
21
20
  export const getEnvironmentContext = (
@@ -27,13 +26,13 @@ export const getEnvironmentContext = (
27
26
  const envConfigRaw = getEnvConfig(config, componentName, env);
28
27
  const envType = getEnvType(env, envConfigRaw);
29
28
 
30
- const environmentSlug = getEnvironmentSlug(
29
+ const environmentSlugPrefix = getEnvironmentSlugPrefix(
31
30
  envConfigRaw,
32
31
  env,
33
- componentName,
34
32
  commitInfo
35
33
  );
36
34
 
35
+ const environmentSlug = `${environmentSlugPrefix}-${componentName}`;
37
36
  const gitlabEnvironmentName =
38
37
  envType === "review" && commitInfo
39
38
  ? `${env}/${commitInfo.refName}/${componentName}`
@@ -45,6 +44,7 @@ export const getEnvironmentContext = (
45
44
  envConfigRaw,
46
45
  deployConfigRaw: envConfigRaw.deploy,
47
46
  buildConfigRaw: envConfigRaw.build,
47
+ environmentSlugPrefix,
48
48
  environmentSlug,
49
49
  gitlabEnvironmentName,
50
50
  fullName,
@@ -12,7 +12,7 @@ export const GCLOUD_RUN_CANONICAL_HOST_SUFFIX =
12
12
 
13
13
  const getCloudSqlVariables = ({
14
14
  deployConfigRaw,
15
- environmentSlug,
15
+ environmentSlugPrefix,
16
16
  env,
17
17
  componentName,
18
18
  fullConfig,
@@ -21,7 +21,8 @@ const getCloudSqlVariables = ({
21
21
  const DB_NAME = [
22
22
  deployConfigRaw.cloudSql.dbNamePrefix ??
23
23
  `${fullConfig.customerName}-${fullConfig.appName}`,
24
- environmentSlug,
24
+ environmentSlugPrefix,
25
+ deployConfigRaw.cloudSql.dbBaseName ?? componentName,
25
26
  ]
26
27
  .filter(Boolean)
27
28
  .join("-");
@@ -46,11 +46,16 @@ export type DeployConfigCloudRunCloudSql = {
46
46
  dbUser?: string;
47
47
 
48
48
  /**
49
- * the prefix of the database, the full db name is this plus the environment slug
49
+ * the prefix of the database, the full db name is this plus the environment slug prefix plus the componentName
50
50
  *
51
51
  * defaults to customerName-appName
52
52
  */
53
53
  dbNamePrefix?: string | false;
54
+
55
+ /**
56
+ * the base name of the db, defaults to the componentName
57
+ */
58
+ dbBaseName?: string;
54
59
  /**
55
60
  * whether to delete the database if the environment is stopped
56
61
  * defaults to true for review envs, to false for every other environment
@@ -18,6 +18,7 @@ export type Environment = {
18
18
  url: string;
19
19
  };
20
20
  shortName: string;
21
+ slugPrefix: string;
21
22
  slug: string;
22
23
  /**
23
24
  * env vars contain all build-time env vars. secrets have to be resolved (they are stored in gitlab)
@@ -16,6 +16,13 @@ export type EnvironmentContext<
16
16
  envType: EnvType;
17
17
  componentName: string;
18
18
  fullName: string;
19
+ /**
20
+ * the environment slug without component name.
21
+ */
22
+ environmentSlugPrefix: string;
23
+ /**
24
+ * the full environment slug, including the componentName
25
+ */
19
26
  environmentSlug: string;
20
27
  gitlabEnvironmentName: string;
21
28