@catladder/pipeline 1.170.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash/BashExpression.d.ts +2 -6
- package/dist/bash/BashExpression.js +5 -15
- package/dist/bash/bashEscape.d.ts +34 -0
- package/dist/bash/bashEscape.js +114 -0
- package/dist/bash/bashYaml.js +25 -2
- package/dist/bash/getInjectVarsScript.js +4 -2
- package/dist/bash/index.d.ts +2 -0
- package/dist/bash/index.js +26 -0
- package/dist/build/base/createAppBuildJob.js +3 -3
- package/dist/build/base/writeDotEnv.js +6 -4
- package/dist/build/custom/testJob.js +12 -12
- package/dist/build/docker.d.ts +3 -3
- package/dist/build/node/buildJob.js +1 -1
- package/dist/build/node/cache.d.ts +2 -4
- package/dist/build/node/cache.js +3 -24
- package/dist/build/node/testJob.js +11 -11
- package/dist/build/rails/build.js +1 -1
- package/dist/build/rails/test.js +8 -8
- package/dist/build/types.d.ts +0 -10
- package/dist/constants.js +1 -1
- package/dist/context/createComponentContext.js +0 -1
- package/dist/context/getEnvConfig.js +2 -1
- package/dist/context/getEnvironment.js +1 -2
- package/dist/context/getEnvironmentVariables.d.ts +5 -6
- package/dist/context/getEnvironmentVariables.js +50 -38
- package/dist/deploy/base/deploy.js +3 -3
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +2 -2
- package/dist/deploy/cloudRun/index.js +2 -2
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +2 -2
- package/dist/deploy/kubernetes/cloudSql/index.js +3 -14
- package/dist/deploy/kubernetes/deployJob.js +1 -3
- package/dist/deploy/kubernetes/index.js +2 -2
- package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -3
- package/dist/deploy/kubernetes/kubeValues.d.ts +3 -4
- package/dist/deploy/kubernetes/kubeValues.js +2 -3
- package/dist/deploy/types/base.d.ts +0 -6
- package/dist/deploy/types/kubernetes.d.ts +1 -34
- package/dist/globalScriptFunctions/index.d.ts +14 -0
- package/dist/globalScriptFunctions/index.js +37 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/pipeline/gitlab/createGitlabJobs.js +3 -5
- package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +1 -0
- package/dist/pipeline/gitlab/createGitlabPipeline.js +38 -2
- package/dist/pipeline/packageManager.js +1 -1
- package/dist/runner/index.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +6 -9
- package/dist/types/context.d.ts +2 -9
- package/dist/types/gitlab-types.d.ts +1 -0
- package/dist/types/jobs.d.ts +0 -8
- package/dist/utils/gitlab.js +4 -1
- package/dist/utils/writeFiles.js +1 -7
- package/dist/variables/VariableValue.d.ts +3 -0
- package/dist/variables/VariableValue.js +5 -0
- package/dist/variables/VariableValueContainingReferences.d.ts +24 -0
- package/dist/variables/VariableValueContainingReferences.js +97 -0
- package/dist/variables/__tests__/resolveAllReferences.test.js +219 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.js +171 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.js +202 -0
- package/dist/variables/__tests__/variableValue.test.d.ts +1 -0
- package/dist/variables/__tests__/variableValue.test.js +36 -0
- package/dist/variables/resolveAllReferences.d.ts +3 -0
- package/dist/{bash/replaceAsync.js → variables/resolveAllReferences.js} +60 -41
- package/dist/variables/resolveAllReferencesOnce.d.ts +5 -0
- package/dist/variables/resolveAllReferencesOnce.js +191 -0
- package/dist/variables/resolveReferencesOnce.d.ts +8 -0
- package/dist/variables/resolveReferencesOnce.js +22 -0
- package/examples/__snapshots__/cloud-run-http2.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +312 -222
- package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +1436 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +316 -238
- package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +313 -238
- package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +316 -238
- package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +294 -220
- package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +652 -486
- package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +282 -288
- package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +312 -238
- package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +284 -194
- package/examples/__snapshots__/custom-build-job.test.ts.snap +278 -188
- package/examples/__snapshots__/custom-deploy.test.ts.snap +220 -154
- package/examples/__snapshots__/custom-envs.test.ts.snap +216 -126
- package/examples/__snapshots__/custom-sbom-java.test.ts.snap +278 -188
- package/examples/__snapshots__/git-submodule.test.ts.snap +312 -238
- package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +231 -253
- package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +240 -262
- package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +504 -506
- package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +239 -261
- package/examples/__snapshots__/local-dot-env.test.ts.snap +236 -238
- package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +236 -242
- package/examples/__snapshots__/multiline-var.test.ts.snap +1355 -973
- package/examples/__snapshots__/native-app.test.ts.snap +438 -392
- package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +312 -238
- package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +312 -238
- package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +186 -188
- package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +162 -164
- package/examples/__snapshots__/referencing-other-vars.test.ts.snap +4741 -0
- package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +330 -228
- package/examples/__snapshots__/{workspace-api-www-custom-cache.test.ts.snap → workspace-api-www-turbo-cache.test.ts.snap} +457 -499
- package/examples/__snapshots__/workspace-api-www.test.ts.snap +452 -482
- package/examples/{workspace-api-www-custom-cache.test.ts → cloud-run-nextjs.test.ts} +2 -2
- package/examples/cloud-run-nextjs.ts +28 -0
- package/examples/cloud-run-with-sql.ts +0 -1
- package/examples/kubernetes-application-customization.ts +1 -0
- package/examples/kubernetes-with-cloud-sql.ts +1 -0
- package/examples/kubernetes-with-jobs.ts +1 -0
- package/examples/kubernetes-with-mongodb.ts +1 -0
- package/examples/meteor-kubernetes.ts +1 -1
- package/examples/native-app.ts +10 -7
- package/examples/rails-k8s-with-worker.ts +7 -1
- package/examples/{kubernetes-with-cloud-sql-legacy.test.ts → referencing-other-vars.test.ts} +2 -2
- package/examples/referencing-other-vars.ts +83 -0
- package/examples/workspace-api-www-turbo-cache.test.ts +11 -0
- package/examples/{workspace-api-www-custom-cache.ts → workspace-api-www-turbo-cache.ts} +4 -3
- package/examples/workspace-api-www.ts +3 -2
- package/package.json +2 -6
- package/src/bash/BashExpression.ts +10 -13
- package/src/bash/bashEscape.ts +158 -0
- package/src/bash/bashYaml.ts +36 -2
- package/src/bash/getInjectVarsScript.ts +11 -2
- package/src/bash/index.ts +2 -0
- package/src/build/base/createAppBuildJob.ts +0 -1
- package/src/build/base/writeDotEnv.ts +6 -6
- package/src/build/custom/testJob.ts +0 -1
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +0 -29
- package/src/build/node/testJob.ts +0 -1
- package/src/build/rails/build.ts +0 -1
- package/src/build/rails/test.ts +0 -1
- package/src/build/types.ts +0 -13
- package/src/context/createComponentContext.ts +0 -1
- package/src/context/getEnvConfig.ts +2 -2
- package/src/context/getEnvironment.ts +1 -1
- package/src/context/getEnvironmentContext.ts +1 -1
- package/src/context/getEnvironmentVariables.ts +44 -51
- package/src/deploy/base/deploy.ts +1 -1
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +4 -12
- package/src/deploy/cloudRun/index.ts +2 -2
- package/src/deploy/kubernetes/cloudSql/index.ts +3 -16
- package/src/deploy/kubernetes/deployJob.ts +0 -2
- package/src/deploy/kubernetes/index.ts +2 -2
- package/src/deploy/kubernetes/kubeEnv.ts +3 -3
- package/src/deploy/kubernetes/kubeValues.ts +5 -8
- package/src/deploy/types/base.ts +0 -6
- package/src/deploy/types/kubernetes.ts +1 -36
- package/src/globalScriptFunctions/index.ts +30 -0
- package/src/index.ts +2 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +1 -4
- package/src/pipeline/gitlab/createGitlabPipeline.ts +8 -1
- package/src/pipeline/packageManager.ts +7 -5
- package/src/runner/index.ts +0 -1
- package/src/types/config.ts +6 -9
- package/src/types/context.ts +3 -9
- package/src/types/gitlab-types.ts +1 -0
- package/src/types/jobs.ts +0 -8
- package/src/utils/gitlab.ts +19 -2
- package/src/utils/writeFiles.ts +1 -2
- package/src/variables/VariableValue.ts +6 -0
- package/src/variables/VariableValueContainingReferences.ts +89 -0
- package/src/variables/__tests__/resolveAllReferences.test.ts +110 -0
- package/src/variables/__tests__/resolveAllReferencesOnce.test.ts +64 -0
- package/src/variables/__tests__/resolveReferencesOnce.test.ts +117 -0
- package/src/variables/__tests__/variableValue.test.ts +73 -0
- package/src/variables/resolveAllReferences.ts +46 -0
- package/src/variables/resolveAllReferencesOnce.ts +44 -0
- package/src/variables/resolveReferencesOnce.ts +29 -0
- package/bin/catladder-gitlab-dev.js +0 -3
- package/bin/catladder-gitlab.js +0 -3
- package/dist/bash/replaceAsync.d.ts +0 -2
- package/dist/bundles/catladder-gitlab/index.js +0 -15
- package/dist/context/__tests__/resolveReferences.test.js +0 -368
- package/dist/context/resolveReferences.d.ts +0 -6
- package/dist/context/resolveReferences.js +0 -286
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +0 -85
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +0 -33
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.test.ts.snap +0 -1795
- package/examples/kubernetes-with-cloud-sql-legacy.ts +0 -35
- package/scripts/bundle +0 -2
- package/src/bash/replaceAsync.ts +0 -54
- package/src/context/__tests__/resolveReferences.test.ts +0 -148
- package/src/context/resolveReferences.ts +0 -93
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +0 -35
- /package/dist/{context/__tests__/resolveReferences.test.d.ts → variables/__tests__/resolveAllReferences.test.d.ts} +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../src";
|
|
2
|
-
|
|
3
|
-
const config: Config = {
|
|
4
|
-
appName: "test-app",
|
|
5
|
-
customerName: "pan",
|
|
6
|
-
components: {
|
|
7
|
-
api: {
|
|
8
|
-
dir: "api",
|
|
9
|
-
build: {
|
|
10
|
-
type: "node",
|
|
11
|
-
},
|
|
12
|
-
deploy: {
|
|
13
|
-
type: "kubernetes",
|
|
14
|
-
cluster: {
|
|
15
|
-
name: "some-cluster-name",
|
|
16
|
-
region: "europe-west6",
|
|
17
|
-
projectId: "some-project-id",
|
|
18
|
-
type: "gcloud",
|
|
19
|
-
domainCanonical: "panter.cloud",
|
|
20
|
-
},
|
|
21
|
-
values: {
|
|
22
|
-
cloudsql: {
|
|
23
|
-
enabled: true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default config;
|
|
32
|
-
|
|
33
|
-
export const information = {
|
|
34
|
-
title: "K8s: With Cloud SQL Legacy",
|
|
35
|
-
};
|
package/scripts/bundle
DELETED
package/src/bash/replaceAsync.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { BashExpression, bashEscape } from "./BashExpression";
|
|
2
|
-
|
|
3
|
-
// from https://github.com/dsblv/string-replace-async/blob/main/index.js
|
|
4
|
-
// and adjusted a bit
|
|
5
|
-
export default async function replaceAsync(
|
|
6
|
-
string: string | BashExpression,
|
|
7
|
-
searchValue: any,
|
|
8
|
-
replacer: (
|
|
9
|
-
substring: string,
|
|
10
|
-
...args: any[]
|
|
11
|
-
) => Promise<string | BashExpression>,
|
|
12
|
-
) {
|
|
13
|
-
const wasBashExpression = string instanceof BashExpression;
|
|
14
|
-
|
|
15
|
-
const stringRepresentation = wasBashExpression
|
|
16
|
-
? string.toString()
|
|
17
|
-
: bashEscape(string);
|
|
18
|
-
try {
|
|
19
|
-
// 1. Run fake pass of `replace`, collect values from `replacer` calls
|
|
20
|
-
// 2. Resolve them with `Promise.all`
|
|
21
|
-
// 3. Run `replace` with resolved values
|
|
22
|
-
const values: Array<Promise<string | BashExpression>> = [];
|
|
23
|
-
String.prototype.replace.call(
|
|
24
|
-
stringRepresentation,
|
|
25
|
-
searchValue,
|
|
26
|
-
function (...args) {
|
|
27
|
-
// eslint-disable-next-line prefer-spread
|
|
28
|
-
const result = replacer.apply(undefined, args);
|
|
29
|
-
values.push(result);
|
|
30
|
-
return "";
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
const resolvedValues = await Promise.all(values);
|
|
34
|
-
|
|
35
|
-
const containsBashExpression = resolvedValues.some(
|
|
36
|
-
(value) => value instanceof BashExpression,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const result = String.prototype.replace.call(
|
|
40
|
-
stringRepresentation,
|
|
41
|
-
searchValue,
|
|
42
|
-
function () {
|
|
43
|
-
return resolvedValues.shift()?.toString() ?? "";
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
if (wasBashExpression || containsBashExpression) {
|
|
47
|
-
return new BashExpression(result);
|
|
48
|
-
} else {
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
return Promise.reject(error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { BashExpression } from "../../bash/BashExpression";
|
|
2
|
-
import {
|
|
3
|
-
resolveReferences,
|
|
4
|
-
translateLegacyFromComponents,
|
|
5
|
-
} from "../resolveReferences";
|
|
6
|
-
|
|
7
|
-
const unpackBashExpressions = (obj: Record<string, string | BashExpression>) =>
|
|
8
|
-
Object.fromEntries(
|
|
9
|
-
Object.entries(obj).map(([key, value]) => [key, value.toString()]),
|
|
10
|
-
);
|
|
11
|
-
describe("resolveReferences", () => {
|
|
12
|
-
it("replaces occurences of ${componentName:VARIABLE_NAME}", async () => {
|
|
13
|
-
const variables = {
|
|
14
|
-
a: "hello world",
|
|
15
|
-
b: "a replaced value looks like this: '${api:FOO}', nice!",
|
|
16
|
-
};
|
|
17
|
-
const otherVariables: Record<string, Record<string, string>> = {
|
|
18
|
-
api: {
|
|
19
|
-
FOO: "foo from api",
|
|
20
|
-
},
|
|
21
|
-
frontend: {
|
|
22
|
-
FOO: "foo from frontend",
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
const result = await resolveReferences(variables, async (componentName) => {
|
|
26
|
-
return otherVariables[componentName];
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
30
|
-
a: "hello world",
|
|
31
|
-
b: "a replaced value looks like this: 'foo from api', nice!",
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("replaces self references with structure ${VARIABLE_NAME}", async () => {
|
|
36
|
-
const variables = {
|
|
37
|
-
FOO: "hello world",
|
|
38
|
-
BAR: "this: ${FOO}!",
|
|
39
|
-
};
|
|
40
|
-
const result = await resolveReferences(variables);
|
|
41
|
-
|
|
42
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
43
|
-
FOO: "hello world",
|
|
44
|
-
BAR: "this: hello world!",
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("replaces self references mixed with other vars", async () => {
|
|
49
|
-
const variables = {
|
|
50
|
-
FOO: "hello from ${api:FOO}",
|
|
51
|
-
BAR: "this: ${FOO}!",
|
|
52
|
-
};
|
|
53
|
-
const otherVariables: Record<string, Record<string, string>> = {
|
|
54
|
-
api: {
|
|
55
|
-
FOO: "foo from api",
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const result = await resolveReferences(variables, async (componentName) => {
|
|
59
|
-
return otherVariables[componentName];
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
63
|
-
FOO: "hello from foo from api",
|
|
64
|
-
BAR: "this: hello from foo from api!",
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("keeps variables as is if not found (when null is returned)", async () => {
|
|
69
|
-
const variables = {
|
|
70
|
-
a: "hello world",
|
|
71
|
-
b: "a not found value looks like this: '${api:FOO}'",
|
|
72
|
-
};
|
|
73
|
-
const otherVariables: Record<string, Record<string, string>> = {};
|
|
74
|
-
const result = await resolveReferences(variables, async (componentName) => {
|
|
75
|
-
return otherVariables[componentName];
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
79
|
-
a: "hello world",
|
|
80
|
-
b: "a not found value looks like this: '${api:FOO}'",
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("replaces mulitple levels deep", async () => {
|
|
85
|
-
const variables = {
|
|
86
|
-
a: "value is ${frontend:FOO}!",
|
|
87
|
-
};
|
|
88
|
-
const otherVariables: Record<string, Record<string, string>> = {
|
|
89
|
-
api: {
|
|
90
|
-
FOO: "foo from api",
|
|
91
|
-
},
|
|
92
|
-
frontend: {
|
|
93
|
-
FOO: "hi, ${api:FOO}",
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const result = await resolveReferences(variables, async (componentName) => {
|
|
97
|
-
return otherVariables[componentName];
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
101
|
-
a: "value is hi, foo from api!",
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("prevents endless loops", async () => {
|
|
106
|
-
const variables = {
|
|
107
|
-
a: "value is ${frontend:FOO}!",
|
|
108
|
-
};
|
|
109
|
-
const otherVariables: Record<string, Record<string, string>> = {
|
|
110
|
-
api: {
|
|
111
|
-
FOO: "api ${frontend:FOO}",
|
|
112
|
-
},
|
|
113
|
-
frontend: {
|
|
114
|
-
FOO: "frontend ${api:FOO}",
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
const result = await resolveReferences(variables, async (componentName) => {
|
|
118
|
-
return otherVariables[componentName];
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
expect(unpackBashExpressions(result)).toEqual({
|
|
122
|
-
a: "value is frontend api ${frontend:FOO}!",
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("translateLegacyFromComponents", () => {
|
|
128
|
-
it("translatetes the old `fromComponents` approach to ${componentName:variableName}", () => {
|
|
129
|
-
const fromComponents = {
|
|
130
|
-
api: {
|
|
131
|
-
API_FOO: "FOO",
|
|
132
|
-
API_BAR: "BAR",
|
|
133
|
-
},
|
|
134
|
-
www: {
|
|
135
|
-
WWW_X: "X",
|
|
136
|
-
WWW_Y: "Y",
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const result = translateLegacyFromComponents(fromComponents);
|
|
141
|
-
expect(result).toEqual({
|
|
142
|
-
API_FOO: "${api:FOO}",
|
|
143
|
-
API_BAR: "${api:BAR}",
|
|
144
|
-
WWW_X: "${www:X}",
|
|
145
|
-
WWW_Y: "${www:Y}",
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { merge } from "lodash";
|
|
2
|
-
|
|
3
|
-
import type { BashExpression } from "../bash/BashExpression";
|
|
4
|
-
import replaceAsync from "../bash/replaceAsync";
|
|
5
|
-
import type { UnspecifiedEnvVars } from "..";
|
|
6
|
-
|
|
7
|
-
// regex to resolve references in catladder variables
|
|
8
|
-
// those expressions have the pattern ${componentName:variableName}
|
|
9
|
-
const REGEX = /\$\{(([^:}]+):)?([^}]+)}/gm;
|
|
10
|
-
|
|
11
|
-
export const resolveReferences = async (
|
|
12
|
-
vars: Record<string, string | BashExpression | undefined | null>,
|
|
13
|
-
getOtherVariables?: (
|
|
14
|
-
componentName: string,
|
|
15
|
-
alreadyVisited: Record<string, Record<string, boolean>>,
|
|
16
|
-
) => Promise<UnspecifiedEnvVars>,
|
|
17
|
-
alreadyVisitedBase: Record<string, Record<string, boolean>> = {},
|
|
18
|
-
) => {
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* replace referenced variables with their values in a value string
|
|
22
|
-
*/
|
|
23
|
-
const replaceSingleValue = async (
|
|
24
|
-
value: string | BashExpression,
|
|
25
|
-
alreadyVisited: Record<
|
|
26
|
-
string,
|
|
27
|
-
Record<string, boolean>
|
|
28
|
-
> = alreadyVisitedBase,
|
|
29
|
-
): Promise<string | BashExpression> => {
|
|
30
|
-
if (REGEX.test(value.toString())) {
|
|
31
|
-
// we consider variables that got references in it BashExpressions, because the replacement may be one
|
|
32
|
-
|
|
33
|
-
return await replaceAsync(
|
|
34
|
-
value,
|
|
35
|
-
REGEX,
|
|
36
|
-
async (match, _, componentName, variableName) => {
|
|
37
|
-
if (alreadyVisited[componentName]?.[variableName]) {
|
|
38
|
-
return match; // prevent endless loop
|
|
39
|
-
}
|
|
40
|
-
const newAlreadyVisited = merge({}, alreadyVisited, {
|
|
41
|
-
[componentName]: {
|
|
42
|
-
[variableName]: true,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
const result = componentName
|
|
46
|
-
? (await getOtherVariables?.(componentName, newAlreadyVisited).then(
|
|
47
|
-
(r) => r?.[variableName],
|
|
48
|
-
)) ?? null
|
|
49
|
-
: vars[variableName]; // is self reference
|
|
50
|
-
|
|
51
|
-
const replaced =
|
|
52
|
-
result !== null && result !== undefined
|
|
53
|
-
? await replaceSingleValue(result, newAlreadyVisited)
|
|
54
|
-
: match;
|
|
55
|
-
|
|
56
|
-
return replaced;
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
} else {
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return Object.fromEntries(
|
|
65
|
-
await Promise.all(
|
|
66
|
-
Object.entries(vars).map(async ([key, value]) => {
|
|
67
|
-
if (value === null || value === undefined) {
|
|
68
|
-
return [key, null];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return [
|
|
72
|
-
key,
|
|
73
|
-
value !== null && value !== undefined
|
|
74
|
-
? await replaceSingleValue(value)
|
|
75
|
-
: null,
|
|
76
|
-
];
|
|
77
|
-
}),
|
|
78
|
-
),
|
|
79
|
-
) as Record<string, BashExpression>;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const translateLegacyFromComponents = (
|
|
83
|
-
fromComponents: Record<string, Record<string, string>>,
|
|
84
|
-
) => {
|
|
85
|
-
return Object.fromEntries(
|
|
86
|
-
Object.entries(fromComponents).flatMap(([componentName, variables]) => {
|
|
87
|
-
return Object.entries(variables).map(([ourName, otherName]) => [
|
|
88
|
-
ourName,
|
|
89
|
-
"${" + componentName + ":" + otherName + "}",
|
|
90
|
-
]);
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { omit } from "lodash";
|
|
2
|
-
import type { DeployConfigKubernetesValues } from "../types";
|
|
3
|
-
import type { StringOrBashExpression } from "../../bash/BashExpression";
|
|
4
|
-
|
|
5
|
-
export const processSecretsAsFiles = <
|
|
6
|
-
T extends {
|
|
7
|
-
env: {
|
|
8
|
-
secret: Record<string, StringOrBashExpression>;
|
|
9
|
-
};
|
|
10
|
-
} & DeployConfigKubernetesValues,
|
|
11
|
-
>(
|
|
12
|
-
values: T,
|
|
13
|
-
): T => {
|
|
14
|
-
if (!values.secretsAsFile || values.secretsAsFile.length === 0) {
|
|
15
|
-
return values;
|
|
16
|
-
}
|
|
17
|
-
// the initial idea was that we "shadow" secrets that we mount as files,
|
|
18
|
-
// but there is a weird kubernetes issue with that (https://github.com/kubernetes/kubernetes/issues/46861),
|
|
19
|
-
// so instead we rename the secrets and append _content, so that inside kuberentes, we can use the original name to contain the path and name+_content as the actual content
|
|
20
|
-
return {
|
|
21
|
-
...values,
|
|
22
|
-
env: {
|
|
23
|
-
...values.env,
|
|
24
|
-
secret: {
|
|
25
|
-
...omit(values.env.secret, values.secretsAsFile),
|
|
26
|
-
...Object.fromEntries(
|
|
27
|
-
values.secretsAsFile.map((key) => [
|
|
28
|
-
key + "_content",
|
|
29
|
-
values.env.secret[key],
|
|
30
|
-
]),
|
|
31
|
-
),
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
File without changes
|