@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.
- package/bin/catladder-gitlab.js +1 -1
- package/dist/build/base/createBuildJob.d.ts +2 -2
- package/dist/build/base/getBuildInfo.d.ts +1 -1
- package/dist/build/docker.d.ts +44 -6
- package/dist/build/docker.js +45 -19
- package/dist/build/index.d.ts +6 -5
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/cache.d.ts +2 -2
- package/dist/build/node/index.d.ts +1 -1
- package/dist/build/node/meteor.d.ts +1 -1
- package/dist/build/node/meteor.js +6 -0
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +3 -0
- package/dist/build/node/yarn.d.ts +1 -1
- package/dist/build/node/yarn.js +13 -1
- package/dist/build/types.d.ts +10 -0
- package/dist/bundles/catladder-gitlab/index.js +32457 -0
- package/dist/catladder-gitlab.js +1 -2
- package/dist/config/configruedEnvs.d.ts +1 -1
- package/dist/config/readConfig.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/getEnvConfig.d.ts +9 -0
- package/dist/context/getEnvConfig.js +26 -0
- package/dist/context/getEnvType.d.ts +4 -0
- package/dist/context/getEnvType.js +18 -0
- package/dist/context/getEnvironment.d.ts +3 -0
- package/dist/context/getEnvironment.js +187 -0
- package/dist/context/getEnvironmentContext.d.ts +4 -0
- package/dist/context/getEnvironmentContext.js +36 -0
- package/dist/context/getEnvironmentVariables.d.ts +10 -0
- package/dist/context/getEnvironmentVariables.js +322 -0
- package/dist/context/getLabels.d.ts +8 -0
- package/dist/context/getLabels.js +49 -0
- package/dist/context/index.d.ts +5 -6
- package/dist/context/index.js +176 -181
- package/dist/context/resolveReferences.d.ts +1 -3
- package/dist/context/resolveReferences.js +275 -26
- package/dist/context/resolveReferences.test.js +332 -81
- package/dist/defaults/index.d.ts +1 -1
- package/dist/deploy/base.d.ts +4 -2
- package/dist/deploy/base.js +37 -17
- package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
- package/dist/deploy/cloudRun/deployJob.js +139 -0
- package/dist/deploy/cloudRun/index.d.ts +9 -0
- package/dist/deploy/cloudRun/index.js +56 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +14 -0
- package/dist/deploy/cloudSql/index.d.ts +8 -0
- package/dist/deploy/cloudSql/index.js +30 -0
- package/dist/deploy/custom/deployJob.d.ts +2 -2
- package/dist/deploy/custom/deployJob.js +4 -1
- package/dist/deploy/custom/index.d.ts +2 -1
- package/dist/deploy/custom/index.js +15 -18
- package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
- package/dist/deploy/dockerTag/deployJob.js +33 -0
- package/dist/deploy/dockerTag/index.d.ts +2 -0
- package/dist/deploy/dockerTag/index.js +19 -0
- package/dist/deploy/index.d.ts +12 -8
- package/dist/deploy/index.js +27 -14
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
- package/dist/deploy/kubernetes/additionalSecretKeys.js +33 -0
- package/dist/deploy/kubernetes/cloudsql.d.ts +1 -1
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +13 -66
- package/dist/deploy/kubernetes/index.d.ts +2 -1
- package/dist/deploy/kubernetes/index.js +45 -16
- package/dist/deploy/kubernetes/kubeEnv.d.ts +10 -0
- package/dist/deploy/kubernetes/kubeEnv.js +90 -0
- package/dist/deploy/kubernetes/kubeValues.d.ts +90 -0
- package/dist/deploy/kubernetes/kubeValues.js +96 -0
- package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
- package/dist/deploy/kubernetes/mongodb.js +118 -8
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +21 -21
- package/dist/deploy/types/base.d.ts +15 -0
- package/dist/deploy/types/base.js +3 -0
- package/dist/deploy/types/custom.d.ts +27 -0
- package/dist/deploy/types/custom.js +3 -0
- package/dist/deploy/types/dockerTag.d.ts +10 -0
- package/dist/deploy/types/dockerTag.js +3 -0
- package/dist/deploy/types/googleCloudRun.d.ts +39 -0
- package/dist/deploy/types/googleCloudRun.js +3 -0
- package/dist/deploy/types/index.d.ts +24 -0
- package/dist/deploy/types/index.js +41 -0
- package/dist/deploy/{types.d.ts → types/kubernetes.d.ts} +128 -36
- package/dist/deploy/types/kubernetes.js +3 -0
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/deploy/utils.js +4 -0
- package/dist/pipeline/createChildPipeline.d.ts +2 -2
- package/dist/pipeline/createChildPipeline.js +3 -3
- package/dist/pipeline/createJobs.d.ts +2 -2
- package/dist/pipeline/createJobs.js +63 -25
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +3 -2
- package/dist/pipeline/gitlab/makeGitlabJob.js +2 -1
- package/dist/pipeline/packageManager.d.ts +1 -1
- package/dist/rules/index.d.ts +1 -1
- package/dist/runner/index.d.ts +2 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +7 -6
- package/dist/types/config.js +1 -1
- package/dist/types/context.d.ts +10 -2
- package/dist/types/environmentContext.d.ts +22 -0
- package/dist/types/environmentContext.js +3 -0
- package/dist/types/gitlab-types.d.ts +1 -1
- package/dist/types/jobs.d.ts +8 -3
- package/dist/types/jobs.js +1 -1
- package/dist/types/pipeline.d.ts +1 -1
- package/package.json +15 -11
- package/scripts/bundle +2 -0
- package/src/build/base/createBuildJob.ts +3 -2
- package/src/build/base/getBuildInfo.ts +1 -1
- package/src/build/docker.ts +47 -29
- package/src/build/index.ts +8 -5
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +2 -2
- package/src/build/node/index.ts +1 -1
- package/src/build/node/meteor.ts +8 -2
- package/src/build/node/testJob.ts +4 -2
- package/src/build/node/yarn.ts +21 -10
- package/src/build/tests/storybook.test.ts +1 -1
- package/src/build/types.ts +13 -1
- package/src/catladder-gitlab.ts +4 -2
- package/src/config/configruedEnvs.test.ts +2 -2
- package/src/config/configruedEnvs.ts +5 -4
- package/src/config/readConfig.ts +1 -1
- package/src/context/getEnvConfig.ts +21 -0
- package/src/context/getEnvType.ts +17 -0
- package/src/context/getEnvironment.ts +40 -0
- package/src/context/getEnvironmentContext.ts +57 -0
- package/src/context/getEnvironmentVariables.ts +152 -0
- package/src/context/getLabels.ts +20 -0
- package/src/context/index.ts +25 -191
- package/src/context/resolveReferences.test.ts +15 -15
- package/src/context/resolveReferences.ts +37 -30
- package/src/defaults/index.ts +1 -1
- package/src/deploy/base.ts +43 -19
- package/src/deploy/cloudRun/deployJob.ts +104 -0
- package/src/deploy/cloudRun/index.ts +48 -0
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
- package/src/deploy/cloudSql/index.ts +16 -0
- package/src/deploy/custom/deployJob.ts +10 -3
- package/src/deploy/custom/index.ts +9 -1
- package/src/deploy/dockerTag/deployJob.ts +31 -0
- package/src/deploy/dockerTag/index.ts +9 -0
- package/src/deploy/index.ts +26 -17
- package/src/deploy/kubernetes/additionalSecretKeys.ts +23 -0
- package/src/deploy/kubernetes/cloudsql.ts +2 -1
- package/src/deploy/kubernetes/deployJob.ts +19 -77
- package/src/deploy/kubernetes/index.ts +42 -1
- package/src/deploy/kubernetes/kubeEnv.ts +48 -0
- package/src/deploy/kubernetes/kubeValues.ts +82 -0
- package/src/deploy/kubernetes/mongodb.ts +104 -7
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +1 -1
- package/src/deploy/types/base.ts +17 -0
- package/src/deploy/types/custom.ts +24 -0
- package/src/deploy/types/dockerTag.ts +12 -0
- package/src/deploy/types/googleCloudRun.ts +79 -0
- package/src/deploy/types/index.ts +28 -0
- package/src/deploy/types/kubernetes.ts +281 -0
- package/src/deploy/utils.ts +6 -2
- package/src/pipeline/createChildPipeline.test.ts +1 -1
- package/src/pipeline/createChildPipeline.ts +4 -4
- package/src/pipeline/createJobs.ts +32 -21
- package/src/pipeline/gitlab/makeGitlabJob.ts +3 -2
- package/src/pipeline/packageManager.ts +1 -1
- package/src/rules/index.ts +1 -1
- package/src/runner/index.ts +2 -1
- package/src/types/config.ts +8 -6
- package/src/types/context.ts +14 -2
- package/src/types/environmentContext.ts +26 -0
- package/src/types/gitlab-types.ts +1 -1
- package/src/types/jobs.ts +9 -2
- package/src/types/pipeline.ts +1 -1
- package/tsconfig.json +2 -0
- package/dist/deploy/types.js +0 -16
- package/src/deploy/types.ts +0 -189
package/src/build/index.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { Context } from "../types/context";
|
|
1
|
+
import type { Context } from "../types/context";
|
|
2
|
+
import type { EnvironmentContext } from "../types/environmentContext";
|
|
2
3
|
|
|
3
|
-
import { CatladderJob } from "../types/jobs";
|
|
4
|
+
import type { CatladderJob } from "../types/jobs";
|
|
4
5
|
import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
|
|
5
6
|
|
|
6
|
-
import { BuildConfig } from "./types";
|
|
7
|
+
import type { BuildConfig, BuildConfigType } from "./types";
|
|
7
8
|
export * from "./types";
|
|
8
9
|
export * from "./node";
|
|
9
10
|
|
|
10
11
|
export type BuildTypes = {
|
|
11
|
-
[type in
|
|
12
|
+
[type in BuildConfigType]: {
|
|
12
13
|
jobs: (context: Context) => CatladderJob[];
|
|
13
|
-
defaults: (
|
|
14
|
+
defaults: (
|
|
15
|
+
envVarContext: EnvironmentContext<BuildConfigType, any>
|
|
16
|
+
) => Partial<Extract<BuildConfig, { type: type }>>;
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "../../types/context";
|
|
1
|
+
import type { Context } from "../../types/context";
|
|
2
2
|
import { ensureArray } from "../../utils";
|
|
3
3
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
4
4
|
import { createBuildJob } from "../base/createBuildJob";
|
|
@@ -8,7 +8,7 @@ import { isOfBuildType } from "../types";
|
|
|
8
8
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
9
9
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
10
10
|
import { getYarnInstall, getYarnInstallCommand } from "./yarn";
|
|
11
|
-
import { CatladderJob } from "../../types/jobs";
|
|
11
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
12
12
|
|
|
13
13
|
export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
14
14
|
const buildConfig = context.componentConfig.build;
|
package/src/build/node/cache.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
|
-
import { Context } from "../../types/context";
|
|
3
|
-
import { GitlabJobCache } from "../../types/gitlab-types";
|
|
2
|
+
import type { Context } from "../../types/context";
|
|
3
|
+
import type { GitlabJobCache } from "../../types/gitlab-types";
|
|
4
4
|
|
|
5
5
|
export const getYarnCache = (
|
|
6
6
|
context: Context,
|
package/src/build/node/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "../../types/context";
|
|
2
|
-
import { CatladderJob } from "../../types/jobs";
|
|
2
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createNodeBuildJobs } from "./buildJob";
|
|
4
4
|
import { createMeteorBuildJobs } from "./meteor";
|
|
5
5
|
import { createNodeTestJobs } from "./testJob";
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { getRunnerImage } from "../../runner";
|
|
3
|
-
import { GitlabJobCache } from "../../types";
|
|
3
|
+
import type { GitlabJobCache } from "../../types";
|
|
4
4
|
import type { Context } from "../../types/context";
|
|
5
5
|
|
|
6
|
-
import { CatladderJob } from "../../types/jobs";
|
|
6
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
7
7
|
|
|
8
8
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
9
9
|
import { createBuildJob } from "../base/createBuildJob";
|
|
@@ -40,6 +40,9 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
40
40
|
? createBuildJob(context, {
|
|
41
41
|
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
42
42
|
image: getRunnerImage("jobs-meteor"),
|
|
43
|
+
variables: {
|
|
44
|
+
METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
|
|
45
|
+
},
|
|
43
46
|
script: [
|
|
44
47
|
...yarnInstall,
|
|
45
48
|
|
|
@@ -63,6 +66,9 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
63
66
|
...(appBuildJob ? [appBuildJob] : []),
|
|
64
67
|
createDockerBuildJobDefault(context, {
|
|
65
68
|
script: ["ensureMeteorDockerfile"],
|
|
69
|
+
variables: {
|
|
70
|
+
METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
|
|
71
|
+
},
|
|
66
72
|
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
67
73
|
}),
|
|
68
74
|
];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getRunnerImage } from "../../runner";
|
|
2
|
+
import type { Context } from "../../types/context";
|
|
3
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
3
4
|
import { ensureArray, notNil } from "../../utils";
|
|
4
5
|
import { getNodeCache } from "./cache";
|
|
5
6
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
@@ -63,6 +64,7 @@ export const createNodeTestJobs = (context: Context): CatladderJob[] => {
|
|
|
63
64
|
name: "🧪 test",
|
|
64
65
|
|
|
65
66
|
...base,
|
|
67
|
+
image: getRunnerImage("jobs-testing-chrome"),
|
|
66
68
|
cache: getNodeCache(context),
|
|
67
69
|
script: [
|
|
68
70
|
`cd ${context.componentConfig.dir}`,
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "../../types";
|
|
1
|
+
import type { Context } from "../../types";
|
|
2
2
|
|
|
3
3
|
export const getYarnInstallCommand = (
|
|
4
4
|
context: Context,
|
|
@@ -6,18 +6,29 @@ export const getYarnInstallCommand = (
|
|
|
6
6
|
prodOnly?: boolean;
|
|
7
7
|
noScripts?: boolean;
|
|
8
8
|
}
|
|
9
|
-
) =>
|
|
10
|
-
context.packageManagerInfo?.isClassic
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
) => {
|
|
10
|
+
if (context.packageManagerInfo?.isClassic) {
|
|
11
|
+
return `yarn install --frozen-lockfile ${
|
|
12
|
+
options?.prodOnly ? "--production" : ""
|
|
13
|
+
} ${options?.noScripts ? "--ignore-scripts" : ""}`;
|
|
14
|
+
}
|
|
15
|
+
// is modern
|
|
16
|
+
|
|
17
|
+
// yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
|
|
18
|
+
// trying to import those fail on this version
|
|
19
|
+
const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) =>
|
|
20
|
+
context.packageManagerInfo?.version.startsWith(v)
|
|
21
|
+
);
|
|
22
|
+
return options?.prodOnly
|
|
23
|
+
? `${options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""}${
|
|
24
|
+
doesNotShipWithBuiltInPlugins
|
|
25
|
+
? "yarn plugin import workspace-tools && "
|
|
26
|
+
: " "
|
|
27
|
+
}yarn workspaces focus --production` // needs yarn plugin import workspace-tools
|
|
18
28
|
: `${
|
|
19
29
|
options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
|
|
20
30
|
}yarn install --immutable`;
|
|
31
|
+
};
|
|
21
32
|
|
|
22
33
|
export const ensureNodeVersion = (context: Context) => [
|
|
23
34
|
"if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
|
package/src/build/types.ts
CHANGED
|
@@ -67,6 +67,11 @@ export type BuildConfigNodeStatic = BuildConfigNodeBase & {
|
|
|
67
67
|
|
|
68
68
|
export type BuildConfigMeteor = BuildConfigNodeBase & {
|
|
69
69
|
type: "meteor";
|
|
70
|
+
/**
|
|
71
|
+
* whether to run yarn install inside the source folder in the docker image.
|
|
72
|
+
* This is only required if you have custom scripts in your image
|
|
73
|
+
*/
|
|
74
|
+
installScripts?: boolean;
|
|
70
75
|
};
|
|
71
76
|
|
|
72
77
|
export type BuildConfigStorybook = BuildConfigNodeBase & {
|
|
@@ -79,7 +84,14 @@ export type BuildConfig =
|
|
|
79
84
|
| BuildConfigStorybook
|
|
80
85
|
| BuildConfigMeteor;
|
|
81
86
|
|
|
82
|
-
export
|
|
87
|
+
export type BuildConfigType = BuildConfig["type"];
|
|
88
|
+
|
|
89
|
+
export type BuildConfigGeneric<T extends BuildConfigType> = Extract<
|
|
90
|
+
BuildConfig,
|
|
91
|
+
{ type: T }
|
|
92
|
+
>;
|
|
93
|
+
|
|
94
|
+
export const isOfBuildType = <T extends Array<BuildConfigType>>(
|
|
83
95
|
t: BuildConfig,
|
|
84
96
|
...types: T
|
|
85
97
|
): t is Extract<BuildConfig, { type: T[number] }> => {
|
package/src/catladder-gitlab.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { dump } from "js-yaml";
|
|
|
3
3
|
import { readConfigSync } from "./config";
|
|
4
4
|
import { PIPELINE_IMAGE_TAG } from "./constants";
|
|
5
5
|
import { createChildPipeline } from "./pipeline";
|
|
6
|
-
import { PipelineTrigger } from "./types";
|
|
6
|
+
import type { PipelineTrigger } from "./types";
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
CI_MERGE_REQUEST_ID,
|
|
@@ -14,7 +14,9 @@ const {
|
|
|
14
14
|
|
|
15
15
|
const isDefaultBranch =
|
|
16
16
|
Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
|
|
17
|
-
const isHotfixBranch =
|
|
17
|
+
const isHotfixBranch = CI_COMMIT_BRANCH
|
|
18
|
+
? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
|
|
19
|
+
: false;
|
|
18
20
|
const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
19
21
|
const isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
20
22
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAllEnvsByTrigger } from ".";
|
|
2
|
-
import { DeployConfigKubernetesCluster } from "..";
|
|
3
|
-
import { Config } from "../types";
|
|
2
|
+
import type { DeployConfigKubernetesCluster } from "..";
|
|
3
|
+
import type { Config } from "../types";
|
|
4
4
|
|
|
5
5
|
describe("getAllEnvsByTrigger", () => {
|
|
6
6
|
const cluster: DeployConfigKubernetesCluster = {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Config,
|
|
3
|
-
DEFAULT_ENV_TYPES,
|
|
4
3
|
EnvType,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
PipelineTrigger} from "../types";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_ENV_TYPES,
|
|
7
|
+
getEnvTypesByTrigger
|
|
7
8
|
} from "../types";
|
|
8
9
|
|
|
9
10
|
const getConfiguredAndDefaultEnvs = (
|
package/src/config/readConfig.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from "../types/config";
|
|
2
|
+
|
|
3
|
+
import { mergeWithMergingArrays } from "../utils";
|
|
4
|
+
|
|
5
|
+
export const getEnvConfig = (
|
|
6
|
+
config: Config,
|
|
7
|
+
componentName: string,
|
|
8
|
+
env: string
|
|
9
|
+
) => {
|
|
10
|
+
const defaultConfig = config.components[componentName];
|
|
11
|
+
if (!defaultConfig) {
|
|
12
|
+
throw new Error("unknown component " + componentName);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const envCustomizations = defaultConfig.env?.[env] ?? {};
|
|
16
|
+
if (envCustomizations === false) {
|
|
17
|
+
throw new Error("env is disabled: " + env);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return mergeWithMergingArrays(defaultConfig, envCustomizations);
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EnvType } from "../types";
|
|
2
|
+
import { isKnowEnvType } from "../types";
|
|
3
|
+
|
|
4
|
+
export const getEnvType = (
|
|
5
|
+
env: string,
|
|
6
|
+
envConfig: {
|
|
7
|
+
type?: EnvType;
|
|
8
|
+
}
|
|
9
|
+
): EnvType => {
|
|
10
|
+
if (envConfig.type) return envConfig.type;
|
|
11
|
+
|
|
12
|
+
if (isKnowEnvType(env)) {
|
|
13
|
+
return env;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error("unknown env type: " + env);
|
|
17
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Config } from "../types/config";
|
|
2
|
+
|
|
3
|
+
import type { CommitInfo, Environment } from "../types/context";
|
|
4
|
+
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
5
|
+
import { getEnvironmentVariables } from "./getEnvironmentVariables";
|
|
6
|
+
|
|
7
|
+
export const getEnvironment = async (
|
|
8
|
+
config: Config,
|
|
9
|
+
componentName: string,
|
|
10
|
+
env: string,
|
|
11
|
+
commitInfo?: CommitInfo
|
|
12
|
+
): Promise<Environment> => {
|
|
13
|
+
const { envVars, secretEnvVarKeys, host, url } =
|
|
14
|
+
await getEnvironmentVariables(config, componentName, env, commitInfo);
|
|
15
|
+
|
|
16
|
+
const envVarContext = getEnvironmentContext(
|
|
17
|
+
config,
|
|
18
|
+
env,
|
|
19
|
+
componentName,
|
|
20
|
+
commitInfo
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// env type: if its set manually, use that, otherwise use the known env types
|
|
24
|
+
const envType = envVarContext.envType;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
envType,
|
|
28
|
+
host,
|
|
29
|
+
url,
|
|
30
|
+
gitlabEnvironment: {
|
|
31
|
+
name: envVarContext.gitlabEnvironmentName,
|
|
32
|
+
url,
|
|
33
|
+
},
|
|
34
|
+
fullName: envVarContext.fullName,
|
|
35
|
+
slug: envVarContext.environmentSlug,
|
|
36
|
+
shortName: env,
|
|
37
|
+
envVars,
|
|
38
|
+
secretEnvVarKeys,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Config, EnvConfigWithComponent } from "../types/config";
|
|
2
|
+
|
|
3
|
+
import type { CommitInfo } from "../types/context";
|
|
4
|
+
import type { EnvironmentContext } from "../types/environmentContext";
|
|
5
|
+
import { getEnvConfig } from "./getEnvConfig";
|
|
6
|
+
import { getEnvType } from "./getEnvType";
|
|
7
|
+
|
|
8
|
+
const getEnvironmentSlug = (
|
|
9
|
+
envConfig: EnvConfigWithComponent,
|
|
10
|
+
env: string,
|
|
11
|
+
componentName: string,
|
|
12
|
+
commitInfo?: CommitInfo
|
|
13
|
+
) => {
|
|
14
|
+
const envType = getEnvType(env, envConfig);
|
|
15
|
+
|
|
16
|
+
return envType === "review" && commitInfo
|
|
17
|
+
? `${env}-${commitInfo.reviewSlug}-${componentName}`
|
|
18
|
+
: `${env}-${componentName}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getEnvironmentContext = (
|
|
22
|
+
config: Config,
|
|
23
|
+
env: string,
|
|
24
|
+
componentName: string,
|
|
25
|
+
commitInfo?: CommitInfo
|
|
26
|
+
): EnvironmentContext<any, any> => {
|
|
27
|
+
const envConfigRaw = getEnvConfig(config, componentName, env);
|
|
28
|
+
const envType = getEnvType(env, envConfigRaw);
|
|
29
|
+
|
|
30
|
+
const environmentSlug = getEnvironmentSlug(
|
|
31
|
+
envConfigRaw,
|
|
32
|
+
env,
|
|
33
|
+
componentName,
|
|
34
|
+
commitInfo
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const gitlabEnvironmentName =
|
|
38
|
+
envType === "review" && commitInfo
|
|
39
|
+
? `${env}/${commitInfo.refName}/${componentName}`
|
|
40
|
+
: `${env}/${componentName}`;
|
|
41
|
+
|
|
42
|
+
const fullName = `${config.customerName}-${config.appName}-${environmentSlug}`;
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
envConfigRaw,
|
|
46
|
+
deployConfigRaw: envConfigRaw.deploy,
|
|
47
|
+
buildConfigRaw: envConfigRaw.build,
|
|
48
|
+
environmentSlug,
|
|
49
|
+
gitlabEnvironmentName,
|
|
50
|
+
fullName,
|
|
51
|
+
envType,
|
|
52
|
+
commitInfo,
|
|
53
|
+
componentName,
|
|
54
|
+
env,
|
|
55
|
+
fullConfig: config,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { isObject, merge } from "lodash";
|
|
2
|
+
import { DEPLOY_TYPES } from "../deploy";
|
|
3
|
+
import type { CommitInfo, Context } from "../types";
|
|
4
|
+
import type { Config, DevLocalEnvConfig } from "../types/config";
|
|
5
|
+
|
|
6
|
+
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
7
|
+
import {
|
|
8
|
+
resolveReferences,
|
|
9
|
+
translateLegacyFromComponents,
|
|
10
|
+
} from "./resolveReferences";
|
|
11
|
+
|
|
12
|
+
export const getEnvironmentVariables = async (
|
|
13
|
+
config: Config,
|
|
14
|
+
componentName: string,
|
|
15
|
+
env: string,
|
|
16
|
+
commitInfo?: CommitInfo,
|
|
17
|
+
alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
|
|
18
|
+
): Promise<{
|
|
19
|
+
envVars: Record<string, string>;
|
|
20
|
+
secretEnvVarKeys: string[];
|
|
21
|
+
host: string;
|
|
22
|
+
url: string;
|
|
23
|
+
}> => {
|
|
24
|
+
const environmentContext = getEnvironmentContext(
|
|
25
|
+
config,
|
|
26
|
+
env,
|
|
27
|
+
componentName,
|
|
28
|
+
commitInfo
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const { envConfigRaw, deployConfigRaw, envType } = environmentContext;
|
|
32
|
+
|
|
33
|
+
const basePredefinedVariables = {
|
|
34
|
+
ENV_SHORT: env,
|
|
35
|
+
APP_DIR: envConfigRaw.dir,
|
|
36
|
+
ENV_TYPE: envType,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let predefinedVariables: Record<string, string>;
|
|
40
|
+
let host: string;
|
|
41
|
+
let url: string;
|
|
42
|
+
|
|
43
|
+
if (envType === "local") {
|
|
44
|
+
const devLocalConfig: DevLocalEnvConfig = envConfigRaw;
|
|
45
|
+
const port = devLocalConfig.port ?? 3000;
|
|
46
|
+
host = "localhost:" + port;
|
|
47
|
+
url = "http://" + host;
|
|
48
|
+
predefinedVariables = {
|
|
49
|
+
ENV_SHORT: "local",
|
|
50
|
+
ROOT_URL: url,
|
|
51
|
+
PORT: port.toString(),
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
const additionalEnvVars = deployConfigRaw
|
|
55
|
+
? DEPLOY_TYPES[deployConfigRaw.type].getAdditionalEnvVars(
|
|
56
|
+
environmentContext
|
|
57
|
+
)
|
|
58
|
+
: {};
|
|
59
|
+
|
|
60
|
+
host =
|
|
61
|
+
envConfigRaw?.host ??
|
|
62
|
+
additionalEnvVars.HOST_CANONICAL ??
|
|
63
|
+
"unknown-host.example.com";
|
|
64
|
+
url = `https://${host}`;
|
|
65
|
+
|
|
66
|
+
predefinedVariables = {
|
|
67
|
+
...basePredefinedVariables,
|
|
68
|
+
HOST: host,
|
|
69
|
+
ROOT_URL: url,
|
|
70
|
+
...additionalEnvVars,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const publicEnvVarsRaw = envConfigRaw.vars?.public ?? {};
|
|
74
|
+
|
|
75
|
+
const additionalSecretKeys = deployConfigRaw
|
|
76
|
+
? DEPLOY_TYPES[deployConfigRaw.type].additionalSecretKeys(
|
|
77
|
+
environmentContext
|
|
78
|
+
)
|
|
79
|
+
: [];
|
|
80
|
+
|
|
81
|
+
const secretEnvVarKeys = [
|
|
82
|
+
...(envConfigRaw.vars?.secret ?? []),
|
|
83
|
+
...additionalSecretKeys,
|
|
84
|
+
];
|
|
85
|
+
const secretEnvVars = Object.fromEntries(
|
|
86
|
+
secretEnvVarKeys.map((key) => [
|
|
87
|
+
key,
|
|
88
|
+
`$${getSecretVarName(env, componentName, key)}`,
|
|
89
|
+
])
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// this is deprecated, we now support: $componentname:FOO
|
|
93
|
+
const legacyFromComponents = envConfigRaw.vars?.fromComponents ?? {};
|
|
94
|
+
const publicEnvVarsRawWithLegasyFromComponents = merge(
|
|
95
|
+
{},
|
|
96
|
+
translateLegacyFromComponents(legacyFromComponents),
|
|
97
|
+
publicEnvVarsRaw
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const publicEnvVarsRawSanitized = Object.fromEntries(
|
|
101
|
+
Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(
|
|
102
|
+
([key, value]) => [
|
|
103
|
+
key,
|
|
104
|
+
isObject(value) ? JSON.stringify(value) : `${value}`,
|
|
105
|
+
]
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const envVarsRaw = addIndexVar({
|
|
110
|
+
...predefinedVariables,
|
|
111
|
+
...secretEnvVars,
|
|
112
|
+
...publicEnvVarsRawSanitized,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const envVars = await resolveReferences(
|
|
116
|
+
envVarsRaw,
|
|
117
|
+
async (otherComponentName, variableName, alreadyVisited) => {
|
|
118
|
+
const { envVars: otherEnvVars } = await getEnvironmentVariables(
|
|
119
|
+
config,
|
|
120
|
+
env,
|
|
121
|
+
otherComponentName,
|
|
122
|
+
commitInfo,
|
|
123
|
+
alreadyVisited
|
|
124
|
+
);
|
|
125
|
+
return otherEnvVars[variableName];
|
|
126
|
+
},
|
|
127
|
+
alreadyVisited
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
envVars,
|
|
132
|
+
secretEnvVarKeys,
|
|
133
|
+
host,
|
|
134
|
+
url,
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const sanitizeForEnVar = (s: string) => s.replace(/-/g, "_");
|
|
139
|
+
|
|
140
|
+
export const getSecretVarName = (
|
|
141
|
+
env: string,
|
|
142
|
+
componentName: string,
|
|
143
|
+
key: string
|
|
144
|
+
) => `CL_${sanitizeForEnVar(env)}_${sanitizeForEnVar(componentName)}_${key}`; // remove dash from component name
|
|
145
|
+
|
|
146
|
+
const addIndexVar = (vars: Record<string, unknown>) => ({
|
|
147
|
+
...vars,
|
|
148
|
+
_ALL_ENV_VAR_KEYS: JSON.stringify(Object.keys(vars)),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export const getSecretVarNameForContext = (context: Context, key: string) =>
|
|
152
|
+
getSecretVarName(context.environment.shortName, context.componentName, key);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import slugify from "slugify";
|
|
2
|
+
import type { Context } from "../types";
|
|
3
|
+
|
|
4
|
+
const sanitize = (value?: string) => {
|
|
5
|
+
if (!value) return value;
|
|
6
|
+
//"The value can only contain lowercase letters, numeric characters, underscores and dashes. The value can be at most 63 characters long. International characters are allowed."
|
|
7
|
+
// slugify should do the job
|
|
8
|
+
return slugify(value).toLowerCase();
|
|
9
|
+
};
|
|
10
|
+
export const getLabels = (context: Context) => {
|
|
11
|
+
const labels = {
|
|
12
|
+
"customer-name": sanitize(context.fullConfig.customerName),
|
|
13
|
+
"app-name": sanitize(context.fullConfig.appName),
|
|
14
|
+
"env-type": sanitize(context.environment.envType),
|
|
15
|
+
"env-name": sanitize(context.environment.shortName),
|
|
16
|
+
"build-type": sanitize(context.componentConfig.build?.type),
|
|
17
|
+
...(context.fullConfig.meta?.labels ?? {}),
|
|
18
|
+
};
|
|
19
|
+
return labels;
|
|
20
|
+
};
|