@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.
- package/dist/build/base/constants.js +2 -2
- package/dist/build/base/createBuildJob.d.ts +4 -2
- package/dist/build/base/createBuildJob.js +18 -17
- package/dist/build/base/getBuildInfo.d.ts +2 -0
- package/dist/build/base/getBuildInfo.js +12 -0
- package/dist/build/docker.d.ts +29 -4
- package/dist/build/docker.js +74 -23
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +1 -1
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/buildJob.js +27 -11
- package/dist/build/node/cache.d.ts +3 -1
- package/dist/build/node/cache.js +34 -6
- package/dist/build/node/constants.js +2 -2
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/meteor.js +7 -23
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +22 -30
- package/dist/build/node/yarn.d.ts +5 -0
- package/dist/build/node/yarn.js +51 -3
- package/dist/build/tests/storybook.test.js +17 -24
- package/dist/build/types.d.ts +13 -0
- package/dist/catladder-gitlab.js +42 -9
- package/dist/config/configruedEnvs.test.js +12 -3
- package/dist/config/readConfig.d.ts +5 -1
- package/dist/config/readConfig.js +20 -5
- package/dist/constants.js +1 -1
- package/dist/context/index.d.ts +4 -3
- package/dist/context/index.js +56 -43
- package/dist/context/resolveReferences.d.ts +6 -0
- package/dist/context/resolveReferences.js +93 -0
- package/dist/context/resolveReferences.test.d.ts +1 -0
- package/dist/context/resolveReferences.test.js +141 -0
- package/dist/deploy/base.d.ts +3 -4
- package/dist/deploy/base.js +55 -35
- package/dist/deploy/custom/deployJob.d.ts +3 -0
- package/dist/deploy/custom/deployJob.js +65 -0
- package/dist/deploy/custom/index.d.ts +1 -0
- package/dist/deploy/custom/index.js +22 -0
- package/dist/deploy/index.d.ts +5 -3
- package/dist/deploy/index.js +12 -0
- package/dist/deploy/kubernetes/cloudsql.js +1 -1
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +74 -42
- package/dist/deploy/kubernetes/mongodb.js +1 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +87 -0
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +39 -0
- package/dist/deploy/types.d.ts +194 -84
- package/dist/deploy/utils.d.ts +5 -0
- package/dist/deploy/utils.js +36 -0
- package/dist/pipeline/createChildPipeline.d.ts +2 -8
- package/dist/pipeline/createChildPipeline.js +24 -15
- package/dist/pipeline/createChildPipeline.test.js +10 -15
- package/dist/pipeline/createJobs.d.ts +2 -2
- package/dist/pipeline/createJobs.js +95 -33
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
- package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
- package/dist/pipeline/packageManager.d.ts +2 -0
- package/dist/pipeline/{yarnInfo.js → packageManager.js} +69 -8
- package/dist/runner/index.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +87 -1
- package/dist/types/context.d.ts +19 -8
- package/dist/types/gitlab-types.d.ts +10 -22
- package/dist/types/gitlab-types.js +1 -3
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +3 -1
- package/dist/types/jobs.d.ts +80 -0
- package/dist/types/jobs.js +5 -0
- package/dist/types/pipeline.d.ts +4 -0
- package/dist/types/pipeline.js +3 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +45 -2
- package/package.json +1 -3
- package/src/build/base/constants.ts +2 -2
- package/src/build/base/createBuildJob.ts +31 -34
- package/src/build/base/getBuildInfo.ts +7 -0
- package/src/build/docker.ts +75 -35
- package/src/build/index.ts +4 -3
- package/src/build/node/buildJob.ts +46 -24
- package/src/build/node/cache.ts +31 -6
- package/src/build/node/constants.ts +2 -2
- package/src/build/node/index.ts +4 -4
- package/src/build/node/meteor.ts +12 -18
- package/src/build/node/testJob.ts +35 -40
- package/src/build/node/yarn.ts +25 -4
- package/src/build/tests/storybook.test.ts +10 -2
- package/src/build/types.ts +12 -0
- package/src/catladder-gitlab.ts +12 -7
- package/src/config/configruedEnvs.test.ts +10 -3
- package/src/config/readConfig.ts +18 -6
- package/src/context/index.ts +90 -52
- package/src/context/resolveReferences.test.ts +158 -0
- package/src/context/resolveReferences.ts +66 -0
- package/src/deploy/base.ts +73 -47
- package/src/deploy/custom/deployJob.ts +23 -0
- package/src/deploy/custom/index.ts +1 -0
- package/src/deploy/index.ts +10 -4
- package/src/deploy/kubernetes/cloudsql.ts +3 -4
- package/src/deploy/kubernetes/deployJob.ts +85 -45
- package/src/deploy/kubernetes/mongodb.ts +1 -3
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +34 -0
- package/src/deploy/types.ts +177 -42
- package/src/deploy/utils.ts +30 -0
- package/src/pipeline/createChildPipeline.test.ts +8 -1
- package/src/pipeline/createChildPipeline.ts +23 -18
- package/src/pipeline/createJobs.ts +104 -56
- package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
- package/src/pipeline/packageManager.ts +99 -0
- package/src/runner/index.ts +3 -1
- package/src/types/config.ts +79 -1
- package/src/types/context.ts +18 -5
- package/src/types/gitlab-types.ts +10 -30
- package/src/types/index.ts +1 -0
- package/src/types/jobs.ts +94 -0
- package/src/types/pipeline.ts +11 -0
- package/src/utils/index.ts +10 -1
- package/dist/pipeline/yarnInfo.d.ts +0 -2
- 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 {
|
|
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):
|
|
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<
|
|
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
|
-
|
|
24
|
+
envMode: "none",
|
|
28
25
|
};
|
|
29
26
|
const yarnInstall = getYarnInstall(context);
|
|
30
|
-
const auditJob:
|
|
27
|
+
const auditJob: CatladderJob | null =
|
|
31
28
|
buildConfig.audit !== false
|
|
32
29
|
? {
|
|
33
30
|
name: "🛡 audit",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
46
|
+
const lintJob: CatladderJob | null =
|
|
48
47
|
buildConfig.lint !== false
|
|
49
48
|
? {
|
|
50
49
|
name: "👮 lint",
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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:
|
|
60
|
+
const testJob: CatladderJob | null =
|
|
64
61
|
buildConfig.test !== false
|
|
65
62
|
? {
|
|
66
63
|
name: "🧪 test",
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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);
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import { Context } from "../../types";
|
|
2
2
|
|
|
3
|
-
export const
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
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 {
|
|
44
|
+
const { jobs } = await createChildPipeline(
|
|
45
|
+
"gitlab",
|
|
38
46
|
"mainBranch",
|
|
39
47
|
config
|
|
40
48
|
);
|
package/src/build/types.ts
CHANGED
|
@@ -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;
|
package/src/catladder-gitlab.ts
CHANGED
|
@@ -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 =
|
|
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(
|
|
35
|
-
|
|
36
|
-
|
|
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,
|
package/src/config/readConfig.ts
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
package/src/context/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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 =
|
|
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.
|
|
73
|
+
? `${env}-${commitInfo.reviewSlug}-${componentName}`
|
|
57
74
|
: `${env}-${componentName}`;
|
|
58
75
|
|
|
59
76
|
let predefinedVariables: Record<string, string>;
|
|
60
|
-
let
|
|
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
|
-
|
|
66
|
-
url = "http://" +
|
|
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.
|
|
94
|
+
envType === "review" && commitInfo ? `${commitInfo.reviewSlug}.${env}` : env;
|
|
78
95
|
|
|
79
|
-
const
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
? `${
|
|
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
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
...
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
230
|
+
packageManagerInfo,
|
|
193
231
|
};
|
|
194
232
|
};
|