@catladder/pipeline 0.0.0-refactor-gcloud-api-5bd4bbed → 0.0.0-refactor-needs-aae6e67d
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.
- package/dist/build/custom/buildJob.js +1 -0
- package/dist/build/index.js +7 -1
- package/dist/build/rails/build.js +41 -16
- package/dist/build/rails/index.d.ts +2 -2
- package/dist/build/types.d.ts +36 -4
- package/dist/bundles/catladder-gitlab/index.js +125 -54
- package/dist/constants.js +1 -1
- package/dist/context/__tests__/resolveReferences.test.js +15 -20
- package/dist/context/getEnvironment.js +1 -0
- package/dist/context/getEnvironmentContext.js +5 -3
- package/dist/context/getEnvironmentVariables.js +2 -2
- package/dist/context/resolveReferences.d.ts +1 -1
- package/dist/context/resolveReferences.js +3 -1
- package/dist/deploy/base.js +1 -1
- package/dist/deploy/cloudRun/deployJob.js +9 -7
- package/dist/deploy/cloudRun/index.js +7 -6
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +1 -1
- package/dist/deploy/cloudRun/utils/createArgsString.js +6 -1
- package/dist/deploy/kubernetes/deployJob.js +4 -4
- package/dist/deploy/kubernetes/kubeValues.d.ts +3 -0
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +3 -0
- package/dist/deploy/types/custom.d.ts +2 -1
- package/dist/deploy/types/googleCloudRun.d.ts +11 -2
- package/dist/deploy/types/kubernetes.d.ts +11 -0
- package/dist/pipeline/createJobs.js +4 -9
- package/dist/pipeline/gitlab/makeGitlabJob.js +33 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +1 -0
- package/dist/types/environmentContext.d.ts +7 -0
- package/dist/types/gitlab-types.d.ts +25 -1
- package/dist/types/jobs.d.ts +9 -2
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +1572 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +1572 -0
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +48 -48
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3116 -0
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +108 -108
- package/examples/__snapshots__/custom-build-job.ts.snap +48 -48
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +24 -24
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
- package/examples/cloud-run-memory-limit.ts +28 -0
- package/examples/cloud-run-no-cpu-throttling.ts +33 -0
- package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
- package/examples/cloud-run-with-sql.ts +1 -1
- package/examples/rails-k8s-with-worker.ts +95 -0
- package/package.json +1 -1
- package/src/build/custom/buildJob.ts +1 -0
- package/src/build/index.ts +7 -1
- package/src/build/rails/build.ts +17 -10
- package/src/build/rails/index.ts +2 -2
- package/src/build/types.ts +40 -5
- package/src/context/__tests__/resolveReferences.test.ts +15 -30
- package/src/context/getEnvironment.ts +1 -0
- package/src/context/getEnvironmentContext.ts +6 -6
- package/src/context/getEnvironmentVariables.ts +7 -5
- package/src/context/resolveReferences.ts +3 -6
- package/src/deploy/base.ts +1 -1
- package/src/deploy/cloudRun/deployJob.ts +9 -11
- package/src/deploy/cloudRun/index.ts +5 -4
- package/src/deploy/cloudRun/utils/createArgsString.ts +9 -2
- package/src/deploy/kubernetes/deployJob.ts +1 -1
- package/src/deploy/types/custom.ts +2 -1
- package/src/deploy/types/googleCloudRun.ts +14 -2
- package/src/deploy/types/kubernetes.ts +12 -0
- package/src/pipeline/createJobs.ts +14 -17
- package/src/pipeline/gitlab/makeGitlabJob.ts +3 -1
- package/src/types/context.ts +1 -0
- package/src/types/environmentContext.ts +7 -0
- package/src/types/gitlab-types.ts +18 -1
- package/src/types/jobs.ts +11 -2
|
@@ -11,9 +11,16 @@ import { isNil } from "lodash";
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
export const createArgsString = (
|
|
14
|
-
args: Record<string, string | number | true | undefined>
|
|
14
|
+
args: Record<string, string | number | true | false | undefined>
|
|
15
15
|
) =>
|
|
16
16
|
Object.entries(args)
|
|
17
17
|
.filter(([, value]) => !isNil(value))
|
|
18
|
-
.map(([key, value]) =>
|
|
18
|
+
.map(([key, value]) => {
|
|
19
|
+
if (value === true) {
|
|
20
|
+
return `--${key}`;
|
|
21
|
+
} else if (value === false) {
|
|
22
|
+
return `--no-${key}`;
|
|
23
|
+
}
|
|
24
|
+
return `--${key}=${value}`;
|
|
25
|
+
})
|
|
19
26
|
.join(" ");
|
|
@@ -40,7 +40,7 @@ export const createKubernetesDeployJobs = (
|
|
|
40
40
|
quotingType: "'",
|
|
41
41
|
forceQuotes: true,
|
|
42
42
|
}),
|
|
43
|
-
HELM_GITLAB_CHART_NAME: "the-panter-chart",
|
|
43
|
+
HELM_GITLAB_CHART_NAME: deployConfig.chartName ?? "/helm-charts/the-panter-chart",
|
|
44
44
|
HELM_ARGS: [
|
|
45
45
|
...(deployConfig.debug ? ["--debug"] : []),
|
|
46
46
|
...(deployConfig.additionalHelmArgs ?? []),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GitlabJobImage } from "../../types";
|
|
1
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
2
3
|
import type { DeployConfigBase } from "./base";
|
|
3
4
|
|
|
@@ -26,7 +27,7 @@ export type DeployConfigCustom = {
|
|
|
26
27
|
/**
|
|
27
28
|
* image to use
|
|
28
29
|
*/
|
|
29
|
-
jobImage?:
|
|
30
|
+
jobImage?: GitlabJobImage;
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* customize cache for the job
|
|
@@ -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
|
|
@@ -67,6 +72,8 @@ export type DeployConfigCloudRunCloudSql = {
|
|
|
67
72
|
statement_cache_size?: number;
|
|
68
73
|
};
|
|
69
74
|
};
|
|
75
|
+
|
|
76
|
+
type Memory = `${number}${"M" | "G" | "Mi" | "Gi"}`;
|
|
70
77
|
export type DeployConfigCloudRunService = {
|
|
71
78
|
/**
|
|
72
79
|
* command / entrypoint, fallsback to buildConfig.startcommand
|
|
@@ -85,7 +92,7 @@ export type DeployConfigCloudRunService = {
|
|
|
85
92
|
maxInstances?: number;
|
|
86
93
|
|
|
87
94
|
/**
|
|
88
|
-
* set to true for workers
|
|
95
|
+
* set to true to allways allocate cpu, e.g. for workers. Careful that this is expensive!
|
|
89
96
|
*/
|
|
90
97
|
noCpuThrottling?: true;
|
|
91
98
|
|
|
@@ -93,6 +100,11 @@ export type DeployConfigCloudRunService = {
|
|
|
93
100
|
* whether to allow public access (defaults to true)
|
|
94
101
|
*/
|
|
95
102
|
allowUnauthenticated?: boolean;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* memory limit. Defaults to 512MB
|
|
106
|
+
*/
|
|
107
|
+
memory?: Memory;
|
|
96
108
|
};
|
|
97
109
|
|
|
98
110
|
export type DeployConfigCloudRunJobBase = {
|
|
@@ -234,6 +234,13 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
|
|
|
234
234
|
* It has the same environment variables as the application and an additional IS_WORKER="true" variable
|
|
235
235
|
*/
|
|
236
236
|
worker?: KubernetesWorkerDef;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* kubernetes resources for jobs and cronjobs
|
|
240
|
+
*/
|
|
241
|
+
jobDefaults?: {
|
|
242
|
+
resources: KubernetesResourcesDef;
|
|
243
|
+
}
|
|
237
244
|
}>;
|
|
238
245
|
|
|
239
246
|
/**
|
|
@@ -281,4 +288,9 @@ export type DeployConfigKubernetes = {
|
|
|
281
288
|
* values to configure the app
|
|
282
289
|
*/
|
|
283
290
|
values?: DeployConfigKubernetesValues;
|
|
291
|
+
/**
|
|
292
|
+
* Custom Helm chart location.
|
|
293
|
+
* Not recommended to use.
|
|
294
|
+
*/
|
|
295
|
+
chartName?: string
|
|
284
296
|
} & DeployConfigBase;
|
|
@@ -5,7 +5,7 @@ import { DEPLOY_TYPES } from "../deploy";
|
|
|
5
5
|
import type { PipelineJob, PipelineType } from "../types";
|
|
6
6
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
7
7
|
import type { CommitInfo, Context } from "../types/context";
|
|
8
|
-
import type { CatladderJob
|
|
8
|
+
import type { CatladderJob } from "../types/jobs";
|
|
9
9
|
import { notNil } from "../utils";
|
|
10
10
|
import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
|
|
11
11
|
import { makeGitlabJob } from "./gitlab/makeGitlabJob";
|
|
@@ -78,28 +78,25 @@ const replaceReferences = (
|
|
|
78
78
|
const stage =
|
|
79
79
|
job.envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
|
|
80
80
|
|
|
81
|
-
const
|
|
81
|
+
const cleanedNeeds: CatladderJob["needs"] = [
|
|
82
|
+
...(job.needs ?? []),
|
|
83
|
+
// pull in legacy needs from other component, which is now identical to needs
|
|
84
|
+
...(job.needsOtherComponent ?? []),
|
|
85
|
+
];
|
|
86
|
+
const needs: CatladderJob["needs"] = cleanedNeeds?.map((n) =>
|
|
82
87
|
isObject(n)
|
|
83
88
|
? {
|
|
84
|
-
job: getFullReferencedJobName(
|
|
89
|
+
job: getFullReferencedJobName(
|
|
90
|
+
n.job,
|
|
91
|
+
n.componentName ?? componentName,
|
|
92
|
+
env,
|
|
93
|
+
allRawJobs
|
|
94
|
+
),
|
|
85
95
|
artifacts: n.artifacts,
|
|
86
96
|
}
|
|
87
97
|
: getFullReferencedJobName(n, componentName, env, allRawJobs)
|
|
88
98
|
);
|
|
89
|
-
|
|
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
|
-
];
|
|
99
|
+
|
|
103
100
|
return {
|
|
104
101
|
...job,
|
|
105
102
|
stage,
|
|
@@ -16,7 +16,9 @@ export const makeGitlabJob = ({
|
|
|
16
16
|
return {
|
|
17
17
|
...rest,
|
|
18
18
|
// sort in a predictable manner for snapshot tests
|
|
19
|
-
needs: needs
|
|
19
|
+
needs: needs
|
|
20
|
+
? [...needs].sort((a, b) => getJobName(a).localeCompare(getJobName(b)))
|
|
21
|
+
: undefined,
|
|
20
22
|
retry: BASE_RETRY,
|
|
21
23
|
interruptible: true,
|
|
22
24
|
};
|
package/src/types/context.ts
CHANGED
|
@@ -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
|
|
|
@@ -2,7 +2,19 @@ export type Artifacts = {
|
|
|
2
2
|
paths: string[];
|
|
3
3
|
expire_in?: string;
|
|
4
4
|
when?: "always" | "on_success" | "on_failure";
|
|
5
|
+
reports?: ArtifactReports;
|
|
5
6
|
};
|
|
7
|
+
// Reports won't show up on MRs until https://gitlab.com/groups/gitlab-org/-/epics/8205
|
|
8
|
+
export type ArtifactReports =
|
|
9
|
+
| { accessibility: string | string[] }
|
|
10
|
+
| { coverage_report: string | string[] }
|
|
11
|
+
| { codequality: string | string[] }
|
|
12
|
+
| { cyclonedx: string | string[] }
|
|
13
|
+
| { dotenv: string | string[] }
|
|
14
|
+
| { junit: string | string[] }
|
|
15
|
+
| { sast: string | string[] }
|
|
16
|
+
| { secret_detection: string | string[] }
|
|
17
|
+
| { terraform: string | string[] }
|
|
6
18
|
export type GitlabJobCache = {
|
|
7
19
|
key: GitlabJobCacheKey;
|
|
8
20
|
policy?: string;
|
|
@@ -31,6 +43,11 @@ export type GitlabJobService = {
|
|
|
31
43
|
alias?: string;
|
|
32
44
|
};
|
|
33
45
|
|
|
46
|
+
export type GitlabJobImage = string | {
|
|
47
|
+
name: string;
|
|
48
|
+
entrypoint?: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
34
51
|
export type GitlabEnvironment = {
|
|
35
52
|
url: string;
|
|
36
53
|
name: string;
|
|
@@ -52,7 +69,7 @@ export type GitlabJobDef = {
|
|
|
52
69
|
artifacts?: Artifacts;
|
|
53
70
|
retry?: Retry;
|
|
54
71
|
services?: GitlabJobService[];
|
|
55
|
-
image?:
|
|
72
|
+
image?: GitlabJobImage;
|
|
56
73
|
variables?: GitlabVariables;
|
|
57
74
|
dependencies?: string[];
|
|
58
75
|
environment?: GitlabEnvironment;
|
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 =
|
|
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?:
|
|
90
|
+
image?: GitlabJobImage;
|
|
82
91
|
|
|
83
92
|
/**
|
|
84
93
|
* variables to pass
|