@catladder/pipeline 0.0.0-fix-command-710f75f1 → 0.0.0-fix-error-sql-db-delete-b3878c2e

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 (98) hide show
  1. package/dist/build/custom/buildJob.js +1 -0
  2. package/dist/build/docker.d.ts +4 -18
  3. package/dist/build/docker.js +15 -9
  4. package/dist/build/index.js +7 -1
  5. package/dist/build/rails/build.js +37 -16
  6. package/dist/build/rails/index.d.ts +2 -2
  7. package/dist/build/rails/test.js +1 -2
  8. package/dist/build/types.d.ts +36 -4
  9. package/dist/bundles/catladder-gitlab/index.js +543 -218
  10. package/dist/constants.js +1 -1
  11. package/dist/context/getEnvironment.js +1 -0
  12. package/dist/context/getEnvironmentContext.js +5 -3
  13. package/dist/context/getEnvironmentVariables.d.ts +5 -1
  14. package/dist/context/getEnvironmentVariables.js +7 -2
  15. package/dist/deploy/base.js +1 -1
  16. package/dist/deploy/cloudRun/index.js +14 -6
  17. package/dist/deploy/custom/deployJob.js +6 -3
  18. package/dist/deploy/index.d.ts +2 -1
  19. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -1
  20. package/dist/deploy/kubernetes/additionalSecretKeys.js +5 -1
  21. package/dist/deploy/kubernetes/deployJob.js +4 -4
  22. package/dist/deploy/kubernetes/kubeValues.d.ts +1 -0
  23. package/dist/deploy/kubernetes/kubeValues.js +9 -6
  24. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +1 -0
  25. package/dist/deploy/types/custom.d.ts +2 -1
  26. package/dist/deploy/types/googleCloudRun.d.ts +5 -1
  27. package/dist/deploy/types/kubernetes.d.ts +9 -0
  28. package/dist/pipeline/createAllJobs.d.ts +8 -0
  29. package/dist/pipeline/createAllJobs.js +164 -0
  30. package/dist/pipeline/createChildPipeline.js +24 -48
  31. package/dist/pipeline/createJobsForComponent.d.ts +3 -0
  32. package/dist/pipeline/{createJobs.js → createJobsForComponent.js} +8 -105
  33. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +14 -0
  34. package/dist/pipeline/gitlab/createGitlabJobs.js +260 -0
  35. package/dist/pipeline/index.d.ts +1 -1
  36. package/dist/pipeline/index.js +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/dist/types/config.d.ts +3 -3
  39. package/dist/types/context.d.ts +3 -1
  40. package/dist/types/environmentContext.d.ts +7 -0
  41. package/dist/types/gitlab-types.d.ts +5 -1
  42. package/dist/types/jobs.d.ts +9 -2
  43. package/dist/utils/gitlab.js +1 -1
  44. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +32 -32
  45. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +32 -32
  46. package/examples/__snapshots__/cloud-run-non-public.ts.snap +32 -32
  47. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3116 -0
  48. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +65 -65
  49. package/examples/__snapshots__/custom-build-job.ts.snap +32 -32
  50. package/examples/__snapshots__/custom-deploy.ts.snap +1384 -0
  51. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +2280 -0
  52. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +2204 -0
  53. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +24 -24
  54. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
  55. package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
  56. package/examples/custom-deploy.ts +25 -0
  57. package/examples/kubernetes-application-customization.ts +57 -0
  58. package/examples/kubernetes-with-cloud-sql-legacy.ts +33 -0
  59. package/examples/rails-k8s-with-worker.ts +95 -0
  60. package/package.json +1 -1
  61. package/src/build/custom/buildJob.ts +1 -0
  62. package/src/build/docker.ts +13 -6
  63. package/src/build/index.ts +7 -1
  64. package/src/build/node/cache.ts +2 -2
  65. package/src/build/rails/build.ts +20 -10
  66. package/src/build/rails/index.ts +2 -2
  67. package/src/build/rails/test.ts +43 -39
  68. package/src/build/types.ts +40 -5
  69. package/src/config/configruedEnvs.ts +2 -8
  70. package/src/context/getEnvironment.ts +1 -0
  71. package/src/context/getEnvironmentContext.ts +6 -6
  72. package/src/context/getEnvironmentVariables.ts +9 -4
  73. package/src/deploy/base.ts +1 -1
  74. package/src/deploy/cloudRun/deployJob.ts +1 -1
  75. package/src/deploy/cloudRun/index.ts +12 -4
  76. package/src/deploy/custom/deployJob.ts +9 -1
  77. package/src/deploy/index.ts +4 -1
  78. package/src/deploy/kubernetes/additionalSecretKeys.ts +1 -1
  79. package/src/deploy/kubernetes/deployJob.ts +2 -1
  80. package/src/deploy/kubernetes/kubeValues.ts +7 -5
  81. package/src/deploy/types/custom.ts +2 -1
  82. package/src/deploy/types/googleCloudRun.ts +6 -1
  83. package/src/deploy/types/kubernetes.ts +11 -1
  84. package/src/pipeline/createAllJobs.ts +38 -0
  85. package/src/pipeline/createChildPipeline.ts +6 -22
  86. package/src/pipeline/createJobsForComponent.ts +64 -0
  87. package/src/pipeline/gitlab/createGitlabJobs.ts +149 -0
  88. package/src/pipeline/index.ts +1 -1
  89. package/src/types/context.ts +3 -1
  90. package/src/types/environmentContext.ts +7 -0
  91. package/src/types/gitlab-types.ts +10 -3
  92. package/src/types/jobs.ts +11 -2
  93. package/src/utils/gitlab.ts +1 -1
  94. package/dist/pipeline/createJobs.d.ts +0 -3
  95. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +0 -10
  96. package/dist/pipeline/gitlab/makeGitlabJob.js +0 -44
  97. package/src/pipeline/createJobs.ts +0 -199
  98. package/src/pipeline/gitlab/makeGitlabJob.ts +0 -23
package/src/types/jobs.ts CHANGED
@@ -5,6 +5,7 @@ import type {
5
5
  GitlabRule,
6
6
  GitlabVariables,
7
7
  GitlabJobService,
8
+ GitlabJobImage,
8
9
  } from "./gitlab-types";
9
10
 
10
11
  export const BASE_STAGES = [
@@ -18,7 +19,9 @@ export const BASE_STAGES = [
18
19
  ] as const;
19
20
  export type BaseStage = typeof BASE_STAGES[number];
20
21
 
21
- export type CatladderJobNeed = string | { job: string; artifacts: boolean };
22
+ export type CatladderJobNeed =
23
+ | string
24
+ | { job: string; artifacts: boolean; componentName?: string };
22
25
  export type CatladderJob<S = BaseStage> = {
23
26
  /**
24
27
  * the name of the job (without any env or app prefix and suffix)
@@ -52,9 +55,15 @@ export type CatladderJob<S = BaseStage> = {
52
55
 
53
56
  /**
54
57
  * does this require another job (from the same component)?
58
+ *
59
+ * You can also require a job from another component if you set `componentName`
60
+ *
55
61
  */
56
62
  needs?: Array<CatladderJobNeed>;
57
63
 
64
+ /**
65
+ * @deprecated set `componentName` to `needs` if you want to wait for a job from another component
66
+ */
58
67
  needsOtherComponent?: Array<{
59
68
  componentName: string;
60
69
  job: string;
@@ -78,7 +87,7 @@ export type CatladderJob<S = BaseStage> = {
78
87
  /**
79
88
  * image to use
80
89
  */
81
- image?: string;
90
+ image?: GitlabJobImage;
82
91
 
83
92
  /**
84
93
  * variables to pass
@@ -14,7 +14,7 @@ export const repeatOnFailure = (
14
14
  }
15
15
  ): string => {
16
16
  return `
17
- until ${command} &> /dev/null
17
+ until ${command}
18
18
  do
19
19
  echo "Trying again."
20
20
  sleep ${options.pauseInSeconds}
@@ -1,3 +0,0 @@
1
- import type { PipelineJob } from "../types";
2
- import type { Config, PipelineTrigger } from "../types/config";
3
- export declare const createJobs: <T extends "gitlab">(type: T, envs: string[], config: Config, componentName: string, trigger: PipelineTrigger) => Promise<Record<string, PipelineJob<T>>>;
@@ -1,10 +0,0 @@
1
- import type { GitlabJobDef } from "../../types";
2
- import type { CatladderJob } from "../../types/jobs";
3
- export declare const makeGitlabJob: ({
4
- envMode,
5
- needsStages,
6
- needsOtherComponent,
7
- name,
8
- needs,
9
- ...rest
10
- }: CatladderJob<string>) => GitlabJobDef;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- var __assign = this && this.__assign || function () {
4
- __assign = Object.assign || function (t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = this && this.__rest || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- exports.__esModule = true;
22
- exports.makeGitlabJob = void 0;
23
- var lodash_1 = require("lodash");
24
- var defaults_1 = require("../../defaults");
25
- var getJobName = function (need) {
26
- return (0, lodash_1.isObject)(need) ? need.job : need;
27
- };
28
- var makeGitlabJob = function (_a) {
29
- var envMode = _a.envMode,
30
- needsStages = _a.needsStages,
31
- needsOtherComponent = _a.needsOtherComponent,
32
- name = _a.name,
33
- needs = _a.needs,
34
- rest = __rest(_a, ["envMode", "needsStages", "needsOtherComponent", "name", "needs"]);
35
- return __assign(__assign({}, rest), {
36
- // sort in a predictable manner for snapshot tests
37
- needs: needs === null || needs === void 0 ? void 0 : needs.sort(function (a, b) {
38
- return getJobName(a).localeCompare(getJobName(b));
39
- }),
40
- retry: defaults_1.BASE_RETRY,
41
- interruptible: true
42
- });
43
- };
44
- exports.makeGitlabJob = makeGitlabJob;
@@ -1,199 +0,0 @@
1
- import { isFunction, isObject } from "lodash";
2
- import { BUILD_TYPES } from "../build";
3
- import { createContext } from "../context";
4
- import { DEPLOY_TYPES } from "../deploy";
5
- import type { PipelineJob, PipelineType } from "../types";
6
- import type { Config, PipelineTrigger } from "../types/config";
7
- import type { CommitInfo, Context } from "../types/context";
8
- import type { CatladderJob, CatladderJobNeed } from "../types/jobs";
9
- import { notNil } from "../utils";
10
- import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
11
- import { makeGitlabJob } from "./gitlab/makeGitlabJob";
12
- import { getPackageManagerInfo } from "./packageManager";
13
-
14
- const injectDefaultVarsInCustomJobs = (
15
- context: Context,
16
- jobs: CatladderJob[]
17
- ) =>
18
- jobs.map(({ variables, ...job }) => ({
19
- variables: {
20
- ...(context.environment.envVars ?? {}),
21
- ...(variables ?? {}),
22
- },
23
- ...job,
24
- }));
25
- const getCustomJobs = (context: Context) => {
26
- if (!context.componentConfig.customJobs) {
27
- return [];
28
- }
29
- const rawJobs = isFunction(context.componentConfig.customJobs)
30
- ? context.componentConfig.customJobs(context)
31
- : context.componentConfig.customJobs;
32
- return injectDefaultVarsInCustomJobs(context, rawJobs);
33
- };
34
- const createRawJobs = (context: Context): CatladderJob[] => {
35
- if (context.componentConfig.deploy === false) {
36
- return [];
37
- }
38
- const buildJobs =
39
- BUILD_TYPES[context.componentConfig.build.type].jobs(context);
40
- const deployJobs =
41
- DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context);
42
-
43
- const customJobs = getCustomJobs(context);
44
- return [...buildJobs, ...deployJobs, ...customJobs];
45
- };
46
- const getFullJobName = (
47
- name: string,
48
- componentName: string,
49
- env?: string | null
50
- ) => {
51
- if (env) {
52
- return `${componentName} ${name} | ${env} `;
53
- }
54
- return `${componentName} ${name}`;
55
- };
56
-
57
- const getFullReferencedJobName = (
58
- referencedJobName: string,
59
- componentName: string,
60
- env: string,
61
- allRawJobs: CatladderJob[]
62
- ) => {
63
- const referencedJob = allRawJobs.find((j) => j.name === referencedJobName);
64
- if (!referencedJob) {
65
- throw new Error("unknown job referenced: " + referencedJobName);
66
- }
67
- const envToSet = referencedJob.envMode !== "none" ? env : null;
68
- return getFullJobName(referencedJobName, componentName, envToSet);
69
- };
70
- // replaces references to other jobs with the full name
71
- // the full name contains the componentname and the env name (if any)
72
- const replaceReferences = (
73
- job: CatladderJob,
74
- componentName: string,
75
- env: string,
76
- allRawJobs: CatladderJob[]
77
- ): CatladderJob<string> => {
78
- const stage =
79
- job.envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
80
-
81
- const needsFromNeeds: CatladderJob["needs"] = job.needs?.map((n) =>
82
- isObject(n)
83
- ? {
84
- job: getFullReferencedJobName(n.job, componentName, env, allRawJobs),
85
- artifacts: n.artifacts,
86
- }
87
- : getFullReferencedJobName(n, componentName, env, allRawJobs)
88
- );
89
- const needsFromOtherComponents: CatladderJob["needs"] =
90
- job.needsOtherComponent?.map((other) => ({
91
- artifacts: other.artifacts,
92
- job: getFullReferencedJobName(
93
- other.job,
94
- other.componentName,
95
- env,
96
- allRawJobs
97
- ),
98
- }));
99
- const needs = [
100
- ...(needsFromNeeds ?? []),
101
- ...(needsFromOtherComponents ?? []),
102
- ];
103
- return {
104
- ...job,
105
- stage,
106
- needs,
107
- environment: job.environment?.on_stop
108
- ? {
109
- ...job.environment,
110
- on_stop: getFullReferencedJobName(
111
- job.environment.on_stop,
112
- componentName,
113
- env,
114
- allRawJobs
115
- ),
116
- }
117
- : job.environment,
118
- };
119
- };
120
-
121
- // this can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/220758 is resolved
122
- const addStageNeeds = (jobs: CatladderJob[]): CatladderJob[] => {
123
- // when a job defines needsStages, we add these as needs
124
- return jobs.map((job) => {
125
- if (!job.needsStages || job.needsStages.length === 0) {
126
- return job;
127
- }
128
-
129
- const neededJobs = jobs
130
- .map((j) => {
131
- const neededStage = job.needsStages?.find((s) => j.stage === s.stage);
132
- if (neededStage) {
133
- return {
134
- job: j.name,
135
- artifacts: neededStage.artifacts ?? false,
136
- };
137
- }
138
- })
139
- .filter(notNil);
140
- return {
141
- ...job,
142
-
143
- needs: [...(job.needs ?? []), ...neededJobs],
144
- };
145
- });
146
- };
147
-
148
- export const createJobs = async <T extends PipelineType>(
149
- type: T,
150
- envs: string[],
151
- config: Config,
152
- componentName: string,
153
- trigger: PipelineTrigger
154
- ): Promise<Record<string, PipelineJob<T>>> => {
155
- const commitInfo: CommitInfo = {
156
- ...(await getBaseCommitInfo()),
157
- trigger,
158
- };
159
-
160
- const packageManagerInfo = await getPackageManagerInfo(config, componentName);
161
-
162
- return envs.reduce(async (acc, env) => {
163
- const context = await createContext(
164
- config,
165
- componentName,
166
- env,
167
- commitInfo,
168
- packageManagerInfo
169
- );
170
- const jobs = addStageNeeds(createRawJobs(context));
171
-
172
- const result = {
173
- ...(await acc),
174
- ...jobs.reduce<Record<string, PipelineJob<T>>>((acc, job) => {
175
- const jobWithResolvedReferences = replaceReferences(
176
- job,
177
- componentName,
178
- env,
179
- jobs
180
- );
181
- const jobName = getFullJobName(
182
- job.name,
183
- componentName,
184
- job.envMode !== "none" ? env : undefined
185
- );
186
- if (type === "gitlab") {
187
- return {
188
- ...acc,
189
- [jobName]: makeGitlabJob(
190
- jobWithResolvedReferences
191
- ) as PipelineJob<T>,
192
- };
193
- }
194
- throw new Error("not supported");
195
- }, await Promise.resolve({})),
196
- };
197
- return result;
198
- }, {});
199
- };
@@ -1,23 +0,0 @@
1
- import { isObject } from "lodash";
2
- import { BASE_RETRY } from "../../defaults";
3
- import type { GitlabJobDef } from "../../types";
4
- import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
5
- const getJobName = (need: CatladderJobNeed) =>
6
- isObject(need) ? need.job : need;
7
-
8
- export const makeGitlabJob = ({
9
- envMode,
10
- needsStages,
11
- needsOtherComponent,
12
- name,
13
- needs,
14
- ...rest
15
- }: CatladderJob<string>): GitlabJobDef => {
16
- return {
17
- ...rest,
18
- // sort in a predictable manner for snapshot tests
19
- needs: needs?.sort((a, b) => getJobName(a).localeCompare(getJobName(b))),
20
- retry: BASE_RETRY,
21
- interruptible: true,
22
- };
23
- };