@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-prettier-cbceeed9
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-dev.js +3 -0
- package/bin/catladder-gitlab.js +1 -1
- package/dist/build/base/createBuildJob.d.ts +2 -2
- package/dist/build/base/createBuildJob.js +15 -30
- package/dist/build/base/writeBuildInfo.d.ts +2 -0
- package/dist/build/base/{getBuildInfo.js → writeBuildInfo.js} +3 -6
- package/dist/build/custom/buildJob.d.ts +3 -0
- package/dist/build/custom/buildJob.js +83 -0
- package/dist/build/custom/index.d.ts +3 -0
- package/dist/build/custom/index.js +40 -0
- package/dist/build/docker.d.ts +33 -9
- package/dist/build/docker.js +51 -54
- package/dist/build/index.d.ts +6 -5
- package/dist/build/index.js +20 -6
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/buildJob.js +3 -25
- package/dist/build/node/cache.d.ts +2 -2
- package/dist/build/node/cache.js +19 -22
- package/dist/build/node/index.d.ts +1 -1
- package/dist/build/node/index.js +3 -16
- package/dist/build/node/meteor.d.ts +1 -1
- package/dist/build/node/meteor.js +9 -20
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +7 -21
- package/dist/build/node/yarn.d.ts +1 -1
- package/dist/build/node/yarn.js +14 -15
- package/dist/build/rails/build.d.ts +3 -0
- package/dist/build/rails/build.js +51 -0
- package/dist/build/rails/index.d.ts +3 -0
- package/dist/build/rails/index.js +41 -0
- package/dist/build/rails/test.d.ts +3 -0
- package/dist/build/rails/test.js +94 -0
- package/dist/build/types.d.ts +84 -9
- package/dist/build/types.js +0 -4
- package/dist/bundles/catladder-gitlab/index.js +32979 -0
- package/dist/catladder-gitlab.js +7 -26
- package/dist/config/{configruedEnvs.test.d.ts → __tests__/configruedEnvs.test.d.ts} +0 -0
- package/dist/config/{configruedEnvs.test.js → __tests__/configruedEnvs.test.js} +10 -12
- package/dist/config/configruedEnvs.d.ts +1 -1
- package/dist/config/configruedEnvs.js +7 -22
- package/dist/config/index.js +0 -4
- package/dist/config/readConfig.d.ts +1 -1
- package/dist/config/readConfig.js +2 -13
- package/dist/constants.js +1 -1
- package/dist/context/{resolveReferences.test.d.ts → __tests__/resolveReferences.test.d.ts} +0 -0
- package/dist/context/__tests__/resolveReferences.test.js +336 -0
- package/dist/context/getEnvConfig.d.ts +2 -0
- package/dist/context/getEnvConfig.js +18 -0
- package/dist/context/getEnvType.d.ts +4 -0
- package/dist/context/getEnvType.js +13 -0
- package/dist/context/getEnvironment.d.ts +3 -0
- package/dist/{pipeline/createChildPipeline.test.js → context/getEnvironment.js} +42 -84
- package/dist/context/getEnvironmentContext.d.ts +4 -0
- package/dist/context/getEnvironmentContext.js +33 -0
- package/dist/context/getEnvironmentVariables.d.ts +10 -0
- package/dist/context/getEnvironmentVariables.js +260 -0
- package/dist/context/getLabels.d.ts +8 -0
- package/dist/context/getLabels.js +38 -0
- package/dist/context/index.d.ts +5 -6
- package/dist/context/index.js +158 -208
- package/dist/context/resolveReferences.d.ts +1 -3
- package/dist/context/resolveReferences.js +213 -52
- package/dist/defaults/index.d.ts +1 -1
- package/dist/deploy/base.d.ts +4 -2
- package/dist/deploy/base.js +38 -33
- package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
- package/dist/deploy/cloudRun/deployJob.js +238 -0
- package/dist/deploy/cloudRun/index.d.ts +4 -0
- package/dist/deploy/cloudRun/index.js +112 -0
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +11 -0
- package/dist/deploy/cloudRun/utils/createArgsString.js +55 -0
- package/dist/deploy/cloudRun/utils/database.d.ts +4 -0
- package/dist/deploy/cloudRun/utils/database.js +64 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +10 -0
- package/dist/deploy/cloudRun/utils/jobName.d.ts +1 -0
- package/dist/deploy/cloudRun/utils/jobName.js +8 -0
- package/dist/deploy/custom/deployJob.d.ts +2 -2
- package/dist/deploy/custom/deployJob.js +10 -16
- package/dist/deploy/custom/index.d.ts +2 -1
- package/dist/deploy/custom/index.js +14 -19
- package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
- package/dist/deploy/dockerTag/deployJob.js +24 -0
- package/dist/deploy/dockerTag/index.d.ts +2 -0
- package/dist/deploy/dockerTag/index.js +17 -0
- package/dist/deploy/index.d.ts +12 -8
- package/dist/deploy/index.js +7 -20
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
- package/dist/deploy/kubernetes/additionalSecretKeys.js +24 -0
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +13 -0
- package/dist/deploy/kubernetes/cloudSql/index.js +30 -0
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +17 -91
- package/dist/deploy/kubernetes/index.d.ts +3 -1
- package/dist/deploy/kubernetes/index.js +42 -4
- package/dist/deploy/kubernetes/kubeEnv.d.ts +9 -0
- package/dist/deploy/kubernetes/kubeEnv.js +72 -0
- package/dist/deploy/kubernetes/kubeValues.d.ts +97 -0
- package/dist/deploy/kubernetes/kubeValues.js +124 -0
- package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
- package/dist/deploy/kubernetes/mongodb.js +96 -10
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +25 -21
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +2 -10
- package/dist/deploy/types/base.d.ts +14 -0
- package/dist/deploy/types/base.js +3 -0
- package/dist/deploy/types/custom.d.ts +33 -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 +121 -0
- package/dist/deploy/types/googleCloudRun.js +3 -0
- package/dist/deploy/types/index.d.ts +22 -0
- package/dist/deploy/types/index.js +31 -0
- package/dist/deploy/types/kubernetes.d.ts +276 -0
- package/dist/deploy/types/kubernetes.js +3 -0
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/deploy/utils.js +3 -10
- package/dist/index.js +0 -10
- package/dist/pipeline/commitInfo/getBuildId.d.ts +1 -0
- package/dist/pipeline/commitInfo/getBuildId.js +135 -0
- package/dist/pipeline/commitInfo/getCommitInfo.d.ts +2 -0
- package/dist/pipeline/commitInfo/getCommitInfo.js +140 -0
- package/dist/pipeline/createAllJobs.d.ts +8 -0
- package/dist/{build/tests/storybook.test.js → pipeline/createAllJobs.js} +54 -104
- package/dist/pipeline/createChildPipeline.d.ts +2 -2
- package/dist/pipeline/createChildPipeline.js +40 -121
- package/dist/pipeline/createJobsForComponent.d.ts +3 -0
- package/dist/pipeline/{createJobs.js → createJobsForComponent.js} +33 -192
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +14 -0
- package/dist/pipeline/gitlab/createGitlabJobs.js +260 -0
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.js +1 -5
- package/dist/pipeline/packageManager.d.ts +1 -1
- package/dist/pipeline/packageManager.js +20 -173
- package/dist/pipeline/yarn/yarnUtils.d.ts +4 -0
- package/dist/pipeline/yarn/yarnUtils.js +193 -0
- package/dist/rules/index.d.ts +3 -1
- package/dist/rules/index.js +7 -6
- package/dist/runner/index.d.ts +2 -3
- package/dist/runner/index.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +19 -25
- package/dist/types/config.js +6 -16
- package/dist/types/context.d.ts +16 -3
- package/dist/types/environmentContext.d.ts +28 -0
- package/dist/types/environmentContext.js +3 -0
- package/dist/types/gitlab-types.d.ts +39 -7
- package/dist/types/index.js +0 -6
- package/dist/types/jobs.d.ts +25 -17
- package/dist/types/jobs.js +1 -1
- package/dist/types/pipeline.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.js +3 -0
- package/dist/utils/gitlab.d.ts +5 -0
- package/dist/utils/gitlab.js +48 -0
- package/dist/utils/index.js +5 -15
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +1560 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +1560 -0
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +1560 -0
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3092 -0
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +3103 -0
- package/examples/__snapshots__/custom-build-job.ts.snap +1162 -0
- package/examples/__snapshots__/custom-envs.ts.snap +261 -0
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +2280 -0
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +4077 -0
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
- package/examples/__snapshots__/wait-for-other-deploy.ts.snap +1626 -0
- package/examples/__utils__/helpers.ts +14 -0
- package/examples/cloud-run-memory-limit.ts +28 -0
- package/examples/cloud-run-no-cpu-throttling.ts +33 -0
- package/examples/cloud-run-non-public.ts +27 -0
- package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
- package/examples/cloud-run-with-sql.ts +61 -0
- package/examples/custom-build-job.ts +28 -0
- package/examples/custom-envs.ts +31 -0
- package/examples/kubernetes-application-customization.ts +57 -0
- package/examples/kubernetes-with-jobs.ts +68 -0
- package/examples/rails-k8s-with-worker.ts +95 -0
- package/examples/wait-for-other-deploy.ts +36 -0
- package/package.json +16 -13
- package/scripts/bundle +2 -0
- package/src/build/base/createBuildJob.ts +12 -5
- package/src/build/base/{getBuildInfo.ts → writeBuildInfo.ts} +2 -2
- package/src/build/custom/buildJob.ts +64 -0
- package/src/build/custom/index.ts +7 -0
- package/src/build/docker.ts +58 -33
- package/src/build/index.ts +24 -5
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +19 -8
- 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/rails/build.ts +38 -0
- package/src/build/rails/index.ts +8 -0
- package/src/build/rails/test.ts +86 -0
- package/src/build/types.ts +97 -2
- package/src/catladder-gitlab.ts +4 -2
- package/src/config/{configruedEnvs.test.ts → __tests__/configruedEnvs.test.ts} +3 -3
- package/src/config/configruedEnvs.ts +2 -7
- package/src/config/readConfig.ts +1 -1
- package/src/context/{resolveReferences.test.ts → __tests__/resolveReferences.test.ts} +23 -38
- 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 +155 -0
- package/src/context/getLabels.ts +20 -0
- package/src/context/index.ts +28 -193
- package/src/context/resolveReferences.ts +35 -31
- package/src/defaults/index.ts +1 -1
- package/src/deploy/base.ts +43 -19
- package/src/deploy/cloudRun/deployJob.ts +276 -0
- package/src/deploy/cloudRun/index.ts +95 -0
- package/src/deploy/cloudRun/utils/createArgsString.ts +26 -0
- package/src/deploy/cloudRun/utils/database.ts +55 -0
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
- package/src/deploy/cloudRun/utils/jobName.ts +2 -0
- package/src/deploy/custom/deployJob.ts +13 -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/index.ts +28 -0
- package/src/deploy/kubernetes/deployJob.ts +21 -78
- package/src/deploy/kubernetes/index.ts +42 -1
- package/src/deploy/kubernetes/kubeEnv.ts +48 -0
- package/src/deploy/kubernetes/kubeValues.ts +96 -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 +36 -0
- package/src/deploy/types/dockerTag.ts +12 -0
- package/src/deploy/types/googleCloudRun.ts +179 -0
- package/src/deploy/types/index.ts +28 -0
- package/src/deploy/types/kubernetes.ts +301 -0
- package/src/deploy/utils.ts +6 -2
- package/src/pipeline/commitInfo/getBuildId.ts +6 -0
- package/src/pipeline/commitInfo/getCommitInfo.ts +12 -0
- package/src/pipeline/createAllJobs.ts +38 -0
- package/src/pipeline/createChildPipeline.ts +9 -20
- package/src/pipeline/createJobsForComponent.ts +64 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +149 -0
- package/src/pipeline/index.ts +1 -1
- package/src/pipeline/packageManager.ts +4 -38
- package/src/pipeline/yarn/yarnUtils.ts +37 -0
- package/src/rules/index.ts +9 -6
- package/src/runner/index.ts +2 -1
- package/src/types/config.ts +26 -13
- package/src/types/context.ts +23 -2
- package/src/types/environmentContext.ts +33 -0
- package/src/types/gitlab-types.ts +36 -6
- package/src/types/jobs.ts +30 -6
- package/src/types/pipeline.ts +1 -1
- package/src/types/utils.ts +7 -0
- package/src/utils/gitlab.ts +23 -0
- package/tsconfig.json +3 -1
- package/dist/build/base/getBuildInfo.d.ts +0 -2
- package/dist/build/tests/storybook.test.d.ts +0 -1
- package/dist/context/resolveReferences.test.js +0 -141
- package/dist/deploy/kubernetes/cloudsql.d.ts +0 -6
- package/dist/deploy/kubernetes/cloudsql.js +0 -16
- package/dist/deploy/types.d.ts +0 -196
- package/dist/deploy/types.js +0 -16
- package/dist/pipeline/createChildPipeline.test.d.ts +0 -1
- package/dist/pipeline/createJobs.d.ts +0 -3
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +0 -8
- package/dist/pipeline/gitlab/makeGitlabJob.js +0 -45
- package/src/build/tests/storybook.test.ts +0 -54
- package/src/deploy/kubernetes/cloudsql.ts +0 -12
- package/src/deploy/types.ts +0 -189
- package/src/pipeline/createChildPipeline.test.ts +0 -49
- package/src/pipeline/createJobs.ts +0 -195
- package/src/pipeline/gitlab/makeGitlabJob.ts +0 -16
package/src/context/index.ts
CHANGED
|
@@ -1,216 +1,51 @@
|
|
|
1
|
-
import { isObject, merge } from "lodash";
|
|
2
|
-
import slugify from "slugify";
|
|
3
1
|
import { BUILD_TYPES } from "../build";
|
|
4
|
-
import { BuildConfig } from "../build/types";
|
|
5
|
-
import { DEPLOY_TYPES
|
|
6
|
-
import { DeployConfig } from "../deploy/types";
|
|
7
|
-
import { Config
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
Context,
|
|
11
|
-
Environment,
|
|
12
|
-
PackageManagerInfo,
|
|
13
|
-
} from "../types/context";
|
|
2
|
+
import type { BuildConfig, BuildConfigType } from "../build/types";
|
|
3
|
+
import { DEPLOY_TYPES } from "../deploy";
|
|
4
|
+
import type { DeployConfig, DeployConfigType } from "../deploy/types";
|
|
5
|
+
import type { Config } from "../types/config";
|
|
6
|
+
import type { CommitInfo, Context, PackageManagerInfo } from "../types/context";
|
|
7
|
+
import type { PartialDeep } from "../types/utils";
|
|
14
8
|
import { mergeWithMergingArrays } from "../utils";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
translateLegacyFromComponents,
|
|
18
|
-
} from "./resolveReferences";
|
|
9
|
+
import { getEnvironment } from "./getEnvironment";
|
|
10
|
+
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
env: string,
|
|
23
|
-
componentName: string,
|
|
24
|
-
key: string
|
|
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);
|
|
29
|
-
export const getEnvironment = (
|
|
30
|
-
config: Config,
|
|
31
|
-
componentName: string,
|
|
32
|
-
env: string,
|
|
33
|
-
commitInfo?: CommitInfo,
|
|
34
|
-
alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
|
|
35
|
-
): Environment => {
|
|
36
|
-
const componentConfig = config.components[componentName];
|
|
37
|
-
if (!componentConfig) {
|
|
38
|
-
throw new Error("unknown component " + componentName);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const defaultConfig = componentConfig;
|
|
42
|
-
|
|
43
|
-
const envConfig = componentConfig.env?.[env] ?? {};
|
|
44
|
-
if (envConfig === false) {
|
|
45
|
-
throw new Error("env is disabled: " + env);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const mergedConfig = mergeWithMergingArrays(defaultConfig, envConfig);
|
|
49
|
-
|
|
50
|
-
// env type: if its set manually, use that, otherwise use the known env types
|
|
51
|
-
|
|
52
|
-
const envType = envConfig?.type ?? (isKnowEnvType(env) ? env : null);
|
|
53
|
-
|
|
54
|
-
if (!envType) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
"Missing type in environment " + env + " in component " + componentName
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const basePredefinedVariables = {
|
|
61
|
-
ENV_SHORT: env,
|
|
62
|
-
APP_DIR: componentConfig.dir,
|
|
63
|
-
ENV_TYPE: envType,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const environmentName =
|
|
67
|
-
envType === "review" && commitInfo
|
|
68
|
-
? `${env}/${commitInfo.refName}/${componentName}`
|
|
69
|
-
: `${env}/${componentName}`;
|
|
70
|
-
|
|
71
|
-
const environmentSlug =
|
|
72
|
-
envType === "review" && commitInfo
|
|
73
|
-
? `${env}-${commitInfo.reviewSlug}-${componentName}`
|
|
74
|
-
: `${env}-${componentName}`;
|
|
12
|
+
export * from "./getEnvironment";
|
|
13
|
+
export * from "./getEnvironmentVariables";
|
|
75
14
|
|
|
76
|
-
|
|
77
|
-
let host: string;
|
|
78
|
-
let url: string;
|
|
79
|
-
if (envType === "local") {
|
|
80
|
-
const devLocalConfig: DevLocalEnvConfig = mergedConfig;
|
|
81
|
-
const port = devLocalConfig.port ?? 3000;
|
|
82
|
-
host = "localhost:" + port;
|
|
83
|
-
url = "http://" + host;
|
|
84
|
-
predefinedVariables = {
|
|
85
|
-
ENV_SHORT: "local",
|
|
86
|
-
ROOT_URL: url,
|
|
87
|
-
PORT: port.toString(),
|
|
88
|
-
};
|
|
89
|
-
} else {
|
|
90
|
-
const RELEASE_NAME = `${config.customerName}-${config.appName}-${environmentSlug}`;
|
|
91
|
-
|
|
92
|
-
const componentSlug = slugify(componentName);
|
|
93
|
-
const envInUrl =
|
|
94
|
-
envType === "review" && commitInfo ? `${commitInfo.reviewSlug}.${env}` : env;
|
|
95
|
-
|
|
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";
|
|
102
|
-
|
|
103
|
-
const HOST_CANONICAL = `${componentSlug}.${envInUrl}.${config.appName}.${config.customerName}.${domainCanonical}`;
|
|
104
|
-
host = mergedConfig?.host ?? HOST_CANONICAL;
|
|
105
|
-
const url = `https://${host}`;
|
|
106
|
-
|
|
107
|
-
// FIXME: move to kube specific jobs
|
|
108
|
-
const KUBE_APP_NAME =
|
|
109
|
-
envType === "review" && commitInfo
|
|
110
|
-
? `${commitInfo.reviewSlug}-${componentName}`
|
|
111
|
-
: componentName;
|
|
112
|
-
const KUBE_NAMESPACE = getKubernetesNamespace(config, env);
|
|
113
|
-
|
|
114
|
-
predefinedVariables = {
|
|
115
|
-
...basePredefinedVariables,
|
|
116
|
-
HOST_CANONICAL,
|
|
117
|
-
ROOT_URL: url,
|
|
118
|
-
KUBE_NAMESPACE,
|
|
119
|
-
KUBE_APP_NAME,
|
|
120
|
-
RELEASE_NAME,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
const publicEnvVarsRaw = mergedConfig.vars?.public ?? {};
|
|
124
|
-
const secretEnvVarKeys = mergedConfig.vars?.secret ?? [];
|
|
125
|
-
const secretEnvVars = Object.fromEntries(
|
|
126
|
-
secretEnvVarKeys.map((key) => [
|
|
127
|
-
key,
|
|
128
|
-
`$${getSecretVarName(env, componentName, key)}`,
|
|
129
|
-
])
|
|
130
|
-
);
|
|
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 = {
|
|
150
|
-
...predefinedVariables,
|
|
151
|
-
...secretEnvVars,
|
|
152
|
-
...publicEnvVarsRawSanitized,
|
|
153
|
-
};
|
|
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
|
-
);
|
|
169
|
-
return {
|
|
170
|
-
envType,
|
|
171
|
-
host,
|
|
172
|
-
fullName: environmentName,
|
|
173
|
-
slug: environmentSlug,
|
|
174
|
-
shortName: env,
|
|
175
|
-
url: predefinedVariables.ROOT_URL,
|
|
176
|
-
envVars,
|
|
177
|
-
secretEnvVarKeys,
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export const createContext = (
|
|
15
|
+
export const createContext = async (
|
|
182
16
|
config: Config,
|
|
183
17
|
componentName: string,
|
|
184
18
|
env: string,
|
|
185
19
|
commitInfo?: CommitInfo,
|
|
186
20
|
packageManagerInfo?: PackageManagerInfo
|
|
187
|
-
): Context => {
|
|
21
|
+
): Promise<Context> => {
|
|
188
22
|
if (!/^[a-z0-9-]+$/.test(componentName)) {
|
|
189
23
|
throw new Error(
|
|
190
24
|
"componentName may only contain lower case letters, numbers and -"
|
|
191
25
|
);
|
|
192
26
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const componentConfigWithoutDefaults = mergeWithMergingArrays(
|
|
200
|
-
rawConfig,
|
|
201
|
-
envConfig
|
|
27
|
+
|
|
28
|
+
const envContext = getEnvironmentContext(
|
|
29
|
+
config,
|
|
30
|
+
env,
|
|
31
|
+
componentName,
|
|
32
|
+
commitInfo
|
|
202
33
|
);
|
|
203
34
|
|
|
204
|
-
|
|
35
|
+
const componentConfigWithoutDefaults = envContext.envConfigRaw;
|
|
205
36
|
const defaults: {
|
|
206
|
-
build:
|
|
207
|
-
deploy:
|
|
37
|
+
build: PartialDeep<BuildConfig>;
|
|
38
|
+
deploy: PartialDeep<DeployConfig>;
|
|
208
39
|
} = componentConfigWithoutDefaults.deploy
|
|
209
40
|
? {
|
|
210
41
|
build:
|
|
211
|
-
BUILD_TYPES[
|
|
42
|
+
BUILD_TYPES[
|
|
43
|
+
componentConfigWithoutDefaults.build.type as BuildConfigType
|
|
44
|
+
].defaults(envContext),
|
|
212
45
|
deploy:
|
|
213
|
-
DEPLOY_TYPES[
|
|
46
|
+
DEPLOY_TYPES[
|
|
47
|
+
componentConfigWithoutDefaults.deploy.type as DeployConfigType
|
|
48
|
+
].defaults(envContext),
|
|
214
49
|
}
|
|
215
50
|
: {
|
|
216
51
|
build: {},
|
|
@@ -225,7 +60,7 @@ export const createContext = (
|
|
|
225
60
|
fullConfig: config,
|
|
226
61
|
componentConfig,
|
|
227
62
|
componentName,
|
|
228
|
-
environment: getEnvironment(config, componentName, env, commitInfo),
|
|
63
|
+
environment: await getEnvironment(config, componentName, env, commitInfo),
|
|
229
64
|
commitInfo,
|
|
230
65
|
packageManagerInfo,
|
|
231
66
|
};
|
|
@@ -1,55 +1,59 @@
|
|
|
1
1
|
import { merge } from "lodash";
|
|
2
|
+
import replaceAsync from "string-replace-async";
|
|
2
3
|
|
|
3
4
|
const REGEX = /\$\{(([^:]+):)?([^}]+)}/gm;
|
|
4
5
|
|
|
5
|
-
export const resolveReferences = (
|
|
6
|
+
export const resolveReferences = async (
|
|
6
7
|
vars: Record<string, string>,
|
|
7
8
|
getOtherVariables?: (
|
|
8
9
|
componentName: string,
|
|
9
|
-
variableName: string,
|
|
10
10
|
alreadyVisited: Record<string, Record<string, boolean>>
|
|
11
|
-
) => string | null
|
|
11
|
+
) => Promise<Record<string, string | null>>,
|
|
12
12
|
alreadyVisitedBase: Record<string, Record<string, boolean>> = {}
|
|
13
13
|
) => {
|
|
14
|
-
const replaceSingleValue = (
|
|
14
|
+
const replaceSingleValue = async (
|
|
15
15
|
value: string,
|
|
16
16
|
alreadyVisited: Record<string, Record<string, boolean>> = alreadyVisitedBase
|
|
17
|
-
): string => {
|
|
17
|
+
): Promise<string> => {
|
|
18
18
|
if (REGEX.test(value)) {
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
return await replaceAsync(
|
|
20
|
+
value,
|
|
21
|
+
REGEX,
|
|
22
|
+
async (match, _, componentName, variableName) => {
|
|
23
|
+
if (alreadyVisited[componentName]?.[variableName]) {
|
|
24
|
+
return match; // prevent endless loop
|
|
25
|
+
}
|
|
26
|
+
const newAlreadyVisited = merge({}, alreadyVisited, {
|
|
27
|
+
[componentName]: {
|
|
28
|
+
[variableName]: true,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const result = componentName
|
|
32
|
+
? (await getOtherVariables?.(componentName, newAlreadyVisited).then(
|
|
33
|
+
(r) => r?.[variableName]
|
|
34
|
+
)) ?? null
|
|
35
|
+
: vars[variableName]; // is self reference
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const replaced =
|
|
38
|
+
result !== null && result !== undefined
|
|
39
|
+
? await replaceSingleValue(result, newAlreadyVisited)
|
|
40
|
+
: match;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
return replaced;
|
|
43
|
+
}
|
|
44
|
+
);
|
|
43
45
|
} else {
|
|
44
46
|
return value;
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
return Object.fromEntries(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await Promise.all(
|
|
52
|
+
Object.entries(vars).map(async ([key, value]) => {
|
|
53
|
+
return [key, await replaceSingleValue(value)];
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
) as Record<string, string>;
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
export const translateLegacyFromComponents = (
|
package/src/defaults/index.ts
CHANGED
package/src/deploy/base.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { requiresDockerBuild } from "../build/docker";
|
|
2
|
-
import { Context } from "../types";
|
|
3
|
-
import { CatladderJob } from "../types/jobs";
|
|
1
|
+
import { getDockerImageVariables, requiresDockerBuild } from "../build/docker";
|
|
2
|
+
import type { Context } from "../types";
|
|
3
|
+
import type { CatladderJob } from "../types/jobs";
|
|
4
|
+
import { isOfDeployType } from "./types";
|
|
4
5
|
import { contextIsStoppable } from "./utils";
|
|
5
6
|
|
|
6
7
|
export const DEPLOY_JOB_NAME = "🚀 Deploy";
|
|
7
8
|
export const STOP_JOB_NAME = "🛑 Stop ⚠️";
|
|
9
|
+
export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
|
|
8
10
|
|
|
9
11
|
const DEPLOY_RUNNER_VARIABLES = {
|
|
10
12
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
@@ -14,20 +16,16 @@ const DEPLOY_RUNNER_VARIABLES = {
|
|
|
14
16
|
};
|
|
15
17
|
type JobWithoutScript = Omit<CatladderJob, "script">;
|
|
16
18
|
export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
17
|
-
const environment = {
|
|
18
|
-
name: context.environment.fullName,
|
|
19
|
-
url: context.environment.url,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
19
|
const hasDocker = requiresDockerBuild(context);
|
|
23
20
|
const isStoppable = contextIsStoppable(context);
|
|
24
21
|
|
|
25
22
|
const autoStop =
|
|
26
23
|
context.environment.envType === "review"
|
|
27
|
-
? "
|
|
24
|
+
? "2 week"
|
|
28
25
|
: context.environment.envType === "dev"
|
|
29
|
-
? "
|
|
26
|
+
? "4 weeks"
|
|
30
27
|
: undefined;
|
|
28
|
+
|
|
31
29
|
// if auto or manual is configured explicitly, use that
|
|
32
30
|
const whenDeployDefined =
|
|
33
31
|
context.componentConfig.deploy && context.componentConfig.deploy.when
|
|
@@ -45,6 +43,14 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
45
43
|
return {
|
|
46
44
|
name: DEPLOY_JOB_NAME,
|
|
47
45
|
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
46
|
+
|
|
47
|
+
needs: context.componentConfig.deploy
|
|
48
|
+
? context.componentConfig.deploy.waitFor?.map((c) => ({
|
|
49
|
+
componentName: c,
|
|
50
|
+
job: DEPLOY_JOB_NAME,
|
|
51
|
+
artifacts: false,
|
|
52
|
+
})) ?? undefined
|
|
53
|
+
: undefined,
|
|
48
54
|
// we don't want to deploy when there is a broken test
|
|
49
55
|
needsStages: [
|
|
50
56
|
{
|
|
@@ -56,7 +62,6 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
56
62
|
artifacts: false,
|
|
57
63
|
},
|
|
58
64
|
], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
|
|
59
|
-
|
|
60
65
|
rules: [
|
|
61
66
|
whenDeploy === "auto"
|
|
62
67
|
? {
|
|
@@ -71,9 +76,10 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
71
76
|
variables: {
|
|
72
77
|
...DEPLOY_RUNNER_VARIABLES,
|
|
73
78
|
...context.environment.envVars,
|
|
79
|
+
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
74
80
|
},
|
|
75
81
|
environment: {
|
|
76
|
-
...environment,
|
|
82
|
+
...context.environment.gitlabEnvironment,
|
|
77
83
|
...(isStoppable
|
|
78
84
|
? {
|
|
79
85
|
on_stop: STOP_JOB_NAME,
|
|
@@ -87,15 +93,10 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
87
93
|
export const getBaseDeploymentStopJob = (
|
|
88
94
|
context: Context
|
|
89
95
|
): JobWithoutScript => {
|
|
90
|
-
const environment = {
|
|
91
|
-
name: context.environment.fullName,
|
|
92
|
-
url: context.environment.url,
|
|
93
|
-
};
|
|
94
96
|
return {
|
|
95
97
|
name: STOP_JOB_NAME,
|
|
96
98
|
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
97
|
-
|
|
98
|
-
needs: [DEPLOY_JOB_NAME],
|
|
99
|
+
needs: [], // can be executed even if the deploy job failed
|
|
99
100
|
rules: [
|
|
100
101
|
{
|
|
101
102
|
if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
|
|
@@ -113,8 +114,31 @@ export const getBaseDeploymentStopJob = (
|
|
|
113
114
|
},
|
|
114
115
|
stage: "stop",
|
|
115
116
|
environment: {
|
|
116
|
-
...environment,
|
|
117
|
+
...context.environment.gitlabEnvironment,
|
|
117
118
|
action: "stop",
|
|
118
119
|
},
|
|
119
120
|
};
|
|
120
121
|
};
|
|
122
|
+
|
|
123
|
+
export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
|
|
124
|
+
return {
|
|
125
|
+
name: ROLLBACK_JOB_NAME,
|
|
126
|
+
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
127
|
+
needs: [], // can be executed even if the deploy job failed
|
|
128
|
+
rules: [
|
|
129
|
+
{
|
|
130
|
+
when: "manual",
|
|
131
|
+
allow_failure: true,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
variables: {
|
|
135
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
136
|
+
GIT_STRATEGY: "none",
|
|
137
|
+
},
|
|
138
|
+
stage: "rollback",
|
|
139
|
+
environment: {
|
|
140
|
+
...context.environment.gitlabEnvironment,
|
|
141
|
+
action: "access",
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
};
|