@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-rolling-update-3bca086c

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.
@@ -6,6 +6,12 @@ export type DeployConfigBase = {
6
6
  * - all other envs: auto
7
7
  */
8
8
  when?: "manual" | "auto";
9
+
10
+ /**
11
+ * EXPERIMENTAL
12
+ * wait for other components to deploy first, before doing this deployment
13
+ */
14
+ waitFor?: string[];
9
15
  };
10
16
  type AllowUnknownProps<T extends Record<string, unknown>> = T &
11
17
  Record<string, unknown>;
@@ -55,6 +61,16 @@ export type KubernetesAutoscale = {
55
61
  */
56
62
  metrics: KubernetesAutoscaleMetric[];
57
63
  };
64
+ export type KubernetesResourcesDef = {
65
+ limits?: {
66
+ cpu?: string;
67
+ memory?: string;
68
+ };
69
+ requests?: {
70
+ cpu?: string;
71
+ memory?: string;
72
+ };
73
+ };
58
74
  type KubernetesHealthDef = {
59
75
  httpGet?: {
60
76
  path?: string;
@@ -69,6 +85,31 @@ type KubernetesHealthDef = {
69
85
  successThreshold?: number;
70
86
  };
71
87
  };
88
+ export type KubernetesUpdateStrategy = {
89
+ rollingUpdate: {
90
+ /**
91
+ * how many pods can be created additionally to the target number
92
+ * can be absolute number or percentage.
93
+ * defaults to 1 (kube default is 25%)
94
+ */
95
+ maxSurge: number | string;
96
+ /**
97
+ * how many pods are allowed to be unavailable
98
+ * can be absolute number or percentage
99
+ * defaults to 0 (kube default is 25%)
100
+ */
101
+ maxUnavailable: number | string;
102
+ };
103
+ type: "RollingUpdate";
104
+ };
105
+ export type KubernetesWorkerDef = {
106
+ enabled: boolean;
107
+ /**
108
+ * which command to run. defaults to `yarn start`
109
+ */
110
+ command?: string;
111
+ resources?: KubernetesResourcesDef;
112
+ };
72
113
  export type DeployConfigKubernetesValues = AllowUnknownProps<{
73
114
  /**
74
115
  * enable cloudsql db. Currently you have to manually set it up
@@ -121,6 +162,10 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
121
162
  * redirects
122
163
  */
123
164
  redirects?: AllowUnknownProps<{ host: string }>[];
165
+ /**
166
+ * Host aliases
167
+ */
168
+ hostAliases?: string[];
124
169
  /**
125
170
  * how many pods will be started
126
171
  */
@@ -130,23 +175,27 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
130
175
  * autoscale the pods horizontally
131
176
  */
132
177
  autoscale?: KubernetesAutoscale;
178
+
179
+ /**
180
+ * the update strategy, see https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment
181
+ */
182
+ updateStrategy?: KubernetesUpdateStrategy;
183
+
133
184
  /**
134
185
  * kubernetes resources
135
186
  */
136
- resources?: {
137
- limits?: {
138
- cpu?: string;
139
- memory?: string;
140
- };
141
- requests?: {
142
- cpu?: string;
143
- memory?: string;
144
- };
145
- };
187
+
188
+ resources?: KubernetesResourcesDef;
146
189
  healthRoute?: string;
147
190
  startupProbe?: KubernetesHealthDef;
148
191
  readinessProbe?: KubernetesHealthDef;
149
192
  livenessProbe?: KubernetesHealthDef;
193
+ /**
194
+ * specify a worker. A worker is a separate deployment that runs continously in the background.
195
+ * The worker pod can use the same entry point as the app or a different one (specify command).
196
+ * It has the same environment variables as the application and an additional IS_WORKER="true" variable
197
+ */
198
+ worker?: KubernetesWorkerDef;
150
199
  }>;
151
200
  /**
152
201
  * Mount secrets as files in the filesystem.
@@ -172,7 +221,7 @@ export type DeployConfigKubernetes = {
172
221
  values?: DeployConfigKubernetesValues;
173
222
  } & DeployConfigBase;
174
223
 
175
- type DeployConfigCustom = {
224
+ export type DeployConfigCustom = {
176
225
  type: "custom";
177
226
  requiresDocker: boolean;
178
227
  script: string[];
@@ -3,9 +3,9 @@ import { RULES_ALWAYS } from "../rules";
3
3
  import { getRunnerImage } from "../runner";
4
4
  import { GitlabPipeline, Pipeline, PipelineJob, PipelineType } from "../types";
5
5
  import { Config, PipelineTrigger } from "../types/config";
6
+ import { BASE_STAGES } from "../types/jobs";
6
7
  import { createJobs } from "./createJobs";
7
8
 
8
- const baseStages = ["setup", "test", "build", "deploy", "verify", "stop"];
9
9
  export const createChildPipeline = async <T extends PipelineType>(
10
10
  type: T,
11
11
  trigger: PipelineTrigger,
@@ -30,7 +30,7 @@ export const createChildPipeline = async <T extends PipelineType>(
30
30
  // this is just so that it looks nicer in gitlab and makes running mutliple manual tasks more easy to use
31
31
 
32
32
  const allEnvs = getAllEnvsInAllComponents(config);
33
- const stages = baseStages.reduce<string[]>(
33
+ const stages = BASE_STAGES.reduce<string[]>(
34
34
  (acc, baseStage) => [
35
35
  ...acc,
36
36
  baseStage,
@@ -77,22 +77,33 @@ const replaceReferences = (
77
77
  ): CatladderJob<string> => {
78
78
  const stage =
79
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
+ ];
80
103
  return {
81
104
  ...job,
82
105
  stage,
83
- needs: job.needs?.map((n) =>
84
- isObject(n)
85
- ? {
86
- job: getFullReferencedJobName(
87
- n.job,
88
- componentName,
89
- env,
90
- allRawJobs
91
- ),
92
- artifacts: n.artifacts,
93
- }
94
- : getFullReferencedJobName(n, componentName, env, allRawJobs)
95
- ),
106
+ needs,
96
107
  environment: job.environment?.on_stop
97
108
  ? {
98
109
  ...job.environment,
@@ -5,6 +5,7 @@ import { CatladderJob } from "../../types/jobs";
5
5
  export const makeGitlabJob = ({
6
6
  envMode,
7
7
  needsStages,
8
+ needsOtherComponent,
8
9
  name,
9
10
  ...rest
10
11
  }: CatladderJob<string>): GitlabJobDef => {
@@ -27,7 +27,7 @@ export type GitlabEnvironment = {
27
27
  kubernetes?: {
28
28
  namespace?: string;
29
29
  };
30
- action?: "stop" | "start" | "prepare"; // defaults to start
30
+ action?: "stop" | "start" | "prepare" | "access"; // defaults to start
31
31
  on_stop?: string; // other job to run on stop
32
32
  auto_stop_in?: string;
33
33
  };
package/src/types/jobs.ts CHANGED
@@ -13,6 +13,7 @@ export const BASE_STAGES = [
13
13
  "build",
14
14
  "deploy",
15
15
  "verify",
16
+ "rollback",
16
17
  "stop",
17
18
  ] as const;
18
19
  export type BaseStage = typeof BASE_STAGES[number];
@@ -49,9 +50,15 @@ export type CatladderJob<S = BaseStage> = {
49
50
  }[];
50
51
 
51
52
  /**
52
- * does this require another job?
53
+ * does this require another job (from the same component)?
53
54
  */
54
55
  needs?: Array<string | { job: string; artifacts: boolean }>;
56
+
57
+ needsOtherComponent?: Array<{
58
+ componentName: string;
59
+ job: string;
60
+ artifacts: boolean;
61
+ }>;
55
62
  /**
56
63
  * cache config, we use here the same shape as gitlab itself
57
64
  */