@catladder/pipeline 0.0.0-update-docker-for-apps-e047cc44 → 0.0.0-update-node-b0c7282d

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 (51) 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 +53 -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 +146 -49
  8. package/dist/constants.js +1 -1
  9. package/dist/deploy/base/deploy.js +1 -1
  10. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +7 -4
  11. package/dist/deploy/cloudRun/artifactsRegistry.js +30 -23
  12. package/dist/deploy/cloudRun/deployJob.js +14 -9
  13. package/dist/deploy/dockerTag/deployJob.js +32 -1
  14. package/dist/deploy/types/googleCloudRun.d.ts +10 -6
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +73 -77
  17. package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +1813 -0
  18. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +73 -77
  19. package/examples/__snapshots__/cloud-run-non-public.ts.snap +73 -77
  20. package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +1855 -0
  21. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +146 -154
  22. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +146 -154
  23. package/examples/__snapshots__/cloud-run-with-worker.ts.snap +1853 -0
  24. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +73 -77
  25. package/examples/__snapshots__/custom-build-job.ts.snap +73 -77
  26. package/examples/__snapshots__/custom-deploy.ts.snap +65 -53
  27. package/examples/__snapshots__/custom-sbom-java.ts.snap +73 -77
  28. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +41 -29
  29. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +41 -29
  30. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +41 -29
  31. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +82 -58
  32. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +41 -29
  33. package/examples/__snapshots__/meteor-kubernetes.ts.snap +41 -29
  34. package/examples/__snapshots__/native-app.ts.snap +73 -77
  35. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +73 -77
  36. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +58 -54
  37. package/examples/cloud-run-meteor-with-worker.ts +35 -0
  38. package/examples/cloud-run-post-stop-job.ts +40 -0
  39. package/examples/cloud-run-with-worker.ts +35 -0
  40. package/examples/custom-deploy.ts +8 -0
  41. package/package.json +1 -1
  42. package/src/build/custom/buildJob.ts +1 -0
  43. package/src/build/docker.ts +56 -16
  44. package/src/build/node/buildJob.ts +1 -0
  45. package/src/build/node/meteor.ts +1 -1
  46. package/src/build/rails/build.ts +2 -2
  47. package/src/deploy/base/deploy.ts +1 -1
  48. package/src/deploy/cloudRun/artifactsRegistry.ts +35 -32
  49. package/src/deploy/cloudRun/deployJob.ts +30 -15
  50. package/src/deploy/dockerTag/deployJob.ts +1 -1
  51. package/src/deploy/types/googleCloudRun.ts +11 -6
@@ -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,14 +26,11 @@ 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
 
36
- const setExtraVarsScripts = (deployConfig: DeployConfigCloudRun) => [
33
+ const setGoogleProjectNumberScript = (deployConfig: DeployConfigCloudRun) => [
37
34
  `export GCLOUD_PROJECT_NUMBER=$(gcloud projects describe ${deployConfig.projectId} --format="value(projectNumber)")`,
38
35
  `echo "GCLOUD_PROJECT_NUMBER: $GCLOUD_PROJECT_NUMBER"`,
39
36
  ];
@@ -112,9 +109,15 @@ export const createGoogleCloudRunDeployJobs = (
112
109
  ? service?.command ?? context.componentConfig.build.startCommand
113
110
  : undefined;
114
111
 
112
+ const commandArray = command
113
+ ? Array.isArray(command)
114
+ ? command
115
+ : command.split(" ")
116
+ : undefined;
117
+
115
118
  const argsString = createArgsString({
116
119
  // command as empty string resets it to default (uses the image's entrypoint)
117
- command: command ? '"' + command.split(" ").join(",") + '"' : '""',
120
+ command: commandArray ? '"' + commandArray.join(",") + '"' : '""',
118
121
  ...commonDeployArgs,
119
122
  "env-vars-file": "____envvars.yaml",
120
123
  "min-instances": customConfig?.minInstances ?? 0,
@@ -137,9 +140,15 @@ export const createGoogleCloudRunDeployJobs = (
137
140
  // lucky, update on the other hand accepts it... so let's just imediatly update it
138
141
 
139
142
  // also we cannot upsert a job, so we have to create it and catch the error and then update
143
+
144
+ const commandArray = Array.isArray(job.command)
145
+ ? job.command
146
+ : job.command.split(" ");
147
+
140
148
  const commonDeployArgsString = createArgsString({
141
- command: '"' + job.command.split(" ").join(",") + '"',
149
+ command: '"' + commandArray.join(",") + '"',
142
150
  ...commonDeployArgs,
151
+ image: job.image || commonDeployArgs.image,
143
152
  memory: job.memory || "512Mi",
144
153
  "task-timeout": job.timeout || "10m",
145
154
  });
@@ -158,14 +167,22 @@ export const createGoogleCloudRunDeployJobs = (
158
167
  .map(({ job, jobName }) => getJobCreateScriptsForJob(jobName, job))
159
168
  .flat();
160
169
 
161
- const getJobRunScriptForJob = (jobName: string) => {
162
- return `gcloud beta run jobs execute ${jobName} ${commonArgsString}`;
170
+ const getJobRunScriptForJob = (jobName: string, wait: boolean) => {
171
+ return `gcloud beta run jobs execute ${jobName} ${commonArgsString}${
172
+ wait ? " --wait" : ""
173
+ }`;
163
174
  };
164
175
 
165
176
  const getJobRunScripts = (when: DeployConfigCloudRunJob["when"]) =>
166
177
  jobsWithNames
167
178
  .filter(({ job }) => job.when === when)
168
- .map(({ jobName }) => getJobRunScriptForJob(jobName));
179
+ .map(({ jobName }) =>
180
+ getJobRunScriptForJob(
181
+ jobName,
182
+ // wait for completin on stop jobs, since stop will delete the jobs afterwards, so they will fail
183
+ ["preStop", "postStop"].includes(when)
184
+ )
185
+ );
169
186
 
170
187
  const getCreateScheduleScripts = () => {
171
188
  return jobsWithSchedule
@@ -217,12 +234,8 @@ export const createGoogleCloudRunDeployJobs = (
217
234
  "Prepare..."
218
235
  )([
219
236
  ...gcloudServiceAccountLoginCommands(context),
220
- ...setExtraVarsScripts(deployConfig),
237
+ ...setGoogleProjectNumberScript(deployConfig),
221
238
  ]),
222
- ...collapseableSection(
223
- "pushToArtifactRegistry",
224
- "Pushing image to artifacts registry"
225
- )(getPushToArtifactsRegistryCommands(context)),
226
239
  ...collapseableSection(
227
240
  "deploy",
228
241
  "Deploy to cloud run"
@@ -254,6 +267,7 @@ export const createGoogleCloudRunDeployJobs = (
254
267
 
255
268
  const stopScripts = [
256
269
  ...gcloudServiceAccountLoginCommands(context),
270
+ ...getJobRunScripts("preStop"),
257
271
  ...(deployConfig.service !== false
258
272
  ? [`gcloud run services delete ${serviceName} ${commonArgsString}`]
259
273
  : []),
@@ -261,6 +275,7 @@ export const createGoogleCloudRunDeployJobs = (
261
275
  ([name]) =>
262
276
  `gcloud run services delete ${serviceName}-${name} ${commonArgsString}`
263
277
  ),
278
+ ...getJobRunScripts("postStop"),
264
279
  ...getDeleteSchedulesScripts(),
265
280
  ...getDeleteJobsScripts(),
266
281
  ...(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop
@@ -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}`,
@@ -78,7 +78,7 @@ export type DeployConfigCloudRunService = {
78
78
  /**
79
79
  * command / entrypoint, fallsback to buildConfig.startcommand
80
80
  */
81
- command?: string;
81
+ command?: string | string[];
82
82
 
83
83
  /**
84
84
  * how many instances to keep around when there are no requests. defaults to 0.
@@ -123,7 +123,12 @@ export type DeployConfigCloudRunJobBase = {
123
123
  /**
124
124
  * command
125
125
  */
126
- command: string;
126
+ command: string | string[];
127
+
128
+ /**
129
+ * custom image to use. Defaults to the image from the build
130
+ */
131
+ image?: string;
127
132
 
128
133
  /**
129
134
  * memory limit of the job, defaults to 51Mi
@@ -151,7 +156,7 @@ export type DeployConfigCloudRunJobWithSchedule =
151
156
  };
152
157
 
153
158
  export type DeployConfigCloudRunJobNormal = DeployConfigCloudRunJobBase & {
154
- when: "manual" | "preDeploy" | "postDeploy";
159
+ when: "manual" | "preDeploy" | "postDeploy" | "preStop" | "postStop";
155
160
  };
156
161
 
157
162
  export type DeployConfigCloudRunJob =
@@ -160,9 +165,9 @@ export type DeployConfigCloudRunJob =
160
165
 
161
166
  export type DeployConfigCloudRun = {
162
167
  /**
163
- * EXPERIMENTAL cloud run deployment.
168
+ * cloud run deployment.
164
169
  *
165
- * This will deploy a cloud run service.
170
+ * This will deploy a cloud run service. You can optionally define one-time and scheduled jobs running on cloud run
166
171
  *
167
172
  * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
168
173
  */
@@ -182,7 +187,7 @@ export type DeployConfigCloudRun = {
182
187
  service?: boolean | DeployConfigCloudRunService;
183
188
 
184
189
  /**
185
- * deploy additional services with different entry pointss
190
+ * deploy additional services with different entry points.
186
191
  */
187
192
  additionalServices?: {
188
193
  [name: string]: DeployConfigCloudRunService;