@catladder/pipeline 0.0.0-tagged-release-2fffd3dd → 0.0.0-waitfor-deploy-e64a33ba

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 (120) hide show
  1. package/dist/build/base/constants.js +2 -2
  2. package/dist/build/base/createBuildJob.d.ts +4 -2
  3. package/dist/build/base/createBuildJob.js +18 -17
  4. package/dist/build/base/getBuildInfo.d.ts +2 -0
  5. package/dist/build/base/getBuildInfo.js +12 -0
  6. package/dist/build/docker.d.ts +29 -4
  7. package/dist/build/docker.js +74 -23
  8. package/dist/build/index.d.ts +2 -2
  9. package/dist/build/index.js +1 -1
  10. package/dist/build/node/buildJob.d.ts +2 -2
  11. package/dist/build/node/buildJob.js +27 -11
  12. package/dist/build/node/cache.d.ts +3 -1
  13. package/dist/build/node/cache.js +34 -6
  14. package/dist/build/node/constants.js +2 -2
  15. package/dist/build/node/index.d.ts +4 -4
  16. package/dist/build/node/meteor.d.ts +2 -2
  17. package/dist/build/node/meteor.js +7 -23
  18. package/dist/build/node/testJob.d.ts +2 -2
  19. package/dist/build/node/testJob.js +22 -30
  20. package/dist/build/node/yarn.d.ts +5 -0
  21. package/dist/build/node/yarn.js +51 -3
  22. package/dist/build/tests/storybook.test.js +17 -24
  23. package/dist/build/types.d.ts +13 -0
  24. package/dist/catladder-gitlab.js +42 -9
  25. package/dist/config/configruedEnvs.test.js +12 -3
  26. package/dist/config/readConfig.d.ts +5 -1
  27. package/dist/config/readConfig.js +20 -5
  28. package/dist/constants.js +1 -1
  29. package/dist/context/index.d.ts +4 -3
  30. package/dist/context/index.js +56 -43
  31. package/dist/context/resolveReferences.d.ts +6 -0
  32. package/dist/context/resolveReferences.js +93 -0
  33. package/dist/context/resolveReferences.test.d.ts +1 -0
  34. package/dist/context/resolveReferences.test.js +141 -0
  35. package/dist/deploy/base.d.ts +3 -4
  36. package/dist/deploy/base.js +55 -35
  37. package/dist/deploy/custom/deployJob.d.ts +3 -0
  38. package/dist/deploy/custom/deployJob.js +65 -0
  39. package/dist/deploy/custom/index.d.ts +1 -0
  40. package/dist/deploy/custom/index.js +22 -0
  41. package/dist/deploy/index.d.ts +5 -3
  42. package/dist/deploy/index.js +12 -0
  43. package/dist/deploy/kubernetes/cloudsql.js +1 -1
  44. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  45. package/dist/deploy/kubernetes/deployJob.js +74 -42
  46. package/dist/deploy/kubernetes/mongodb.js +1 -1
  47. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +87 -0
  48. package/dist/deploy/kubernetes/processSecretsAsFiles.js +39 -0
  49. package/dist/deploy/types.d.ts +194 -84
  50. package/dist/deploy/utils.d.ts +5 -0
  51. package/dist/deploy/utils.js +36 -0
  52. package/dist/pipeline/createChildPipeline.d.ts +2 -8
  53. package/dist/pipeline/createChildPipeline.js +24 -15
  54. package/dist/pipeline/createChildPipeline.test.js +10 -15
  55. package/dist/pipeline/createJobs.d.ts +2 -2
  56. package/dist/pipeline/createJobs.js +95 -33
  57. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
  58. package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
  59. package/dist/pipeline/packageManager.d.ts +2 -0
  60. package/dist/pipeline/{yarnInfo.js → packageManager.js} +69 -8
  61. package/dist/runner/index.d.ts +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/dist/types/config.d.ts +87 -1
  64. package/dist/types/context.d.ts +19 -8
  65. package/dist/types/gitlab-types.d.ts +10 -22
  66. package/dist/types/gitlab-types.js +1 -3
  67. package/dist/types/index.d.ts +2 -1
  68. package/dist/types/index.js +3 -1
  69. package/dist/types/jobs.d.ts +80 -0
  70. package/dist/types/jobs.js +5 -0
  71. package/dist/types/pipeline.d.ts +4 -0
  72. package/dist/types/pipeline.js +3 -0
  73. package/dist/utils/index.d.ts +2 -1
  74. package/dist/utils/index.js +45 -2
  75. package/package.json +1 -3
  76. package/src/build/base/constants.ts +2 -2
  77. package/src/build/base/createBuildJob.ts +31 -34
  78. package/src/build/base/getBuildInfo.ts +7 -0
  79. package/src/build/docker.ts +75 -35
  80. package/src/build/index.ts +4 -3
  81. package/src/build/node/buildJob.ts +46 -24
  82. package/src/build/node/cache.ts +31 -6
  83. package/src/build/node/constants.ts +2 -2
  84. package/src/build/node/index.ts +4 -4
  85. package/src/build/node/meteor.ts +12 -18
  86. package/src/build/node/testJob.ts +35 -40
  87. package/src/build/node/yarn.ts +25 -4
  88. package/src/build/tests/storybook.test.ts +10 -2
  89. package/src/build/types.ts +12 -0
  90. package/src/catladder-gitlab.ts +12 -7
  91. package/src/config/configruedEnvs.test.ts +10 -3
  92. package/src/config/readConfig.ts +18 -6
  93. package/src/context/index.ts +90 -52
  94. package/src/context/resolveReferences.test.ts +158 -0
  95. package/src/context/resolveReferences.ts +66 -0
  96. package/src/deploy/base.ts +73 -47
  97. package/src/deploy/custom/deployJob.ts +23 -0
  98. package/src/deploy/custom/index.ts +1 -0
  99. package/src/deploy/index.ts +10 -4
  100. package/src/deploy/kubernetes/cloudsql.ts +3 -4
  101. package/src/deploy/kubernetes/deployJob.ts +85 -45
  102. package/src/deploy/kubernetes/mongodb.ts +1 -3
  103. package/src/deploy/kubernetes/processSecretsAsFiles.ts +34 -0
  104. package/src/deploy/types.ts +177 -42
  105. package/src/deploy/utils.ts +30 -0
  106. package/src/pipeline/createChildPipeline.test.ts +8 -1
  107. package/src/pipeline/createChildPipeline.ts +23 -18
  108. package/src/pipeline/createJobs.ts +104 -56
  109. package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
  110. package/src/pipeline/packageManager.ts +99 -0
  111. package/src/runner/index.ts +3 -1
  112. package/src/types/config.ts +79 -1
  113. package/src/types/context.ts +18 -5
  114. package/src/types/gitlab-types.ts +10 -30
  115. package/src/types/index.ts +1 -0
  116. package/src/types/jobs.ts +94 -0
  117. package/src/types/pipeline.ts +11 -0
  118. package/src/utils/index.ts +10 -1
  119. package/dist/pipeline/yarnInfo.d.ts +0 -2
  120. package/src/pipeline/yarnInfo.ts +0 -54
@@ -1,12 +1,11 @@
1
- import { BASE_RETRY } from "../../defaults";
2
1
  import { Context } from "../../types/context";
3
- import { GitlabJob, GitlabJobDef, GitlabJobs } from "../../types/gitlab-types";
2
+ import { CatladderJob } from "../../types/jobs";
4
3
  import { ensureArray, notNil } from "../../utils";
5
4
  import { getNodeCache } from "./cache";
6
5
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
7
6
  import { getYarnInstall } from "./yarn";
8
7
 
9
- export const createNodeTestJobs = (context: Context): GitlabJobs => {
8
+ export const createNodeTestJobs = (context: Context): CatladderJob[] => {
10
9
  // don't run tests after release
11
10
  if (context.commitInfo?.trigger === "taggedRelease") {
12
11
  return [];
@@ -14,66 +13,62 @@ export const createNodeTestJobs = (context: Context): GitlabJobs => {
14
13
 
15
14
  const buildConfig = context.componentConfig.build;
16
15
 
17
- const base: Omit<GitlabJobDef, "script"> = {
16
+ const base: Omit<CatladderJob, "script" | "name"> = {
18
17
  variables: {
19
18
  APP_PATH: context.componentConfig.dir,
20
19
  ...NODE_RUNNER_BUILD_VARIABLES,
21
20
  ...(buildConfig.extraVars ?? {}),
22
21
  },
23
-
24
22
  stage: "test",
25
- interruptible: true,
26
23
  needs: [],
27
- retry: BASE_RETRY,
24
+ envMode: "none",
28
25
  };
29
26
  const yarnInstall = getYarnInstall(context);
30
- const auditJob: GitlabJob | null =
27
+ const auditJob: CatladderJob | null =
31
28
  buildConfig.audit !== false
32
29
  ? {
33
30
  name: "🛡 audit",
34
- envMode: "none",
35
- job: {
36
- ...base,
37
- cache: undefined, // audit does not need yarn install and no cache
38
- script: [
39
- `cd ${context.componentConfig.dir}`,
40
- ...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
41
- ],
42
- allow_failure: true,
43
- },
31
+
32
+ ...base,
33
+ cache: undefined, // audit does not need yarn install and no cache
34
+ script: [
35
+ `cd ${context.componentConfig.dir}`,
36
+ ...(ensureArray(buildConfig.audit?.command) ?? [
37
+ context.packageManagerInfo?.isClassic
38
+ ? "yarn audit"
39
+ : "yarn npm audit --environment production", // yarn 2
40
+ ]),
41
+ ],
42
+ allow_failure: true,
44
43
  }
45
44
  : null;
46
45
 
47
- const lintJob: GitlabJob | null =
46
+ const lintJob: CatladderJob | null =
48
47
  buildConfig.lint !== false
49
48
  ? {
50
49
  name: "👮 lint",
51
- envMode: "none",
52
- job: {
53
- ...base,
54
- cache: getNodeCache(context),
55
- script: [
56
- `cd ${context.componentConfig.dir}`,
57
- ...yarnInstall,
58
- ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
59
- ],
60
- },
50
+
51
+ ...base,
52
+ cache: getNodeCache(context),
53
+ script: [
54
+ `cd ${context.componentConfig.dir}`,
55
+ ...yarnInstall,
56
+ ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
57
+ ],
61
58
  }
62
59
  : null;
63
- const testJob: GitlabJob | null =
60
+ const testJob: CatladderJob | null =
64
61
  buildConfig.test !== false
65
62
  ? {
66
63
  name: "🧪 test",
67
- envMode: "none",
68
- job: {
69
- ...base,
70
- cache: getNodeCache(context),
71
- script: [
72
- `cd ${context.componentConfig.dir}`,
73
- ...yarnInstall,
74
- ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
75
- ],
76
- },
64
+
65
+ ...base,
66
+ cache: getNodeCache(context),
67
+ script: [
68
+ `cd ${context.componentConfig.dir}`,
69
+ ...yarnInstall,
70
+ ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
71
+ ],
77
72
  }
78
73
  : null;
79
74
  return [auditJob, lintJob, testJob].filter(notNil);
@@ -1,8 +1,29 @@
1
1
  import { Context } from "../../types";
2
2
 
3
- export const getYarnInstall = (context: Context) => [
3
+ export const getYarnInstallCommand = (
4
+ context: Context,
5
+ options?: {
6
+ prodOnly?: boolean;
7
+ noScripts?: boolean;
8
+ }
9
+ ) =>
10
+ context.packageManagerInfo?.isClassic
11
+ ? `yarn install --frozen-lockfile ${
12
+ options?.prodOnly ? "--production" : ""
13
+ } ${options?.noScripts ? "--ignore-scripts" : ""}`
14
+ : options?.prodOnly
15
+ ? `${
16
+ options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
17
+ }yarn plugin import workspace-tools && yarn workspaces focus --production` // needs yarn plugin import workspace-tools
18
+ : `${
19
+ options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
20
+ }yarn install --immutable`;
21
+
22
+ export const ensureNodeVersion = (context: Context) => [
4
23
  "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
5
- context.yarnInfo?.isClassic
6
- ? "yarn install --frozen-lockfile"
7
- : "yarn install --immutable",
24
+ ];
25
+
26
+ export const getYarnInstall = (context: Context) => [
27
+ ...ensureNodeVersion(context),
28
+ getYarnInstallCommand(context),
8
29
  ];
@@ -14,13 +14,20 @@ describe("storybook build", () => {
14
14
  },
15
15
  deploy: {
16
16
  type: "kubernetes",
17
+ cluster: {
18
+ name: "production",
19
+ projectId: "bla",
20
+ region: "europe",
21
+ type: "gcloud",
22
+ },
17
23
  },
18
24
  },
19
25
  },
20
26
  };
21
27
 
22
28
  it("creates a pipeline for storybook that does not contain test stages", async () => {
23
- const { image, stages, workflow, ...jobs } = await createChildPipeline(
29
+ const { jobs } = await createChildPipeline(
30
+ "gitlab",
24
31
  "mainBranch",
25
32
  config
26
33
  );
@@ -34,7 +41,8 @@ describe("storybook build", () => {
34
41
  });
35
42
 
36
43
  it("runs build and renames folder", async () => {
37
- const { image, stages, workflow, ...jobs } = await createChildPipeline(
44
+ const { jobs } = await createChildPipeline(
45
+ "gitlab",
38
46
  "mainBranch",
39
47
  config
40
48
  );
@@ -1,5 +1,11 @@
1
1
  export type BuildConfigBase = {
2
+ /**
3
+ * command to run on the image to start the app (e.g. yarn start)
4
+ */
2
5
  startCommand?: string;
6
+ /**
7
+ * additional env vars for the buid jobs
8
+ */
3
9
  extraVars?: Record<string, string>;
4
10
  /**
5
11
  * define the build command
@@ -40,6 +46,12 @@ export type BuildConfigBase = {
40
46
  | {
41
47
  command?: string | string[];
42
48
  };
49
+
50
+ /**
51
+ * additional paths for artifacts,
52
+ * by default "dist" and ".next" are allways included
53
+ */
54
+ artifactsPaths?: string[];
43
55
  };
44
56
 
45
57
  export type BuildConfigNodeBase = BuildConfigBase;
@@ -1,4 +1,5 @@
1
1
  import { writeFileSync } from "fs";
2
+ import { dump } from "js-yaml";
2
3
  import { readConfigSync } from "./config";
3
4
  import { PIPELINE_IMAGE_TAG } from "./constants";
4
5
  import { createChildPipeline } from "./pipeline";
@@ -11,7 +12,8 @@ const {
11
12
  CI_DEFAULT_BRANCH,
12
13
  } = process.env;
13
14
 
14
- const isDefaultBranch = CI_COMMIT_BRANCH == CI_DEFAULT_BRANCH;
15
+ const isDefaultBranch =
16
+ Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
15
17
  const isHotfixBranch = false; // TODO: $CI_COMMIT_BRANCH =~ /^[0-9]+\.([0-9]+|x)\.x$/
16
18
  const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
17
19
  const isTaggedRelease = Boolean(CI_COMMIT_TAG);
@@ -27,15 +29,18 @@ const trigger: PipelineTrigger | null =
27
29
  ? "taggedRelease"
28
30
  : null;
29
31
  if (trigger) {
30
- const config = readConfigSync();
32
+ const config = readConfigSync()?.config;
31
33
  if (!config) {
32
34
  throw new Error("no catladder config found");
33
35
  }
34
- createChildPipeline(trigger, config).then((mainPipeline) => {
35
- writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
36
- encoding: "utf-8",
37
- });
38
- });
36
+ createChildPipeline("gitlab", trigger, config).then(
37
+ ({ jobs, ...mainPipeline }) => {
38
+ // need to spread out the jobs
39
+ writeFileSync(`__pipeline.yml`, dump({ ...jobs, ...mainPipeline }), {
40
+ encoding: "utf-8",
41
+ });
42
+ }
43
+ );
39
44
  } else {
40
45
  throw new Error(
41
46
  "no matching trigger: " +
@@ -1,7 +1,14 @@
1
1
  import { getAllEnvsByTrigger } from ".";
2
+ import { DeployConfigKubernetesCluster } from "..";
2
3
  import { Config } from "../types";
3
4
 
4
5
  describe("getAllEnvsByTrigger", () => {
6
+ const cluster: DeployConfigKubernetesCluster = {
7
+ type: "gcloud",
8
+ name: "mega-cluster",
9
+ projectId: "super-google-project",
10
+ region: "ch-blabla",
11
+ };
5
12
  const SIMPLE_CONFIG: Config = {
6
13
  appName: "my-app",
7
14
  customerName: "pan",
@@ -11,14 +18,14 @@ describe("getAllEnvsByTrigger", () => {
11
18
  build: {
12
19
  type: "node",
13
20
  },
14
- deploy: { type: "kubernetes" },
21
+ deploy: { type: "kubernetes", cluster },
15
22
  },
16
23
  app2: {
17
24
  dir: "dir2",
18
25
  build: {
19
26
  type: "node",
20
27
  },
21
- deploy: { type: "kubernetes" },
28
+ deploy: { type: "kubernetes", cluster },
22
29
  env: {
23
30
  dev2: {
24
31
  type: "dev",
@@ -39,7 +46,7 @@ describe("getAllEnvsByTrigger", () => {
39
46
  build: {
40
47
  type: "node",
41
48
  },
42
- deploy: { type: "kubernetes" },
49
+ deploy: { type: "kubernetes", cluster },
43
50
  env: {
44
51
  dev: false,
45
52
  review: false,
@@ -8,9 +8,14 @@ import { Config } from "../types";
8
8
  const fullPath = (directory: string, ext: string) =>
9
9
  directory + "/catladder." + ext;
10
10
 
11
+ function requireUncached(module: string) {
12
+ delete require.cache[require.resolve(module)];
13
+ return require(module);
14
+ }
15
+
11
16
  export const readConfigSync = (
12
17
  directory: string = process.cwd()
13
- ): Config | null => {
18
+ ): { config: Config; path: string; ext: string } | null => {
14
19
  register({
15
20
  cwd: directory,
16
21
  transpileOnly: true,
@@ -23,13 +28,20 @@ export const readConfigSync = (
23
28
  existsSync(fullPath(directory, extension))
24
29
  );
25
30
  if (found) {
31
+ const filePath = fullPath(directory, found);
26
32
  if (found === "ts" || found === "js") {
27
- // eslint-disable-next-line @typescript-eslint/no-var-requires
28
- return require(fullPath(directory, found)).default;
33
+ return {
34
+ path: filePath,
35
+ ext: found,
36
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
37
+ config: requireUncached(filePath).default,
38
+ };
29
39
  } else {
30
- return load(
31
- readFileSync(fullPath(directory, found), { encoding: "utf-8" })
32
- ) as Config;
40
+ return {
41
+ path: filePath,
42
+ ext: found,
43
+ config: load(readFileSync(filePath, { encoding: "utf-8" })) as Config,
44
+ };
33
45
  }
34
46
  }
35
47
  return null;
@@ -1,11 +1,21 @@
1
- import { merge } from "lodash";
1
+ import { isObject, merge } from "lodash";
2
2
  import slugify from "slugify";
3
3
  import { BUILD_TYPES } from "../build";
4
4
  import { BuildConfig } from "../build/types";
5
- import { DEPLOY_TYPES } from "../deploy";
5
+ import { DEPLOY_TYPES, getKubernetesNamespace } from "../deploy";
6
6
  import { DeployConfig } from "../deploy/types";
7
7
  import { Config, isKnowEnvType, DevLocalEnvConfig } from "../types/config";
8
- import { CommitInfo, Context, Environment, YarnInfo } from "../types/context";
8
+ import {
9
+ CommitInfo,
10
+ Context,
11
+ Environment,
12
+ PackageManagerInfo,
13
+ } from "../types/context";
14
+ import { mergeWithMergingArrays } from "../utils";
15
+ import {
16
+ resolveReferences,
17
+ translateLegacyFromComponents,
18
+ } from "./resolveReferences";
9
19
 
10
20
  const sanitizeForEnVar = (s: string) => s.replace(/-/g, "_");
11
21
  export const getSecretVarName = (
@@ -13,12 +23,15 @@ export const getSecretVarName = (
13
23
  componentName: string,
14
24
  key: string
15
25
  ) => `CL_${sanitizeForEnVar(env)}_${sanitizeForEnVar(componentName)}_${key}`; // remove dash from component name
26
+
27
+ export const getSecretVarNameForContext = (context: Context, key: string) =>
28
+ getSecretVarName(context.environment.shortName, context.componentName, key);
16
29
  export const getEnvironment = (
17
30
  config: Config,
18
31
  componentName: string,
19
32
  env: string,
20
33
  commitInfo?: CommitInfo,
21
- skipReferences = false // to prevent infinit loop
34
+ alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
22
35
  ): Environment => {
23
36
  const componentConfig = config.components[componentName];
24
37
  if (!componentConfig) {
@@ -32,20 +45,24 @@ export const getEnvironment = (
32
45
  throw new Error("env is disabled: " + env);
33
46
  }
34
47
 
35
- const mergedConfig = merge({}, defaultConfig, envConfig);
48
+ const mergedConfig = mergeWithMergingArrays(defaultConfig, envConfig);
36
49
 
37
50
  // env type: if its set manually, use that, otherwise use the known env types
38
51
 
39
- const basePredefinedVariables = {
40
- ENV_SHORT: env,
41
- APP_DIR: componentConfig.dir,
42
- };
43
52
  const envType = envConfig?.type ?? (isKnowEnvType(env) ? env : null);
53
+
44
54
  if (!envType) {
45
55
  throw new Error(
46
56
  "Missing type in environment " + env + " in component " + componentName
47
57
  );
48
58
  }
59
+
60
+ const basePredefinedVariables = {
61
+ ENV_SHORT: env,
62
+ APP_DIR: componentConfig.dir,
63
+ ENV_TYPE: envType,
64
+ };
65
+
49
66
  const environmentName =
50
67
  envType === "review" && commitInfo
51
68
  ? `${env}/${commitInfo.refName}/${componentName}`
@@ -53,38 +70,46 @@ export const getEnvironment = (
53
70
 
54
71
  const environmentSlug =
55
72
  envType === "review" && commitInfo
56
- ? `${env}-${commitInfo.refSlug}-${componentName}`
73
+ ? `${env}-${commitInfo.reviewSlug}-${componentName}`
57
74
  : `${env}-${componentName}`;
58
75
 
59
76
  let predefinedVariables: Record<string, string>;
60
- let hostname: string;
77
+ let host: string;
61
78
  let url: string;
62
79
  if (envType === "local") {
63
80
  const devLocalConfig: DevLocalEnvConfig = mergedConfig;
64
81
  const port = devLocalConfig.port ?? 3000;
65
- hostname = "localhost:" + port;
66
- url = "http://" + hostname;
82
+ host = "localhost:" + port;
83
+ url = "http://" + host;
67
84
  predefinedVariables = {
85
+ ENV_SHORT: "local",
68
86
  ROOT_URL: url,
69
87
  PORT: port.toString(),
70
88
  };
71
89
  } else {
72
- const KUBE_NAMESPACE = `${config.customerName}-${config.appName}-${env}`;
73
90
  const RELEASE_NAME = `${config.customerName}-${config.appName}-${environmentSlug}`;
74
91
 
75
92
  const componentSlug = slugify(componentName);
76
93
  const envInUrl =
77
- envType === "review" && commitInfo ? `${commitInfo.refSlug}.${env}` : env;
94
+ envType === "review" && commitInfo ? `${commitInfo.reviewSlug}.${env}` : env;
78
95
 
79
- const HOST_CANONICAL = `${config.appName}-${componentSlug}.${envInUrl}.${config.customerName}.panter.cloud`;
96
+ const domainCanonical =
97
+ (mergedConfig?.deploy &&
98
+ mergedConfig?.deploy.type === "kubernetes" &&
99
+ mergedConfig.deploy.cluster?.domainCanonical) || // for convenience, we allow clusters to define a canonical domain, because a cluster has a fixed ip and you will usually have a domain pointing to that cluster
100
+ config.domainCanonical ||
101
+ "panter.cloud";
80
102
 
81
- hostname = mergedConfig?.hostname ?? HOST_CANONICAL;
82
- const url = `https://${hostname}`;
103
+ const HOST_CANONICAL = `${componentSlug}.${envInUrl}.${config.appName}.${config.customerName}.${domainCanonical}`;
104
+ host = mergedConfig?.host ?? HOST_CANONICAL;
105
+ const url = `https://${host}`;
83
106
 
107
+ // FIXME: move to kube specific jobs
84
108
  const KUBE_APP_NAME =
85
109
  envType === "review" && commitInfo
86
- ? `${componentName}-${commitInfo.refSlug}`
110
+ ? `${commitInfo.reviewSlug}-${componentName}`
87
111
  : componentName;
112
+ const KUBE_NAMESPACE = getKubernetesNamespace(config, env);
88
113
 
89
114
  predefinedVariables = {
90
115
  ...basePredefinedVariables,
@@ -95,7 +120,7 @@ export const getEnvironment = (
95
120
  RELEASE_NAME,
96
121
  };
97
122
  }
98
- const publicEnvVars = mergedConfig.vars?.public ?? {};
123
+ const publicEnvVarsRaw = mergedConfig.vars?.public ?? {};
99
124
  const secretEnvVarKeys = mergedConfig.vars?.secret ?? [];
100
125
  const secretEnvVars = Object.fromEntries(
101
126
  secretEnvVarKeys.map((key) => [
@@ -103,40 +128,47 @@ export const getEnvironment = (
103
128
  `$${getSecretVarName(env, componentName, key)}`,
104
129
  ])
105
130
  );
106
- const referencedRaw = mergedConfig.vars?.fromComponents ?? {};
107
-
108
- const referenced = skipReferences
109
- ? {}
110
- : Object.entries(referencedRaw).reduce((acc, [otherApp, mapping]) => {
111
- const { envVars } = getEnvironment(
112
- config,
113
- otherApp,
114
- env,
115
- commitInfo,
116
- true // prevent infinit loop
117
- );
118
-
119
- return {
120
- ...acc,
121
- ...Object.fromEntries(
122
- Object.entries(mapping).map(([ourKey, otherKey]) => [
123
- ourKey,
124
- envVars[otherKey],
125
- ])
126
- ),
127
- };
128
- }, {});
129
-
130
- const envVars = {
131
+
132
+ // this is deprecated, we now support: $componentname:FOO
133
+ const legacyFromComponents = mergedConfig.vars?.fromComponents ?? {};
134
+ const publicEnvVarsRawWithLegasyFromComponents = merge(
135
+ {},
136
+ translateLegacyFromComponents(legacyFromComponents),
137
+ publicEnvVarsRaw
138
+ );
139
+
140
+ const publicEnvVarsRawSanitized = Object.fromEntries(
141
+ Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(
142
+ ([key, value]) => [
143
+ key,
144
+ isObject(value) ? JSON.stringify(value) : `${value}`,
145
+ ]
146
+ )
147
+ );
148
+
149
+ const envVarsRaw = {
131
150
  ...predefinedVariables,
132
151
  ...secretEnvVars,
133
- ...referenced,
134
- ...publicEnvVars,
152
+ ...publicEnvVarsRawSanitized,
135
153
  };
136
154
 
155
+ const envVars = resolveReferences(
156
+ envVarsRaw,
157
+ (componentName, variableName, alreadyVisited) => {
158
+ const { envVars } = getEnvironment(
159
+ config,
160
+ componentName,
161
+ env,
162
+ commitInfo,
163
+ alreadyVisited
164
+ );
165
+ return envVars[variableName];
166
+ },
167
+ alreadyVisited
168
+ );
137
169
  return {
138
170
  envType,
139
- hostname,
171
+ host,
140
172
  fullName: environmentName,
141
173
  slug: environmentSlug,
142
174
  shortName: env,
@@ -151,7 +183,7 @@ export const createContext = (
151
183
  componentName: string,
152
184
  env: string,
153
185
  commitInfo?: CommitInfo,
154
- yarnInfo?: YarnInfo
186
+ packageManagerInfo?: PackageManagerInfo
155
187
  ): Context => {
156
188
  if (!/^[a-z0-9-]+$/.test(componentName)) {
157
189
  throw new Error(
@@ -164,7 +196,10 @@ export const createContext = (
164
196
  }
165
197
  // envs can override the config
166
198
  const envConfig = rawConfig.env?.[env] ?? {};
167
- const componentConfigWithoutDefaults = merge({}, rawConfig, envConfig);
199
+ const componentConfigWithoutDefaults = mergeWithMergingArrays(
200
+ rawConfig,
201
+ envConfig
202
+ );
168
203
 
169
204
  // fill in defaults of build and deploy
170
205
  const defaults: {
@@ -181,7 +216,10 @@ export const createContext = (
181
216
  build: {},
182
217
  deploy: {},
183
218
  };
184
- const componentConfig = merge({}, defaults, componentConfigWithoutDefaults);
219
+ const componentConfig = mergeWithMergingArrays(
220
+ defaults,
221
+ componentConfigWithoutDefaults
222
+ );
185
223
 
186
224
  return {
187
225
  fullConfig: config,
@@ -189,6 +227,6 @@ export const createContext = (
189
227
  componentName,
190
228
  environment: getEnvironment(config, componentName, env, commitInfo),
191
229
  commitInfo,
192
- yarnInfo,
230
+ packageManagerInfo,
193
231
  };
194
232
  };