@catladder/pipeline 1.82.1 → 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.
@@ -151,7 +151,7 @@ exports[`matches snapshot 1`] = `
151
151
  "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
152
152
  "docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
153
153
  "echo "$ENV_VARS" > ____envvars.yaml",
154
- "gcloud run deploy pan-test-app-dev-www --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=dev,env-name=dev,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
154
+ "gcloud run deploy pan-test-app-dev-www --command="" --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=dev,env-name=dev,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
155
155
  "docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
156
156
  ],
157
157
  "services": [
@@ -461,7 +461,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
461
461
  "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
462
462
  "docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
463
463
  "echo "$ENV_VARS" > ____envvars.yaml",
464
- "gcloud run deploy pan-test-app-review-mr1234-www --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=review,env-name=review,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
464
+ "gcloud run deploy pan-test-app-review-mr1234-www --command="" --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=review,env-name=review,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
465
465
  "docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
466
466
  ],
467
467
  "services": [
@@ -868,7 +868,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
868
868
  "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
869
869
  "docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
870
870
  "echo "$ENV_VARS" > ____envvars.yaml",
871
- "gcloud run deploy pan-test-app-prod-www --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=prod,env-name=prod,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
871
+ "gcloud run deploy pan-test-app-prod-www --command="" --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=prod,env-name=prod,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
872
872
  "docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
873
873
  ],
874
874
  "services": [
@@ -966,7 +966,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
966
966
  "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
967
967
  "docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
968
968
  "echo "$ENV_VARS" > ____envvars.yaml",
969
- "gcloud run deploy pan-test-app-stage-www --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=stage,env-name=stage,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
969
+ "gcloud run deploy pan-test-app-stage-www --command="" --image=asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project=asdf --region=asia-east1 --labels=customer-name=pan,app-name=test-app,env-type=stage,env-name=stage,build-type=custom --env-vars-file=____envvars.yaml --min-instances=0 --max-instances=100 --cpu-throttling --allow-unauthenticated",
970
970
  "docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
971
971
  ],
972
972
  "services": [
@@ -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.1",
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,
@@ -116,7 +116,8 @@ export const createGoogleCloudRunDeployJobs = (
116
116
  : undefined;
117
117
 
118
118
  const argsString = createArgsString({
119
- command: command ? '"' + command.split(" ").join(",") + '"' : undefined, // not sure if quotes are needed
119
+ // command as empty string resets it to default (uses the image's entrypoint)
120
+ command: command ? '"' + command.split(" ").join(",") + '"' : '""',
120
121
  ...commonDeployArgs,
121
122
  "env-vars-file": "____envvars.yaml",
122
123
  "min-instances": customConfig?.minInstances ?? 0,
@@ -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