@catladder/pipeline 1.124.0 → 1.124.2

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.
Files changed (40) hide show
  1. package/dist/build/custom/buildJob.js +1 -1
  2. package/dist/build/docker.d.ts +26 -6
  3. package/dist/build/docker.js +20 -8
  4. package/dist/build/node/buildJob.js +1 -1
  5. package/dist/build/node/meteor.js +1 -1
  6. package/dist/build/rails/build.js +12 -3
  7. package/dist/bundles/catladder-gitlab/index.js +3 -3
  8. package/dist/constants.js +1 -1
  9. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +7 -4
  10. package/dist/deploy/cloudRun/artifactsRegistry.js +30 -23
  11. package/dist/deploy/cloudRun/deployJob.js +1 -1
  12. package/dist/deploy/dockerTag/deployJob.js +32 -1
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +48 -72
  15. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +48 -72
  16. package/examples/__snapshots__/cloud-run-non-public.ts.snap +48 -72
  17. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +96 -144
  18. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +96 -144
  19. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +48 -72
  20. package/examples/__snapshots__/custom-build-job.ts.snap +48 -72
  21. package/examples/__snapshots__/custom-deploy.ts.snap +16 -24
  22. package/examples/__snapshots__/custom-sbom-java.ts.snap +48 -72
  23. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +16 -24
  24. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +16 -24
  25. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +16 -24
  26. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +32 -48
  27. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +16 -24
  28. package/examples/__snapshots__/meteor-kubernetes.ts.snap +16 -24
  29. package/examples/__snapshots__/native-app.ts.snap +48 -72
  30. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +48 -72
  31. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +32 -48
  32. package/package.json +1 -1
  33. package/src/build/custom/buildJob.ts +1 -0
  34. package/src/build/docker.ts +41 -11
  35. package/src/build/node/buildJob.ts +1 -0
  36. package/src/build/node/meteor.ts +1 -1
  37. package/src/build/rails/build.ts +2 -2
  38. package/src/deploy/cloudRun/artifactsRegistry.ts +35 -32
  39. package/src/deploy/cloudRun/deployJob.ts +1 -8
  40. package/src/deploy/dockerTag/deployJob.ts +1 -1
@@ -6,6 +6,12 @@ import type { CatladderJob } from "../types/jobs";
6
6
  import { existsSync } from "fs";
7
7
  import path from "path";
8
8
  import { collapseableSection } from "../utils/gitlab";
9
+ import {
10
+ getArtifactsRegistryBuildCacheImage,
11
+ getArtifactsRegistryHost,
12
+ getArtifactsRegistryImageName,
13
+ } from "../deploy/cloudRun/artifactsRegistry";
14
+ import { gcloudServiceAccountLoginCommands } from "../deploy/cloudRun/utils/gcloudServiceAccountLoginCommands";
9
15
 
10
16
  const DOCKER_RUNNER_BUILD_VARIABLES = {
11
17
  KUBERNETES_CPU_REQUEST: "0.5",
@@ -16,13 +22,24 @@ const DOCKER_RUNNER_BUILD_VARIABLES = {
16
22
 
17
23
  export const getDockerImageVariables = (context: Context) => {
18
24
  return {
19
- DOCKER_REGISTRY: "$CI_REGISTRY",
20
- DOCKER_REGISTRY_IMAGE_PATH: "$CI_REGISTRY_IMAGE",
21
- DOCKER_CACHE_IMAGE:
22
- "$DOCKER_REGISTRY_IMAGE_PATH/caches/" + context.componentName,
23
- DOCKER_IMAGE_NAME:
24
- context.environment.shortName + "/" + context.componentName,
25
- DOCKER_IMAGE: "$DOCKER_REGISTRY_IMAGE_PATH/$DOCKER_IMAGE_NAME",
25
+ ...(isOfDeployType(context.componentConfig.deploy, "google-cloudrun")
26
+ ? {
27
+ DOCKER_REGISTRY: getArtifactsRegistryHost(context),
28
+ DOCKER_IMAGE: getArtifactsRegistryImageName(context),
29
+ DOCKER_CACHE_IMAGE: getArtifactsRegistryBuildCacheImage(context),
30
+ }
31
+ : // gitlab registry:
32
+ {
33
+ DOCKER_REGISTRY: "$CI_REGISTRY",
34
+
35
+ DOCKER_CACHE_IMAGE:
36
+ "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
37
+ // ONLY USED IN KUBERNETES
38
+ DOCKER_IMAGE_NAME:
39
+ context.environment.shortName + "/" + context.componentName,
40
+ DOCKER_IMAGE: "$CI_REGISTRY_IMAGE/$DOCKER_IMAGE_NAME",
41
+ }),
42
+
26
43
  DOCKER_IMAGE_TAG: "$CI_COMMIT_SHA",
27
44
  };
28
45
  };
@@ -94,13 +111,26 @@ export const createDockerBuildJobBase = (
94
111
  );
95
112
  };
96
113
 
97
- export const gitlabDockerLogin =
98
- "docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY";
114
+ export const gitlabDockerLogin = (context: Context) =>
115
+ isOfDeployType(context.componentConfig.deploy, "google-cloudrun")
116
+ ? [
117
+ ...gcloudServiceAccountLoginCommands(context),
118
+ `gcloud auth configure-docker ${getArtifactsRegistryHost(context)}`,
119
+ ]
120
+ : [
121
+ "docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
122
+ ];
99
123
 
100
- export const getDockerBuildDefaultScript = (ensureDockerFileScript?: string) =>
124
+ export const getDockerBuildDefaultScript = (
125
+ context: Context,
126
+ ensureDockerFileScript?: string
127
+ ) =>
101
128
  [
102
129
  ensureDockerFileScript,
103
- ...collapseableSection("docker-login", "Docker Login")([gitlabDockerLogin]),
130
+ ...collapseableSection(
131
+ "docker-login",
132
+ "Docker Login"
133
+ )(gitlabDockerLogin(context)),
104
134
  ...collapseableSection(
105
135
  "docker-build",
106
136
  "Docker build"
@@ -60,6 +60,7 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
60
60
 
61
61
  dockerBuild: {
62
62
  script: getDockerBuildDefaultScript(
63
+ context,
63
64
  buildConfig.type === "node-static" || buildConfig.type === "storybook"
64
65
  ? "ensureNginxDockerfile"
65
66
  : "ensureNodeDockerfile"
@@ -64,7 +64,7 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
64
64
  }
65
65
  : undefined,
66
66
  dockerBuild: {
67
- script: getDockerBuildDefaultScript("ensureMeteorDockerfile"),
67
+ script: getDockerBuildDefaultScript(context, "ensureMeteorDockerfile"),
68
68
  variables: {
69
69
  METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
70
70
  },
@@ -19,7 +19,7 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
19
19
  return createBuildJobs(context, {
20
20
  appBuild: undefined,
21
21
  dockerBuild: {
22
- script: getDockerBuildDefaultScript(),
22
+ script: getDockerBuildDefaultScript(context),
23
23
  variables: {},
24
24
  },
25
25
  });
@@ -39,7 +39,7 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
39
39
  },
40
40
  // custom script
41
41
  script: [
42
- gitlabDockerLogin,
42
+ ...gitlabDockerLogin(context),
43
43
  `docker pull $DOCKER_CACHE_IMAGE || true`,
44
44
  `wget --output-document=- https://github.com/buildpacks/pack/releases/download/v${cnbConf?.packVersion}/pack-v${cnbConf?.packVersion}-linux.tgz | tar -zx --directory /usr/local/bin pack`,
45
45
  `chmod +x /usr/local/bin/pack`,
@@ -1,9 +1,33 @@
1
- import { gitlabDockerLogin } from "../../build/docker";
2
1
  import type { Context } from "../../types/context";
3
2
  import { allowFailureInScripts } from "../../utils/gitlab";
4
3
  import { isOfDeployType } from "../types";
5
4
  import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
6
5
 
6
+ export const getArtifactsRegistryHost = ({
7
+ componentConfig: { deploy },
8
+ }: Context) => {
9
+ if (!isOfDeployType(deploy, "google-cloudrun")) {
10
+ // should not happen
11
+ throw new Error("deploy config is wrong");
12
+ }
13
+ return `${deploy.region}-docker.pkg.dev`;
14
+ };
15
+
16
+ export const getArtifactsRegistryDockerUrl = (context: Context) => {
17
+ const deployConfig = context.componentConfig.deploy;
18
+
19
+ if (!isOfDeployType(deployConfig, "google-cloudrun")) {
20
+ // should not happen
21
+ throw new Error("deploy config is wrong");
22
+ }
23
+
24
+ const fullAppName = `${context.fullConfig.customerName}-${context.fullConfig.appName}`;
25
+
26
+ return `${getArtifactsRegistryHost(context)}/${
27
+ deployConfig.projectId
28
+ }/catladder-deploy/${fullAppName}`;
29
+ };
30
+
7
31
  /**
8
32
  *
9
33
  * lecacyReviewImageName is only temporary. In old versions the images had no reviewslug in review apps, which makes cleanup harder. We delete all those images now, but need the path
@@ -12,19 +36,11 @@ export const getArtifactsRegistryImageName = (
12
36
  context: Context,
13
37
  lecacyReviewImageName = false
14
38
  ) => {
15
- const deployConfig = context.componentConfig.deploy;
16
-
17
- if (!isOfDeployType(deployConfig, "google-cloudrun")) {
18
- // should not happen
19
- throw new Error("deploy config is wrong");
20
- }
21
-
22
39
  if (lecacyReviewImageName && context.environment.envType !== "review") {
23
40
  throw new Error("lecacyReviewImageName is only allowed for review app");
24
41
  }
25
- const fullAppName = `${context.fullConfig.customerName}-${context.fullConfig.appName}`;
26
42
 
27
- const dockerUrl = `${deployConfig.region}-docker.pkg.dev/${deployConfig.projectId}/catladder-deploy/${fullAppName}`;
43
+ const dockerUrl = getArtifactsRegistryDockerUrl(context);
28
44
  const gcloudImagePath = [
29
45
  dockerUrl,
30
46
  context.environment.shortName,
@@ -37,31 +53,16 @@ export const getArtifactsRegistryImageName = (
37
53
  return gcloudImagePath.join("/");
38
54
  };
39
55
 
56
+ export const getArtifactsRegistryBuildCacheImage = (context: Context) => {
57
+ const dockerUrl = getArtifactsRegistryDockerUrl(context);
58
+ // does not include env, so that after merge, you might get more cache hits (review-->dev)
59
+ const gcloudImagePath = [dockerUrl, "caches", context.componentName];
60
+ return gcloudImagePath.join("/");
61
+ };
62
+
40
63
  export const getArtifactsRegistryImage = (context: Context) =>
41
64
  `${getArtifactsRegistryImageName(context)}:$DOCKER_IMAGE_TAG`;
42
65
 
43
- /**
44
- * commands to pull the image from the default registry and pushes it to google artifact registry. We might build and push directly to google artifact registry in the future
45
- */
46
- export const getPushToArtifactsRegistryCommands = (context: Context) => {
47
- const deployConfig = context.componentConfig.deploy;
48
-
49
- if (!isOfDeployType(deployConfig, "google-cloudrun")) {
50
- // should not happen
51
- throw new Error("deploy config is wrong");
52
- }
53
-
54
- const fullImageName = getArtifactsRegistryImageName(context);
55
-
56
- return [
57
- gitlabDockerLogin,
58
- `gcloud auth configure-docker ${deployConfig.region}-docker.pkg.dev`,
59
- `docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
60
- `docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG ${fullImageName}:$DOCKER_IMAGE_TAG`,
61
- `docker push ${fullImageName}:$DOCKER_IMAGE_TAG`,
62
- ];
63
- };
64
-
65
66
  const getDeleteImageCommands = (fullImageName: string, keepNewest = 0) => {
66
67
  if (keepNewest === 0) {
67
68
  // no need to list tags, we delete the whole thing
@@ -101,9 +102,11 @@ export const getDeleteUnusedImagesCommands = (context: Context, keep = 0) => {
101
102
  }
102
103
 
103
104
  const fullImageName = getArtifactsRegistryImageName(context);
105
+ const buildCacheImageName = getArtifactsRegistryBuildCacheImage(context);
104
106
 
105
107
  return [
106
108
  ...getDeleteImageCommands(fullImageName, keep),
109
+ ...getDeleteImageCommands(buildCacheImageName, 1),
107
110
  // because a recent version of catladder had no review-slug in the image name, we have to delete those as well
108
111
  // we can later remove this line in some months
109
112
 
@@ -26,10 +26,7 @@ import {
26
26
  } from "./utils/database";
27
27
  import { gcloudServiceAccountLoginCommands } from "./utils/gcloudServiceAccountLoginCommands";
28
28
  import { getCloudRunJobName } from "./utils/jobName";
29
- import {
30
- getArtifactsRegistryImage,
31
- getPushToArtifactsRegistryCommands,
32
- } from "./artifactsRegistry";
29
+ import { getArtifactsRegistryImage } from "./artifactsRegistry";
33
30
  import { getServiceName } from "./utils/getServiceName";
34
31
  import { getRemoveOldRevisionsAndImagesCommand } from "./cleanup";
35
32
 
@@ -219,10 +216,6 @@ export const createGoogleCloudRunDeployJobs = (
219
216
  ...gcloudServiceAccountLoginCommands(context),
220
217
  ...setExtraVarsScripts(deployConfig),
221
218
  ]),
222
- ...collapseableSection(
223
- "pushToArtifactRegistry",
224
- "Pushing image to artifacts registry"
225
- )(getPushToArtifactsRegistryCommands(context)),
226
219
  ...collapseableSection(
227
220
  "deploy",
228
221
  "Deploy to cloud run"
@@ -19,7 +19,7 @@ export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
19
19
  deploy: {
20
20
  ...getDockerJobBaseProps(context),
21
21
  script: [
22
- gitlabDockerLogin,
22
+ ...gitlabDockerLogin(context),
23
23
  `docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
24
24
  `docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_IMAGE:${tag}`,
25
25
  `docker push $DOCKER_IMAGE:${tag}`,