@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-refactor-env-context-9e652b63

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 (175) hide show
  1. package/bin/catladder-gitlab.js +1 -1
  2. package/dist/build/base/createBuildJob.d.ts +2 -2
  3. package/dist/build/base/getBuildInfo.d.ts +1 -1
  4. package/dist/build/docker.d.ts +44 -6
  5. package/dist/build/docker.js +45 -19
  6. package/dist/build/index.d.ts +6 -5
  7. package/dist/build/node/buildJob.d.ts +2 -2
  8. package/dist/build/node/cache.d.ts +2 -2
  9. package/dist/build/node/index.d.ts +1 -1
  10. package/dist/build/node/meteor.d.ts +1 -1
  11. package/dist/build/node/meteor.js +6 -0
  12. package/dist/build/node/testJob.d.ts +2 -2
  13. package/dist/build/node/testJob.js +3 -0
  14. package/dist/build/node/yarn.d.ts +1 -1
  15. package/dist/build/node/yarn.js +13 -1
  16. package/dist/build/types.d.ts +10 -0
  17. package/dist/bundles/catladder-gitlab/index.js +32457 -0
  18. package/dist/catladder-gitlab.js +1 -2
  19. package/dist/config/configruedEnvs.d.ts +1 -1
  20. package/dist/config/readConfig.d.ts +1 -1
  21. package/dist/constants.js +1 -1
  22. package/dist/context/getEnvConfig.d.ts +9 -0
  23. package/dist/context/getEnvConfig.js +26 -0
  24. package/dist/context/getEnvType.d.ts +4 -0
  25. package/dist/context/getEnvType.js +18 -0
  26. package/dist/context/getEnvironment.d.ts +3 -0
  27. package/dist/context/getEnvironment.js +187 -0
  28. package/dist/context/getEnvironmentContext.d.ts +4 -0
  29. package/dist/context/getEnvironmentContext.js +36 -0
  30. package/dist/context/getEnvironmentVariables.d.ts +10 -0
  31. package/dist/context/getEnvironmentVariables.js +322 -0
  32. package/dist/context/getLabels.d.ts +8 -0
  33. package/dist/context/getLabels.js +49 -0
  34. package/dist/context/index.d.ts +5 -6
  35. package/dist/context/index.js +176 -181
  36. package/dist/context/resolveReferences.d.ts +1 -3
  37. package/dist/context/resolveReferences.js +275 -26
  38. package/dist/context/resolveReferences.test.js +332 -81
  39. package/dist/defaults/index.d.ts +1 -1
  40. package/dist/deploy/base.d.ts +4 -2
  41. package/dist/deploy/base.js +37 -17
  42. package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
  43. package/dist/deploy/cloudRun/deployJob.js +139 -0
  44. package/dist/deploy/cloudRun/index.d.ts +9 -0
  45. package/dist/deploy/cloudRun/index.js +56 -0
  46. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
  47. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +14 -0
  48. package/dist/deploy/cloudSql/index.d.ts +8 -0
  49. package/dist/deploy/cloudSql/index.js +30 -0
  50. package/dist/deploy/custom/deployJob.d.ts +2 -2
  51. package/dist/deploy/custom/deployJob.js +4 -1
  52. package/dist/deploy/custom/index.d.ts +2 -1
  53. package/dist/deploy/custom/index.js +15 -18
  54. package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
  55. package/dist/deploy/dockerTag/deployJob.js +33 -0
  56. package/dist/deploy/dockerTag/index.d.ts +2 -0
  57. package/dist/deploy/dockerTag/index.js +19 -0
  58. package/dist/deploy/index.d.ts +12 -8
  59. package/dist/deploy/index.js +27 -14
  60. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
  61. package/dist/deploy/kubernetes/additionalSecretKeys.js +33 -0
  62. package/dist/deploy/kubernetes/cloudsql.d.ts +1 -1
  63. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  64. package/dist/deploy/kubernetes/deployJob.js +13 -66
  65. package/dist/deploy/kubernetes/index.d.ts +2 -1
  66. package/dist/deploy/kubernetes/index.js +45 -16
  67. package/dist/deploy/kubernetes/kubeEnv.d.ts +10 -0
  68. package/dist/deploy/kubernetes/kubeEnv.js +90 -0
  69. package/dist/deploy/kubernetes/kubeValues.d.ts +90 -0
  70. package/dist/deploy/kubernetes/kubeValues.js +96 -0
  71. package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
  72. package/dist/deploy/kubernetes/mongodb.js +118 -8
  73. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +21 -21
  74. package/dist/deploy/types/base.d.ts +15 -0
  75. package/dist/deploy/types/base.js +3 -0
  76. package/dist/deploy/types/custom.d.ts +27 -0
  77. package/dist/deploy/types/custom.js +3 -0
  78. package/dist/deploy/types/dockerTag.d.ts +10 -0
  79. package/dist/deploy/types/dockerTag.js +3 -0
  80. package/dist/deploy/types/googleCloudRun.d.ts +39 -0
  81. package/dist/deploy/types/googleCloudRun.js +3 -0
  82. package/dist/deploy/types/index.d.ts +24 -0
  83. package/dist/deploy/types/index.js +41 -0
  84. package/dist/deploy/{types.d.ts → types/kubernetes.d.ts} +128 -36
  85. package/dist/deploy/types/kubernetes.js +3 -0
  86. package/dist/deploy/utils.d.ts +2 -2
  87. package/dist/deploy/utils.js +4 -0
  88. package/dist/pipeline/createChildPipeline.d.ts +2 -2
  89. package/dist/pipeline/createChildPipeline.js +3 -3
  90. package/dist/pipeline/createJobs.d.ts +2 -2
  91. package/dist/pipeline/createJobs.js +63 -25
  92. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +3 -2
  93. package/dist/pipeline/gitlab/makeGitlabJob.js +2 -1
  94. package/dist/pipeline/packageManager.d.ts +1 -1
  95. package/dist/rules/index.d.ts +1 -1
  96. package/dist/runner/index.d.ts +2 -3
  97. package/dist/tsconfig.tsbuildinfo +1 -1
  98. package/dist/types/config.d.ts +7 -6
  99. package/dist/types/config.js +1 -1
  100. package/dist/types/context.d.ts +10 -2
  101. package/dist/types/environmentContext.d.ts +22 -0
  102. package/dist/types/environmentContext.js +3 -0
  103. package/dist/types/gitlab-types.d.ts +1 -1
  104. package/dist/types/jobs.d.ts +8 -3
  105. package/dist/types/jobs.js +1 -1
  106. package/dist/types/pipeline.d.ts +1 -1
  107. package/package.json +15 -11
  108. package/scripts/bundle +2 -0
  109. package/src/build/base/createBuildJob.ts +3 -2
  110. package/src/build/base/getBuildInfo.ts +1 -1
  111. package/src/build/docker.ts +47 -29
  112. package/src/build/index.ts +8 -5
  113. package/src/build/node/buildJob.ts +2 -2
  114. package/src/build/node/cache.ts +2 -2
  115. package/src/build/node/index.ts +1 -1
  116. package/src/build/node/meteor.ts +8 -2
  117. package/src/build/node/testJob.ts +4 -2
  118. package/src/build/node/yarn.ts +21 -10
  119. package/src/build/tests/storybook.test.ts +1 -1
  120. package/src/build/types.ts +13 -1
  121. package/src/catladder-gitlab.ts +4 -2
  122. package/src/config/configruedEnvs.test.ts +2 -2
  123. package/src/config/configruedEnvs.ts +5 -4
  124. package/src/config/readConfig.ts +1 -1
  125. package/src/context/getEnvConfig.ts +21 -0
  126. package/src/context/getEnvType.ts +17 -0
  127. package/src/context/getEnvironment.ts +40 -0
  128. package/src/context/getEnvironmentContext.ts +57 -0
  129. package/src/context/getEnvironmentVariables.ts +152 -0
  130. package/src/context/getLabels.ts +20 -0
  131. package/src/context/index.ts +25 -191
  132. package/src/context/resolveReferences.test.ts +15 -15
  133. package/src/context/resolveReferences.ts +37 -30
  134. package/src/defaults/index.ts +1 -1
  135. package/src/deploy/base.ts +43 -19
  136. package/src/deploy/cloudRun/deployJob.ts +104 -0
  137. package/src/deploy/cloudRun/index.ts +48 -0
  138. package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
  139. package/src/deploy/cloudSql/index.ts +16 -0
  140. package/src/deploy/custom/deployJob.ts +10 -3
  141. package/src/deploy/custom/index.ts +9 -1
  142. package/src/deploy/dockerTag/deployJob.ts +31 -0
  143. package/src/deploy/dockerTag/index.ts +9 -0
  144. package/src/deploy/index.ts +26 -17
  145. package/src/deploy/kubernetes/additionalSecretKeys.ts +23 -0
  146. package/src/deploy/kubernetes/cloudsql.ts +2 -1
  147. package/src/deploy/kubernetes/deployJob.ts +19 -77
  148. package/src/deploy/kubernetes/index.ts +42 -1
  149. package/src/deploy/kubernetes/kubeEnv.ts +48 -0
  150. package/src/deploy/kubernetes/kubeValues.ts +82 -0
  151. package/src/deploy/kubernetes/mongodb.ts +104 -7
  152. package/src/deploy/kubernetes/processSecretsAsFiles.ts +1 -1
  153. package/src/deploy/types/base.ts +17 -0
  154. package/src/deploy/types/custom.ts +24 -0
  155. package/src/deploy/types/dockerTag.ts +12 -0
  156. package/src/deploy/types/googleCloudRun.ts +79 -0
  157. package/src/deploy/types/index.ts +28 -0
  158. package/src/deploy/types/kubernetes.ts +281 -0
  159. package/src/deploy/utils.ts +6 -2
  160. package/src/pipeline/createChildPipeline.test.ts +1 -1
  161. package/src/pipeline/createChildPipeline.ts +4 -4
  162. package/src/pipeline/createJobs.ts +32 -21
  163. package/src/pipeline/gitlab/makeGitlabJob.ts +3 -2
  164. package/src/pipeline/packageManager.ts +1 -1
  165. package/src/rules/index.ts +1 -1
  166. package/src/runner/index.ts +2 -1
  167. package/src/types/config.ts +8 -6
  168. package/src/types/context.ts +14 -2
  169. package/src/types/environmentContext.ts +26 -0
  170. package/src/types/gitlab-types.ts +1 -1
  171. package/src/types/jobs.ts +9 -2
  172. package/src/types/pipeline.ts +1 -1
  173. package/tsconfig.json +2 -0
  174. package/dist/deploy/types.js +0 -16
  175. package/src/deploy/types.ts +0 -189
@@ -1,11 +1,23 @@
1
- import { PipelineTrigger, ComponentConfig, Config, EnvType } from "./config";
1
+ import type {
2
+ PipelineTrigger,
3
+ ComponentConfig,
4
+ Config,
5
+ EnvType,
6
+ } from "./config";
2
7
 
3
8
  export type Environment = {
4
9
  host: string;
10
+ url: string;
11
+ /**
12
+ * the full name of the app. We use this as RELEASE_NAME in kubernetes and the service name in google cloud run
13
+ */
5
14
  fullName: string;
15
+ gitlabEnvironment: {
16
+ name: string;
17
+ url: string;
18
+ };
6
19
  shortName: string;
7
20
  slug: string;
8
- url: string;
9
21
  /**
10
22
  * env vars contain all build-time env vars. secrets have to be resolved (they are stored in gitlab)
11
23
  */
@@ -0,0 +1,26 @@
1
+ import type { BuildConfigGeneric, BuildConfigType } from "../build";
2
+ import type { DeployConfigGeneric } from "../deploy";
3
+ import type { DeployConfigType } from "../deploy";
4
+ import type { Config, EnvConfigWithComponent, EnvType } from "./config";
5
+ import type { CommitInfo } from "./context";
6
+
7
+ export type EnvironmentContext<
8
+ B extends BuildConfigType,
9
+ D extends DeployConfigType
10
+ > = {
11
+ envConfigRaw: EnvConfigWithComponent;
12
+ buildConfigRaw: false | BuildConfigGeneric<B>;
13
+ deployConfigRaw: false | DeployConfigGeneric<D>;
14
+ commitInfo?: CommitInfo;
15
+ env: string;
16
+ envType: EnvType;
17
+ componentName: string;
18
+ fullName: string;
19
+ environmentSlug: string;
20
+ gitlabEnvironmentName: string;
21
+
22
+ /**
23
+ * the full catladder config
24
+ */
25
+ fullConfig: Config;
26
+ };
@@ -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
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  Artifacts,
3
3
  GitlabEnvironment,
4
4
  GitlabJobCache,
@@ -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
  */
@@ -1,4 +1,4 @@
1
- import { GitlabJobDef, GitlabPipeline } from "./gitlab-types";
1
+ import type { GitlabJobDef, GitlabPipeline } from "./gitlab-types";
2
2
 
3
3
  export type PipelineType = "gitlab";
4
4
 
package/tsconfig.json CHANGED
@@ -2,9 +2,11 @@
2
2
  "compilerOptions": {
3
3
  "lib": ["es2020", "DOM"],
4
4
  "strict": true,
5
+ "module": "CommonJS",
5
6
  "downlevelIteration": true,
6
7
  "declaration": true,
7
8
  "outDir": "dist",
9
+ "moduleResolution": "node",
8
10
  "esModuleInterop": true,
9
11
  "incremental": true
10
12
  },
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.isOfDeployType = void 0;
5
-
6
- var isOfDeployType = function (t) {
7
- var types = [];
8
-
9
- for (var _i = 1; _i < arguments.length; _i++) {
10
- types[_i - 1] = arguments[_i];
11
- }
12
-
13
- return t && types.includes(t.type);
14
- };
15
-
16
- exports.isOfDeployType = isOfDeployType;
@@ -1,189 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-types
2
- export type DeployConfigBase = {
3
- /**
4
- * whether to deploy automatically or manual. If not defined, these rules apply:
5
- * - prod: manual
6
- * - all other envs: auto
7
- */
8
- when?: "manual" | "auto";
9
- };
10
- type AllowUnknownProps<T extends Record<string, unknown>> = T &
11
- Record<string, unknown>;
12
-
13
- export type DeployConfigKubernetesClusterGCloud = {
14
- type: "gcloud";
15
- /**
16
- * gcoud name of the cluster
17
- */
18
- name: string;
19
- /**
20
- * google cloud project id
21
- */
22
- projectId: string;
23
- /**
24
- * region
25
- */
26
- region: string;
27
- /**
28
- * domain of the cluster, for canonical domains without custom host (e.g. review and dev apps)
29
- */
30
- domainCanonical?: string;
31
- };
32
- export type DeployConfigKubernetesCluster = DeployConfigKubernetesClusterGCloud; // currently only this
33
-
34
- export type KubernetesAutoscaleMetricResourceTarget =
35
- | {
36
- type: "Utilization";
37
- averageUtilization: number;
38
- }
39
- | {
40
- type: "AverageValue";
41
- averageValue: number | string;
42
- };
43
- export type KubernetesAutoscaleMetric = {
44
- type: "Resource";
45
- resource: {
46
- name: "cpu" | "memory";
47
- target: KubernetesAutoscaleMetricResourceTarget;
48
- };
49
- };
50
- export type KubernetesAutoscale = {
51
- minReplicas: number;
52
- maxReplicas: number;
53
- /**
54
- * declare a number of metrics (at least one). Usually you would use cpu as a metric
55
- */
56
- metrics: KubernetesAutoscaleMetric[];
57
- };
58
- type KubernetesHealthDef = {
59
- httpGet?: {
60
- path?: string;
61
- port?: number;
62
- httpHeaders?: {
63
- name: string;
64
- value: string;
65
- }[];
66
- failureThreshold?: number;
67
- timeoutSeconds?: number;
68
- periodSeconds?: number;
69
- successThreshold?: number;
70
- };
71
- };
72
- export type DeployConfigKubernetesValues = AllowUnknownProps<{
73
- /**
74
- * enable cloudsql db. Currently you have to manually set it up
75
- */
76
- cloudsql?: {
77
- enabled: boolean;
78
- instanceId?: string;
79
- projectId?: string;
80
- region?: string;
81
- };
82
- /**
83
- * enable mongodb. The mongodb is deployed using a helm chart.
84
- * Consider using external services instead of this.
85
- */
86
- mongodb?: AllowUnknownProps<{
87
- enabled: boolean;
88
- }>;
89
- /**
90
- * enable mailhog. Mailhog is a virtual mail server that catches all outgoing mailsl and show them in a mailbox.
91
- * This is great for development as it prevents to accidentially send out real emails and helps with debugging outgoing mails.
92
- *
93
- * It will automaticaly inject a MAIL_URL env var.
94
- *
95
- * Turn it of for production.
96
- */
97
- mailhog?: {
98
- enabled: boolean;
99
- };
100
- /**
101
- * post-install/upgrade jobs. These use the app image and have all env vars available.
102
- * Typically used for migrations and seeds
103
- */
104
- jobs?: Record<string, AllowUnknownProps<{ command: string }>>;
105
- /**
106
- * cronjobs that run periodically. These use the app image have all env vars available.
107
- */
108
- cronjobs?: Record<
109
- string,
110
- AllowUnknownProps<{
111
- schedule: string;
112
- command: string;
113
- concurrencyPolicy?: "Forbid" | "Allow" | "Replace";
114
- }>
115
- >;
116
- /**
117
- * configuration for the application ("Deployment" in kubernetes)
118
- */
119
- application?: AllowUnknownProps<{
120
- /**
121
- * redirects
122
- */
123
- redirects?: AllowUnknownProps<{ host: string }>[];
124
- /**
125
- * how many pods will be started
126
- */
127
- replicas?: number;
128
-
129
- /**
130
- * autoscale the pods horizontally
131
- */
132
- autoscale?: KubernetesAutoscale;
133
- /**
134
- * kubernetes resources
135
- */
136
- resources?: {
137
- limits?: {
138
- cpu?: string;
139
- memory?: string;
140
- };
141
- requests?: {
142
- cpu?: string;
143
- memory?: string;
144
- };
145
- };
146
- healthRoute?: string;
147
- startupProbe?: KubernetesHealthDef;
148
- readinessProbe?: KubernetesHealthDef;
149
- livenessProbe?: KubernetesHealthDef;
150
- }>;
151
- /**
152
- * Mount secrets as files in the filesystem.
153
- * These secrets are still available as env vars, but will contain the path of the file instead
154
- */
155
- secretsAsFile?: string[];
156
- }>;
157
-
158
- export type DeployConfigKubernetes = {
159
- type: "kubernetes";
160
- /**
161
- * cluster config to use.
162
- */
163
- cluster: DeployConfigKubernetesCluster;
164
- /**
165
- * prints out debug info (helm --debug)
166
- */
167
- debug?: boolean;
168
- additionalHelmArgs?: string[];
169
- /**
170
- * values to configure the app
171
- */
172
- values?: DeployConfigKubernetesValues;
173
- } & DeployConfigBase;
174
-
175
- type DeployConfigCustom = {
176
- type: "custom";
177
- requiresDocker: boolean;
178
- script: string[];
179
- stopScript?: string[];
180
- } & DeployConfigBase;
181
-
182
- export type DeployConfig = DeployConfigKubernetes | DeployConfigCustom;
183
-
184
- export const isOfDeployType = <T extends Array<DeployConfig["type"]>>(
185
- t: DeployConfig | false,
186
- ...types: T
187
- ): t is Extract<DeployConfig, { type: T[number] }> => {
188
- return t && types.includes(t.type);
189
- };