@catladder/pipeline 1.170.0 → 2.0.0

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 (194) hide show
  1. package/dist/bash/BashExpression.d.ts +2 -6
  2. package/dist/bash/BashExpression.js +5 -15
  3. package/dist/bash/bashEscape.d.ts +34 -0
  4. package/dist/bash/bashEscape.js +114 -0
  5. package/dist/bash/bashYaml.js +25 -2
  6. package/dist/bash/getInjectVarsScript.js +4 -2
  7. package/dist/bash/index.d.ts +2 -0
  8. package/dist/bash/index.js +26 -0
  9. package/dist/build/base/createAppBuildJob.js +3 -3
  10. package/dist/build/base/writeDotEnv.js +6 -4
  11. package/dist/build/custom/testJob.js +12 -12
  12. package/dist/build/docker.d.ts +3 -3
  13. package/dist/build/node/buildJob.js +1 -1
  14. package/dist/build/node/cache.d.ts +2 -4
  15. package/dist/build/node/cache.js +3 -24
  16. package/dist/build/node/testJob.js +11 -11
  17. package/dist/build/rails/build.js +1 -1
  18. package/dist/build/rails/test.js +8 -8
  19. package/dist/build/types.d.ts +0 -10
  20. package/dist/constants.js +1 -1
  21. package/dist/context/createComponentContext.js +0 -1
  22. package/dist/context/getEnvConfig.js +2 -1
  23. package/dist/context/getEnvironment.js +1 -2
  24. package/dist/context/getEnvironmentVariables.d.ts +5 -6
  25. package/dist/context/getEnvironmentVariables.js +50 -38
  26. package/dist/deploy/base/deploy.js +3 -3
  27. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +2 -2
  28. package/dist/deploy/cloudRun/index.js +2 -2
  29. package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
  30. package/dist/deploy/kubernetes/cloudSql/index.d.ts +2 -2
  31. package/dist/deploy/kubernetes/cloudSql/index.js +3 -14
  32. package/dist/deploy/kubernetes/deployJob.js +1 -3
  33. package/dist/deploy/kubernetes/index.js +2 -2
  34. package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -3
  35. package/dist/deploy/kubernetes/kubeValues.d.ts +3 -4
  36. package/dist/deploy/kubernetes/kubeValues.js +2 -3
  37. package/dist/deploy/types/base.d.ts +0 -6
  38. package/dist/deploy/types/kubernetes.d.ts +1 -34
  39. package/dist/globalScriptFunctions/index.d.ts +14 -0
  40. package/dist/globalScriptFunctions/index.js +37 -0
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.js +3 -1
  43. package/dist/pipeline/gitlab/createGitlabJobs.js +3 -5
  44. package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +1 -0
  45. package/dist/pipeline/gitlab/createGitlabPipeline.js +38 -2
  46. package/dist/pipeline/packageManager.js +1 -1
  47. package/dist/runner/index.d.ts +1 -1
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/dist/types/config.d.ts +6 -9
  50. package/dist/types/context.d.ts +2 -9
  51. package/dist/types/gitlab-types.d.ts +1 -0
  52. package/dist/types/jobs.d.ts +0 -8
  53. package/dist/utils/gitlab.js +4 -1
  54. package/dist/utils/writeFiles.js +1 -7
  55. package/dist/variables/VariableValue.d.ts +3 -0
  56. package/dist/variables/VariableValue.js +5 -0
  57. package/dist/variables/VariableValueContainingReferences.d.ts +24 -0
  58. package/dist/variables/VariableValueContainingReferences.js +97 -0
  59. package/dist/variables/__tests__/resolveAllReferences.test.js +219 -0
  60. package/dist/variables/__tests__/resolveAllReferencesOnce.test.d.ts +1 -0
  61. package/dist/variables/__tests__/resolveAllReferencesOnce.test.js +171 -0
  62. package/dist/variables/__tests__/resolveReferencesOnce.test.d.ts +1 -0
  63. package/dist/variables/__tests__/resolveReferencesOnce.test.js +202 -0
  64. package/dist/variables/__tests__/variableValue.test.d.ts +1 -0
  65. package/dist/variables/__tests__/variableValue.test.js +36 -0
  66. package/dist/variables/resolveAllReferences.d.ts +3 -0
  67. package/dist/{bash/replaceAsync.js → variables/resolveAllReferences.js} +60 -41
  68. package/dist/variables/resolveAllReferencesOnce.d.ts +5 -0
  69. package/dist/variables/resolveAllReferencesOnce.js +191 -0
  70. package/dist/variables/resolveReferencesOnce.d.ts +8 -0
  71. package/dist/variables/resolveReferencesOnce.js +22 -0
  72. package/examples/__snapshots__/cloud-run-http2.test.ts.snap +312 -238
  73. package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +312 -238
  74. package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +312 -222
  75. package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +1436 -0
  76. package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +312 -238
  77. package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +316 -238
  78. package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +312 -238
  79. package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +313 -238
  80. package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +312 -238
  81. package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +312 -238
  82. package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +312 -238
  83. package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +312 -238
  84. package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +316 -238
  85. package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +294 -220
  86. package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +312 -238
  87. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +652 -486
  88. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +282 -288
  89. package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +312 -238
  90. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +284 -194
  91. package/examples/__snapshots__/custom-build-job.test.ts.snap +278 -188
  92. package/examples/__snapshots__/custom-deploy.test.ts.snap +220 -154
  93. package/examples/__snapshots__/custom-envs.test.ts.snap +216 -126
  94. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +278 -188
  95. package/examples/__snapshots__/git-submodule.test.ts.snap +312 -238
  96. package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +231 -253
  97. package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +240 -262
  98. package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +504 -506
  99. package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +239 -261
  100. package/examples/__snapshots__/local-dot-env.test.ts.snap +236 -238
  101. package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +236 -242
  102. package/examples/__snapshots__/multiline-var.test.ts.snap +1355 -973
  103. package/examples/__snapshots__/native-app.test.ts.snap +438 -392
  104. package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +312 -238
  105. package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +312 -238
  106. package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +186 -188
  107. package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +162 -164
  108. package/examples/__snapshots__/referencing-other-vars.test.ts.snap +4741 -0
  109. package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +330 -228
  110. package/examples/__snapshots__/{workspace-api-www-custom-cache.test.ts.snap → workspace-api-www-turbo-cache.test.ts.snap} +457 -499
  111. package/examples/__snapshots__/workspace-api-www.test.ts.snap +452 -482
  112. package/examples/{workspace-api-www-custom-cache.test.ts → cloud-run-nextjs.test.ts} +2 -2
  113. package/examples/cloud-run-nextjs.ts +28 -0
  114. package/examples/cloud-run-with-sql.ts +0 -1
  115. package/examples/kubernetes-application-customization.ts +1 -0
  116. package/examples/kubernetes-with-cloud-sql.ts +1 -0
  117. package/examples/kubernetes-with-jobs.ts +1 -0
  118. package/examples/kubernetes-with-mongodb.ts +1 -0
  119. package/examples/meteor-kubernetes.ts +1 -1
  120. package/examples/native-app.ts +10 -7
  121. package/examples/rails-k8s-with-worker.ts +7 -1
  122. package/examples/{kubernetes-with-cloud-sql-legacy.test.ts → referencing-other-vars.test.ts} +2 -2
  123. package/examples/referencing-other-vars.ts +83 -0
  124. package/examples/workspace-api-www-turbo-cache.test.ts +11 -0
  125. package/examples/{workspace-api-www-custom-cache.ts → workspace-api-www-turbo-cache.ts} +4 -3
  126. package/examples/workspace-api-www.ts +3 -2
  127. package/package.json +2 -6
  128. package/src/bash/BashExpression.ts +10 -13
  129. package/src/bash/bashEscape.ts +158 -0
  130. package/src/bash/bashYaml.ts +36 -2
  131. package/src/bash/getInjectVarsScript.ts +11 -2
  132. package/src/bash/index.ts +2 -0
  133. package/src/build/base/createAppBuildJob.ts +0 -1
  134. package/src/build/base/writeDotEnv.ts +6 -6
  135. package/src/build/custom/testJob.ts +0 -1
  136. package/src/build/node/buildJob.ts +2 -2
  137. package/src/build/node/cache.ts +0 -29
  138. package/src/build/node/testJob.ts +0 -1
  139. package/src/build/rails/build.ts +0 -1
  140. package/src/build/rails/test.ts +0 -1
  141. package/src/build/types.ts +0 -13
  142. package/src/context/createComponentContext.ts +0 -1
  143. package/src/context/getEnvConfig.ts +2 -2
  144. package/src/context/getEnvironment.ts +1 -1
  145. package/src/context/getEnvironmentContext.ts +1 -1
  146. package/src/context/getEnvironmentVariables.ts +44 -51
  147. package/src/deploy/base/deploy.ts +1 -1
  148. package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +4 -12
  149. package/src/deploy/cloudRun/index.ts +2 -2
  150. package/src/deploy/kubernetes/cloudSql/index.ts +3 -16
  151. package/src/deploy/kubernetes/deployJob.ts +0 -2
  152. package/src/deploy/kubernetes/index.ts +2 -2
  153. package/src/deploy/kubernetes/kubeEnv.ts +3 -3
  154. package/src/deploy/kubernetes/kubeValues.ts +5 -8
  155. package/src/deploy/types/base.ts +0 -6
  156. package/src/deploy/types/kubernetes.ts +1 -36
  157. package/src/globalScriptFunctions/index.ts +30 -0
  158. package/src/index.ts +2 -0
  159. package/src/pipeline/gitlab/createGitlabJobs.ts +1 -4
  160. package/src/pipeline/gitlab/createGitlabPipeline.ts +8 -1
  161. package/src/pipeline/packageManager.ts +7 -5
  162. package/src/runner/index.ts +0 -1
  163. package/src/types/config.ts +6 -9
  164. package/src/types/context.ts +3 -9
  165. package/src/types/gitlab-types.ts +1 -0
  166. package/src/types/jobs.ts +0 -8
  167. package/src/utils/gitlab.ts +19 -2
  168. package/src/utils/writeFiles.ts +1 -2
  169. package/src/variables/VariableValue.ts +6 -0
  170. package/src/variables/VariableValueContainingReferences.ts +89 -0
  171. package/src/variables/__tests__/resolveAllReferences.test.ts +110 -0
  172. package/src/variables/__tests__/resolveAllReferencesOnce.test.ts +64 -0
  173. package/src/variables/__tests__/resolveReferencesOnce.test.ts +117 -0
  174. package/src/variables/__tests__/variableValue.test.ts +73 -0
  175. package/src/variables/resolveAllReferences.ts +46 -0
  176. package/src/variables/resolveAllReferencesOnce.ts +44 -0
  177. package/src/variables/resolveReferencesOnce.ts +29 -0
  178. package/bin/catladder-gitlab-dev.js +0 -3
  179. package/bin/catladder-gitlab.js +0 -3
  180. package/dist/bash/replaceAsync.d.ts +0 -2
  181. package/dist/bundles/catladder-gitlab/index.js +0 -15
  182. package/dist/context/__tests__/resolveReferences.test.js +0 -368
  183. package/dist/context/resolveReferences.d.ts +0 -6
  184. package/dist/context/resolveReferences.js +0 -286
  185. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +0 -85
  186. package/dist/deploy/kubernetes/processSecretsAsFiles.js +0 -33
  187. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.test.ts.snap +0 -1795
  188. package/examples/kubernetes-with-cloud-sql-legacy.ts +0 -35
  189. package/scripts/bundle +0 -2
  190. package/src/bash/replaceAsync.ts +0 -54
  191. package/src/context/__tests__/resolveReferences.test.ts +0 -148
  192. package/src/context/resolveReferences.ts +0 -93
  193. package/src/deploy/kubernetes/processSecretsAsFiles.ts +0 -35
  194. /package/dist/{context/__tests__/resolveReferences.test.d.ts → variables/__tests__/resolveAllReferences.test.d.ts} +0 -0
@@ -31,7 +31,6 @@ export const createCustomTestJobs = (
31
31
  variables: {
32
32
  APP_PATH: context.build.dir,
33
33
  ...context.environment.jobOnlyVars.build.envVars,
34
- ...(buildConfig.extraVars ?? {}),
35
34
  },
36
35
  runnerVariables: RUNNER_CUSTOM_TEST_VARIABLES,
37
36
  services: buildConfig.jobServices,
@@ -15,7 +15,7 @@ import { createComponentBuildJobs, createWorkspaceBuildJobs } from "../base";
15
15
  import { createBuildJobDefinition } from "../base/createBuildJobDefinition";
16
16
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
17
17
  import type { BuildConfigDocker } from "../types";
18
- import { getNextCache, getNodeCache, getYarnCache } from "./cache";
18
+ import { getNodeCache, getYarnCache } from "./cache";
19
19
  import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
20
20
 
21
21
  export const createNodeBuildJobs = (
@@ -43,7 +43,7 @@ export const createNodeBuildJobDefinition = (
43
43
  const yarnInstall = getYarnInstall(context);
44
44
  return createBuildJobDefinition(context, buildConfig, {
45
45
  prescript: yarnInstall,
46
- cache: [...getNodeCache(context), ...getNextCache(context)],
46
+ cache: getNodeCache(context),
47
47
  });
48
48
  };
49
49
 
@@ -63,34 +63,5 @@ export const getNodeCache = (
63
63
  return [
64
64
  ...getYarnCache(context, policy),
65
65
  ...getNodeModulesCache(context, policy),
66
- ...(context.type === "workspace" ? getWorkspaceDefaultCaches(context) : []),
67
- ];
68
- };
69
-
70
- export const getNextCache = (context: Context): CacheConfig[] => {
71
- const paths = context.build
72
- .getComponentDirs("direct")
73
- .map((c) => join(c, ".next/cache"));
74
-
75
- return [
76
- {
77
- pathMode: "absolute",
78
- key: "next-cache",
79
- policy: "pull-push",
80
- paths,
81
- },
82
- ];
83
- };
84
-
85
- export const getWorkspaceDefaultCaches = (
86
- context: WorkspaceContext,
87
- ): CacheConfig[] => {
88
- return [
89
- {
90
- // turbo repo
91
- key: "turbo",
92
- policy: "pull-push",
93
- paths: [".turbo"],
94
- },
95
66
  ];
96
67
  };
@@ -35,7 +35,6 @@ export const createNodeTestJobs = (
35
35
  ...(context.type === "component"
36
36
  ? {
37
37
  ...context.environment.jobOnlyVars.build.envVars,
38
- ...(context.build.config.extraVars ?? {}),
39
38
  }
40
39
  : {}),
41
40
  },
@@ -47,7 +47,6 @@ export const createRailsBuildJobs = (
47
47
  dockerBuild: {
48
48
  variables: {
49
49
  ...context.environment.jobOnlyVars.build.envVars,
50
- ...context.build.config.extraVars,
51
50
  },
52
51
  // custom script
53
52
  script: [
@@ -24,7 +24,6 @@ export const createRailsTestJobs = (
24
24
  const base: Omit<CatladderJob, "script" | "name"> = {
25
25
  variables: {
26
26
  ...context.environment.jobOnlyVars.build.envVars,
27
- ...(buildConfig.extraVars ?? {}),
28
27
  },
29
28
  stage: "test",
30
29
  needs: [],
@@ -89,12 +89,6 @@ export type BuildConfigBase = {
89
89
  * Can curently not reference other variables from other components
90
90
  */
91
91
  jobVars?: EnvVars;
92
- /**
93
- * additional env vars for the buid jobs
94
- *
95
- * @deprecated use jobVars or runnerVariables
96
- */
97
- extraVars?: Record<string, string>;
98
92
 
99
93
  /**
100
94
  * additional vars only for the runner.
@@ -239,13 +233,6 @@ export type BuildConfigDocker =
239
233
  | BuildConfigDockerBuiltIn
240
234
  | BuildConfigDockerCustom;
241
235
 
242
- /**
243
- * @deprecated this type is no longer used. Use {@link BuildConfigDocker} instead.
244
- */
245
- export type BuildConfigCustomDocker =
246
- | BuildConfigDockerCustom
247
- | BuildConfigDockerBuiltInNgninx;
248
-
249
236
  export type BuildConfigCustom = Omit<
250
237
  BuildConfigBase,
251
238
  "lint" | "test" | "audit"
@@ -108,7 +108,6 @@ export const createComponentContext = async (
108
108
  const context: Omit<ComponentContext, "customJobs"> = {
109
109
  type: "component",
110
110
  name: ctx.componentName,
111
- componentName: ctx.componentName,
112
111
  env: ctx.env,
113
112
  fullConfig: ctx.config,
114
113
  componentConfig,
@@ -14,8 +14,8 @@ export const getEnvConfig = (
14
14
 
15
15
  const envCustomizations = defaultConfig.env?.[env] ?? {};
16
16
  if (envCustomizations === false) {
17
- throw new Error("env is disabled: " + env + ":" + componentName);
17
+ // env is disabled, still return the default config
18
+ return defaultConfig;
18
19
  }
19
-
20
20
  return mergeWithMergingArrays(defaultConfig, envCustomizations);
21
21
  };
@@ -20,7 +20,7 @@ export const getEnvironment = async (
20
20
  slugPrefix: envContext.environmentSlugPrefix,
21
21
  reviewSlug: envContext.reviewSlug,
22
22
  slug: envContext.environmentSlug,
23
- shortName: env,
23
+
24
24
  ...variables,
25
25
  };
26
26
  };
@@ -1,4 +1,4 @@
1
- import type { BuildConfig, CreateComponentContextContext } from "..";
1
+ import type { CreateComponentContextContext } from "..";
2
2
  import type { StringOrBashExpression } from "../bash/BashExpression";
3
3
  import { joinBashExpressions } from "../bash/BashExpression";
4
4
 
@@ -1,4 +1,3 @@
1
- import { merge } from "lodash";
2
1
  import { DEPLOY_TYPES } from "../deploy";
3
2
  import type {
4
3
  ComponentContext,
@@ -11,12 +10,10 @@ import type { StringOrBashExpression } from "../bash/BashExpression";
11
10
  import { joinBashExpressions } from "../bash/BashExpression";
12
11
  import { isStandaloneBuildConfig } from "../build/types";
13
12
  import type { EnvironmentContext } from "../types/environmentContext";
13
+ import { createVariableValueContainingReferencesFromString } from "../variables/VariableValueContainingReferences";
14
+ import { resolveAllReferences } from "../variables/resolveAllReferences";
14
15
  import { getBuildInfoVariables } from "./getBuildInfoVariables";
15
16
  import { getEnvironmentContext } from "./getEnvironmentContext";
16
- import {
17
- resolveReferences,
18
- translateLegacyFromComponents,
19
- } from "./resolveReferences";
20
17
  import { transformJobOnlyVars } from "./transformJobOnlyVars";
21
18
  import {
22
19
  makeSecretEnvVarMapping,
@@ -43,18 +40,15 @@ type BasePredefinedVariables = ReturnType<typeof getBasePredefinedVariables>;
43
40
 
44
41
  // we export so that we have later nice autocomplete
45
42
  export type PredefinedVariables = BasePredefinedVariables & {
46
- /**
47
- * undefined in rails, Rails before 6.1 (mis)uses the `HOST` environment variable to specify the IP to bind to
48
- */
49
- HOST?: StringOrBashExpression;
43
+ HOSTNAME?: StringOrBashExpression;
50
44
  ROOT_URL: StringOrBashExpression;
51
- HOST_INTERNAL: StringOrBashExpression;
45
+ HOSTNAME_INTERNAL: StringOrBashExpression;
52
46
  ROOT_URL_INTERNAL: StringOrBashExpression;
53
47
  };
54
48
 
55
49
  export const getEnvironmentVariables = async (
56
50
  ctx: CreateComponentContextContext,
57
- alreadyVisited: Record<string, Record<string, boolean>> = {}, // to prevent endless loop
51
+ options: { shouldResolveReferences?: boolean } = {},
58
52
  ): Promise<EnvironmentVariables> => {
59
53
  const environmentContext = getEnvironmentContext(ctx);
60
54
 
@@ -78,12 +72,8 @@ export const getEnvironmentVariables = async (
78
72
  ...basePredefinedVariables,
79
73
  ENV_SHORT: "local",
80
74
  ROOT_URL: url,
81
- // Rails before 6.1 (mis)uses the `HOST` environment variable to specify the IP to bind to
82
- ...(isStandaloneBuildConfig(buildConfigRaw) &&
83
- buildConfigRaw.type === "rails"
84
- ? {}
85
- : { HOST: host }),
86
- HOST_INTERNAL: host,
75
+ HOSTNAME: host,
76
+ HOSTNAME_INTERNAL: host,
87
77
  ROOT_URL_INTERNAL: "http://" + host,
88
78
  PORT: port.toString(),
89
79
  };
@@ -94,10 +84,10 @@ export const getEnvironmentVariables = async (
94
84
  )
95
85
  : {};
96
86
 
97
- const HOST_INTERNAL =
98
- additionalEnvVars.HOST_INTERNAL ?? "unknown-host.example.com";
87
+ const HOSTNAME_INTERNAL =
88
+ additionalEnvVars.HOSTNAME_INTERNAL ?? "unknown-host.example.com";
99
89
 
100
- host = envConfigRaw?.host ?? HOST_INTERNAL;
90
+ host = envConfigRaw?.host ?? HOSTNAME_INTERNAL;
101
91
  url = joinBashExpressions(["https://", host]);
102
92
 
103
93
  predefinedVariables = {
@@ -106,12 +96,11 @@ export const getEnvironmentVariables = async (
106
96
  ...(isStandaloneBuildConfig(buildConfigRaw) &&
107
97
  buildConfigRaw.type === "rails"
108
98
  ? {}
109
- : { HOST: host }),
99
+ : { HOSTNAME: host }),
110
100
  ROOT_URL: url,
111
- HOST_INTERNAL,
112
- /**@deprecated */
113
- HOST_CANONICAL: HOST_INTERNAL, // legacy alias for HOST_INTERNAL
114
- ROOT_URL_INTERNAL: joinBashExpressions(["https://", HOST_INTERNAL]),
101
+ HOSTNAME_INTERNAL,
102
+
103
+ ROOT_URL_INTERNAL: joinBashExpressions(["https://", HOSTNAME_INTERNAL]),
115
104
  ...additionalEnvVars,
116
105
  };
117
106
  }
@@ -132,39 +121,43 @@ export const getEnvironmentVariables = async (
132
121
  componentName,
133
122
  secretEnvVarKeys,
134
123
  );
135
- // this is deprecated, we now support: $componentname:FOO
136
- const legacyFromComponents = envConfigRaw.vars?.fromComponents ?? {};
137
- const publicEnvVarsRawWithLegacyFromComponents = merge(
138
- {},
139
- translateLegacyFromComponents(legacyFromComponents),
140
- publicEnvVarsRaw,
141
- );
142
124
 
143
- const publicEnvVarsRawSanitized = stringifyValues(
144
- publicEnvVarsRawWithLegacyFromComponents,
125
+ const publicEnvVarsRawSanitized = stringifyValues(publicEnvVarsRaw);
126
+
127
+ const publicEnvVarsUnresolved = Object.fromEntries(
128
+ Object.entries(publicEnvVarsRawSanitized).map(([key, value]) => [
129
+ key,
130
+ createVariableValueContainingReferencesFromString(value, {
131
+ componentName: ctx.componentName,
132
+ }),
133
+ ]),
145
134
  );
146
135
 
147
- const envVarsRaw = addIndexVar({
136
+ const publicEnvVars =
137
+ options.shouldResolveReferences ?? true
138
+ ? await resolveAllReferences(
139
+ publicEnvVarsUnresolved,
140
+ async (otherComponentName) => {
141
+ const { envVars: otherEnvVars } = await getEnvironmentVariables(
142
+ {
143
+ ...ctx,
144
+ componentName: otherComponentName,
145
+ },
146
+ {
147
+ shouldResolveReferences: false, // we already do this here with replaceAllReferences recursivly until re replaced all
148
+ },
149
+ );
150
+ return otherEnvVars;
151
+ },
152
+ )
153
+ : publicEnvVarsUnresolved;
154
+
155
+ const envVars = addIndexVar({
148
156
  ...predefinedVariables,
149
157
  ...secretEnvVars,
150
- ...publicEnvVarsRawSanitized,
158
+ ...publicEnvVars,
151
159
  });
152
160
 
153
- const envVars = (await resolveReferences(
154
- envVarsRaw,
155
- async (otherComponentName, alreadyVisited) => {
156
- const { envVars: otherEnvVars } = await getEnvironmentVariables(
157
- {
158
- ...ctx,
159
- componentName: otherComponentName,
160
- },
161
- alreadyVisited,
162
- );
163
- return otherEnvVars;
164
- },
165
- alreadyVisited,
166
- )) as typeof envVarsRaw;
167
-
168
161
  return {
169
162
  envVars,
170
163
  secretEnvVarKeys,
@@ -111,7 +111,7 @@ export const createDeployJob = (
111
111
  ...context.environment.envVars,
112
112
  ...(hasDocker ? getDockerImageVariables(context) : {}),
113
113
  ...context.environment.jobOnlyVars.deploy.envVars,
114
- ...(deployConfig ? deployConfig.extraVars ?? {} : {}),
114
+
115
115
  ...jobDefinition.variables,
116
116
  },
117
117
  runnerVariables: {
@@ -1,11 +1,10 @@
1
- import { isNil, omit } from "lodash";
2
- import type {
3
- ComponentContext,
4
- UnspecifiedEnvVars,
5
- } from "../../../types/context";
1
+ import { omit } from "lodash";
2
+ import type { ComponentContext } from "../../../types/context";
6
3
  import { collapseableSection } from "../../../utils/gitlab";
7
4
  import { getDependencyTrackUploadScript } from "../../sbom";
8
5
 
6
+ import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
7
+ import { writeBashYamlToFileScript } from "../../../bash/bashYaml";
9
8
  import { getRemoveOldRevisionsAndImagesCommand } from "../cleanup";
10
9
  import { getDatabaseCreateScript } from "../utils/database";
11
10
  import { gcloudServiceAccountLoginCommands } from "../utils/gcloudServiceAccountLoginCommands";
@@ -19,14 +18,7 @@ import {
19
18
  getCloudRunDeployConfig,
20
19
  setGoogleProjectNumberScript,
21
20
  } from "./common";
22
- import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
23
- import type { StringOrBashExpression } from "../../../bash/BashExpression";
24
- import { BashExpression, bashEscape } from "../../../bash/BashExpression";
25
21
  import { ENV_VARS_FILENAME } from "./constants";
26
- import {
27
- writeBashYamlToFileScript,
28
- yamlBashString,
29
- } from "../../../bash/bashYaml";
30
22
 
31
23
  export function getCloudRunDeployScripts(context: ComponentContext) {
32
24
  const deployConfig = getCloudRunDeployConfig(context);
@@ -85,7 +85,7 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigCloudRun>
85
85
  getAdditionalEnvVars: (ctx) => {
86
86
  const { fullName, env, componentName, deployConfigRaw } = ctx;
87
87
 
88
- const HOST_INTERNAL = joinBashExpressions(
88
+ const HOSTNAME_INTERNAL = joinBashExpressions(
89
89
  [
90
90
  fullName,
91
91
  getBashVariable(
@@ -113,7 +113,7 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigCloudRun>
113
113
  : {};
114
114
 
115
115
  return {
116
- HOST_INTERNAL,
116
+ HOSTNAME_INTERNAL,
117
117
  ...getCloudSqlVariables(ctx),
118
118
  ...jobTriggers,
119
119
  DEPLOY_CLOUD_RUN_PROJECT_ID: deployConfigRaw
@@ -1,6 +1,7 @@
1
1
  import type { StringOrBashExpression } from "../../../bash/BashExpression";
2
2
  import { getSecretVarNameForContext } from "../../../context";
3
3
  import type { ComponentContext } from "../../../types";
4
+ import type { VariableValue } from "../../../variables/VariableValue";
4
5
  import { getFullDbName } from "../../cloudSql/utils";
5
6
  import { isOfDeployType } from "../../types";
6
7
 
@@ -18,7 +19,7 @@ type CloudSqlValues = {
18
19
  proxyCredentials: string;
19
20
 
20
21
  instanceConnectionName: string;
21
- fullDbName: StringOrBashExpression;
22
+ fullDbName: VariableValue;
22
23
  dbUser: string;
23
24
  };
24
25
  export const createKubernetesCloudsqlBaseValues = (
@@ -41,21 +42,7 @@ export const createKubernetesCloudsqlBaseValues = (
41
42
  context,
42
43
  "cloudsqlProxyCredentials",
43
44
  )}`;
44
- if (config?.type !== "unmanaged") {
45
- const instanceConnectionName = `${config.projectId ?? "skynet-164509"}:${
46
- config.region ?? "europe-west6"
47
- }:${config.instanceId ?? context.environment.envVars.KUBE_NAMESPACE}`;
48
-
49
- return {
50
- cloudsql: {
51
- enabled: config.enabled,
52
- dbUser: "postgres",
53
- instanceConnectionName,
54
- proxyCredentials,
55
- fullDbName: context.environment.envVars.KUBE_APP_NAME ?? "",
56
- },
57
- };
58
- } else if (config.type === "unmanaged") {
45
+ if (config.type === "unmanaged") {
59
46
  return {
60
47
  cloudsql: {
61
48
  enabled: config.enabled,
@@ -47,8 +47,6 @@ export const createKubernetesDeployJobs = (
47
47
  ...(deployConfig.additionalHelmArgs ?? []),
48
48
  ].join(" "),
49
49
  COMPONENT_NAME: context.name,
50
- /** @deprecated */
51
- BUILD_ID: context.environment.envVars.BUILD_INFO_BUILD_ID,
52
50
  },
53
51
  };
54
52
 
@@ -29,7 +29,7 @@ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigKubernetes
29
29
  fullConfig.domainCanonical ||
30
30
  "panter.cloud";
31
31
 
32
- const HOST_INTERNAL = joinBashExpressions(
32
+ const HOSTNAME_INTERNAL = joinBashExpressions(
33
33
  [
34
34
  componentSlug,
35
35
  ...(envType === "review" && reviewSlug ? [reviewSlug] : []),
@@ -44,7 +44,7 @@ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigKubernetes
44
44
  KUBE_NAMESPACE,
45
45
  KUBE_APP_NAME,
46
46
  KUBE_APP_NAME_PREFIX,
47
- HOST_INTERNAL,
47
+ HOSTNAME_INTERNAL,
48
48
  };
49
49
  },
50
50
  };
@@ -1,5 +1,5 @@
1
- import type { StringOrBashExpression } from "../../bash/BashExpression";
2
1
  import type { ComponentContext } from "../../types";
2
+ import type { VariableValue } from "../../variables/VariableValue";
3
3
  import { isOfDeployType } from "../types";
4
4
 
5
5
  const shouldGoIntoSecrets = (key: string, value: string | undefined) => {
@@ -23,8 +23,8 @@ export const createKubeEnv = (context: ComponentContext) => {
23
23
  const allEnvVars = context.environment.envVars;
24
24
 
25
25
  const env = Object.entries(allEnvVars).reduce<{
26
- secret: Record<string, StringOrBashExpression>;
27
- public: Record<string, StringOrBashExpression>;
26
+ secret: Record<string, VariableValue>;
27
+ public: Record<string, VariableValue>;
28
28
  }>(
29
29
  (acc, [key, value]) => {
30
30
  if (shouldGoIntoSecrets(key, value?.toString())) {
@@ -11,7 +11,6 @@ import {
11
11
 
12
12
  import { createKubeEnv } from "./kubeEnv";
13
13
  import { createMongodbBaseConfig } from "./mongodb";
14
- import { processSecretsAsFiles } from "./processSecretsAsFiles";
15
14
 
16
15
  const createAppConfig = (
17
16
  context: ComponentContext,
@@ -87,14 +86,12 @@ export const createKubeValues = (context: ComponentContext) => {
87
86
  : {},
88
87
  );
89
88
 
90
- const kubeValues = processSecretsAsFiles(
91
- mergeWithMergingArrays(defaultKubeValues, {
92
- jobs: removeFalsy(jobs),
93
- cronjobs: removeFalsy(cronjobs),
89
+ const kubeValues = mergeWithMergingArrays(defaultKubeValues, {
90
+ jobs: removeFalsy(jobs),
91
+ cronjobs: removeFalsy(cronjobs),
94
92
 
95
- ...rest,
96
- }),
97
- );
93
+ ...rest,
94
+ });
98
95
 
99
96
  return kubeValues;
100
97
  };
@@ -25,12 +25,6 @@ export type DeployConfigBase = {
25
25
  */
26
26
  jobVars?: EnvVars;
27
27
 
28
- /**
29
- * additional env vars for the deploy job
30
- *
31
- * @deprecated use deploy.jobVars for deploy job specific variables
32
- */
33
- extraVars?: Record<string, string>;
34
28
  /**
35
29
  * additional vars only for the runner.
36
30
  * Also if you use services: that require env vars, you need to set them here.
@@ -164,33 +164,6 @@ export type DeployConfigMongodbReplicaset = {
164
164
  export type DeployConfigMongodb = DeployConfigMongodbBase &
165
165
  (DeployConfigMongodbStandalone | DeployConfigMongodbReplicaset);
166
166
 
167
- /**
168
- * @deprecated use config with instanceConnectionName
169
- */
170
- type DeployConfigKubernetesValuesCloudSQLLegacy = {
171
- enabled: boolean;
172
- /**
173
- * @deprecated use config with instanceConnectionName
174
- */
175
- instanceId?: string;
176
- /**
177
- * @deprecated use config with instanceConnectionName
178
- */
179
- projectId?: string;
180
- /**
181
- * @deprecated use config with instanceConnectionName
182
- */
183
- region?: string;
184
- /**
185
- * @deprecated use type "unmanaged".
186
- *
187
- * Be aware that "unmanaged" is not fully backward compatible with "legacy".
188
- *
189
- *
190
- */
191
- type?: "legacy";
192
- };
193
-
194
167
  export type DeployConfigKubernetesValuesCloudSQLUnmanaged = {
195
168
  enabled: boolean;
196
169
  instanceConnectionName: string;
@@ -220,8 +193,7 @@ export type DeployConfigKubernetesValuesCloudSQLUnmanaged = {
220
193
  dbBaseName?: string;
221
194
  };
222
195
  export type DeployConfigKubernetesValuesCloudSQL =
223
- | DeployConfigKubernetesValuesCloudSQLLegacy
224
- | DeployConfigKubernetesValuesCloudSQLUnmanaged;
196
+ DeployConfigKubernetesValuesCloudSQLUnmanaged;
225
197
  export type DeployConfigKubernetesValues = AllowUnknownProps<{
226
198
  /**
227
199
  * enable cloudsql db. Currently you have to manually set it up
@@ -358,13 +330,6 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
358
330
  mapServiceUrlToEnv?: {
359
331
  [envVar: string]: string;
360
332
  };
361
- /**
362
- * Mount secrets as files in the filesystem.
363
- * These secrets are still available as env vars, but will contain the path of the file instead
364
- *
365
- * @deprecated this will be removed in the future, because its very niche and not used
366
- */
367
- secretsAsFile?: string[];
368
333
  }>;
369
334
 
370
335
  export type DeployConfigKubernetes = {
@@ -0,0 +1,30 @@
1
+ class GlobalScriptFunction {
2
+ constructor(
3
+ public name: string,
4
+ public script: string,
5
+ ) {}
6
+
7
+ toBashFunction() {
8
+ return `function ${this.name} () {
9
+ ${this.script.trim()}
10
+ }`.trim();
11
+ }
12
+ invoke(...args: string[]) {
13
+ return `${this.name} ${args.join(" ")}`;
14
+ }
15
+ }
16
+
17
+ export const globalScriptFunctions = new Map<string, GlobalScriptFunction>();
18
+
19
+ /**
20
+ * registers a global script function
21
+ * only use that in top-level scopes as it will attach the function to the global scope
22
+ */
23
+ export const registerGlobalScriptFunction = (name: string, script: string) => {
24
+ if (globalScriptFunctions.has(name)) {
25
+ throw new Error(`Global script function ${name} already exists`);
26
+ }
27
+ const scriptFunction = new GlobalScriptFunction(name, script);
28
+ globalScriptFunctions.set(name, scriptFunction);
29
+ return scriptFunction;
30
+ };
package/src/index.ts CHANGED
@@ -7,3 +7,5 @@ export * from "./context";
7
7
  export * from "./build";
8
8
  export * from "./deploy";
9
9
  export * from "./utils/writeFiles";
10
+ export * from "./variables/VariableValue";
11
+ export * from "./bash";
@@ -106,7 +106,6 @@ export const makeGitlabJob = (
106
106
  environment,
107
107
  envMode,
108
108
  needsStages,
109
- needsOtherComponent,
110
109
  name,
111
110
  needs,
112
111
  jobTags,
@@ -310,7 +309,7 @@ function deduplicateNeeds(needs: GitlabJobDef["needs"]): GitlabJobDef["needs"] {
310
309
 
311
310
  function getGitlabNeedsForComponentJob(
312
311
  context: ComponentContext,
313
- { needsStages, needs, needsOtherComponent }: CatladderJob<string>,
312
+ { needsStages, needs }: CatladderJob<string>,
314
313
  allJobs: AllCatladderJobs,
315
314
  ): GitlabJobDef["needs"] {
316
315
  const needsFromStages = needsStages?.flatMap<CatladderJobNeed>((n) => {
@@ -353,8 +352,6 @@ function getGitlabNeedsForComponentJob(
353
352
  const cleanedNeeds: CatladderJob["needs"] = [
354
353
  ...(needsFromStages ?? []),
355
354
  ...(needs ?? []),
356
- // pull in legacy needs from other component, which is now identical to needs
357
- ...(needsOtherComponent ?? []),
358
355
  ];
359
356
 
360
357
  return cleanedNeeds
@@ -1,11 +1,12 @@
1
1
  import { getRunnerImage } from "../../runner";
2
2
  import type { Pipeline } from "../../types";
3
-
3
+ import { globalScriptFunctions } from "../../globalScriptFunctions";
4
4
  type PickRequired<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
5
5
 
6
6
  export const createGitlabPipelineWithDefaults = ({
7
7
  image,
8
8
  variables,
9
+ before_script,
9
10
  ...config
10
11
  }: PickRequired<
11
12
  Partial<Pipeline<"gitlab">>,
@@ -22,6 +23,12 @@ export const createGitlabPipelineWithDefaults = ({
22
23
  GIT_DEPTH: "1", // no need the full depth
23
24
  ...(variables ?? {}),
24
25
  },
26
+ before_script: [
27
+ ...[...globalScriptFunctions.values()].map((script) =>
28
+ script.toBashFunction(),
29
+ ),
30
+ ...(before_script ?? []),
31
+ ],
25
32
 
26
33
  ...config,
27
34
  };
@@ -49,11 +49,13 @@ export const getPackageManagerInfoForComponent = async (
49
49
  : [];
50
50
 
51
51
  const pathsToCopyInDocker = [
52
- packageJson,
53
- ...(workspacePackageJson ? [workspacePackageJson] : []),
54
- lockFile,
55
- ...configFilePaths,
56
- ...currentWorkspaceDependencies,
52
+ ...new Set([
53
+ packageJson,
54
+ ...(workspacePackageJson ? [workspacePackageJson] : []),
55
+ lockFile,
56
+ ...configFilePaths,
57
+ ...currentWorkspaceDependencies,
58
+ ]),
57
59
  ];
58
60
  return {
59
61
  ...baseInfo,