@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,11 +1,11 @@
|
|
|
1
1
|
import { createYamlLocalPipeline } from "./__utils__/helpers";
|
|
2
|
-
import config from "./
|
|
2
|
+
import config from "./cloud-run-nextjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* This test is auto-generated.
|
|
6
6
|
* Modifications will be overwritten on every `yarn test` run!
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
it("matches snapshot for
|
|
9
|
+
it("matches snapshot for cloud-run-nextjs local pipeline YAML", async () => {
|
|
10
10
|
expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
|
|
11
11
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
appName: "test-app",
|
|
5
|
+
customerName: "pan",
|
|
6
|
+
components: {
|
|
7
|
+
www: {
|
|
8
|
+
dir: "www",
|
|
9
|
+
build: {
|
|
10
|
+
type: "node",
|
|
11
|
+
cache: {
|
|
12
|
+
paths: [".next/cache"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
deploy: {
|
|
16
|
+
type: "google-cloudrun",
|
|
17
|
+
projectId: "google-project-id",
|
|
18
|
+
region: "europe-west6",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default config;
|
|
25
|
+
|
|
26
|
+
export const information = {
|
|
27
|
+
title: "Cloud Run: With SQL",
|
|
28
|
+
};
|
package/examples/native-app.ts
CHANGED
|
@@ -16,7 +16,6 @@ const config: Config = {
|
|
|
16
16
|
components: {
|
|
17
17
|
app: {
|
|
18
18
|
dir: "app",
|
|
19
|
-
dotEnv: true,
|
|
20
19
|
vars: {
|
|
21
20
|
public: {
|
|
22
21
|
GRAPHQL_URL: "${api:ROOT_URL}/graphql",
|
|
@@ -28,9 +27,11 @@ const config: Config = {
|
|
|
28
27
|
],
|
|
29
28
|
},
|
|
30
29
|
build: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
jobVars: {
|
|
31
|
+
public: {
|
|
32
|
+
LC_A: "L=en_US.UTF-8",
|
|
33
|
+
LANG: "en_US.UTF-8",
|
|
34
|
+
},
|
|
34
35
|
},
|
|
35
36
|
type: "node",
|
|
36
37
|
buildCommand: [
|
|
@@ -46,9 +47,11 @@ const config: Config = {
|
|
|
46
47
|
|
|
47
48
|
deploy: {
|
|
48
49
|
type: "custom",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
jobVars: {
|
|
51
|
+
public: {
|
|
52
|
+
LC_A: "L=en_US.UTF-8",
|
|
53
|
+
LANG: "en_US.UTF-8",
|
|
54
|
+
},
|
|
52
55
|
},
|
|
53
56
|
requiresDocker: false,
|
|
54
57
|
script: [
|
|
@@ -9,6 +9,8 @@ const config: Config = {
|
|
|
9
9
|
components: {
|
|
10
10
|
app: {
|
|
11
11
|
dir: ".",
|
|
12
|
+
dotEnv: false,
|
|
13
|
+
envDTs: false,
|
|
12
14
|
vars: {
|
|
13
15
|
public: {
|
|
14
16
|
RAILS_ENV: "production",
|
|
@@ -44,7 +46,11 @@ const config: Config = {
|
|
|
44
46
|
domainCanonical: "panter.cloud",
|
|
45
47
|
},
|
|
46
48
|
values: {
|
|
47
|
-
cloudsql: {
|
|
49
|
+
cloudsql: {
|
|
50
|
+
enabled: true,
|
|
51
|
+
type: "unmanaged",
|
|
52
|
+
instanceConnectionName: "myproject:europe-west6:instance-name",
|
|
53
|
+
},
|
|
48
54
|
application: {
|
|
49
55
|
// if deployed to Google Cloud Run use a gem like cloudtasker instead of a permanently running expensive worker
|
|
50
56
|
worker: {
|
package/examples/{kubernetes-with-cloud-sql-legacy.test.ts → referencing-other-vars.test.ts}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createYamlLocalPipeline } from "./__utils__/helpers";
|
|
2
|
-
import config from "./
|
|
2
|
+
import config from "./referencing-other-vars";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* This test is auto-generated.
|
|
6
6
|
* Modifications will be overwritten on every `yarn test` run!
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
it("matches snapshot for
|
|
9
|
+
it("matches snapshot for referencing-other-vars local pipeline YAML", async () => {
|
|
10
10
|
expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
|
|
11
11
|
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
appName: "test-app",
|
|
5
|
+
customerName: "pan",
|
|
6
|
+
components: {
|
|
7
|
+
app1: {
|
|
8
|
+
dir: "app1",
|
|
9
|
+
build: {
|
|
10
|
+
type: "node",
|
|
11
|
+
},
|
|
12
|
+
vars: {
|
|
13
|
+
secret: ["SECRET1"],
|
|
14
|
+
public: {
|
|
15
|
+
foo: "foo-value",
|
|
16
|
+
bar: "bar-value",
|
|
17
|
+
foo3: "from app3: ${app3:foo3}",
|
|
18
|
+
circle:
|
|
19
|
+
'this is from app3 that has reference to app1: "${app3:transitive}"', // not officially recommended, but may work in some cases
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
deploy: {
|
|
23
|
+
type: "google-cloudrun",
|
|
24
|
+
projectId: "asdf",
|
|
25
|
+
region: "asia-east1",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
app2: {
|
|
29
|
+
dir: "app2",
|
|
30
|
+
build: {
|
|
31
|
+
type: "node",
|
|
32
|
+
},
|
|
33
|
+
vars: {
|
|
34
|
+
secret: ["SECRET2"],
|
|
35
|
+
public: {
|
|
36
|
+
foo2: "foo-value-2",
|
|
37
|
+
referencingSecret: "secret1: ${app1:SECRET1}, secret2: ${SECRET2}",
|
|
38
|
+
foo1: "this is from app1: ${app1:foo}",
|
|
39
|
+
selfReference: "this is from self: ${foo2}",
|
|
40
|
+
selfReference2: "this is from self: ${foo1}",
|
|
41
|
+
app1Api: "${app1:ROOT_URL}/graphql",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
deploy: {
|
|
45
|
+
type: "google-cloudrun",
|
|
46
|
+
projectId: "asdf",
|
|
47
|
+
region: "asia-east1",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
app3: {
|
|
51
|
+
dir: "kube",
|
|
52
|
+
build: {
|
|
53
|
+
type: "node",
|
|
54
|
+
},
|
|
55
|
+
vars: {
|
|
56
|
+
public: {
|
|
57
|
+
foo3: "foo-value-3",
|
|
58
|
+
foo2: "this is from app2: ${app2:foo2}",
|
|
59
|
+
transitive: "this is from app2: ${app2:foo1}",
|
|
60
|
+
transitiveWithSecret: "this is from app2: ${app2:referencingSecret}",
|
|
61
|
+
someJson:
|
|
62
|
+
'[{"name": "app1", "url": "${app1:ROOT_URL}"}, {"name": "app2", "url": "${app2:ROOT_URL}"}, {"name": "app3", "url": "${ROOT_URL}"}]',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
deploy: {
|
|
66
|
+
type: "kubernetes",
|
|
67
|
+
cluster: {
|
|
68
|
+
name: "some-cluster-name",
|
|
69
|
+
region: "europe-west6",
|
|
70
|
+
projectId: "some-project-id",
|
|
71
|
+
type: "gcloud",
|
|
72
|
+
domainCanonical: "panter.cloud",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default config;
|
|
80
|
+
|
|
81
|
+
export const information = {
|
|
82
|
+
title: "Multiline Environment Variables",
|
|
83
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createYamlLocalPipeline } from "./__utils__/helpers";
|
|
2
|
+
import config from "./workspace-api-www-turbo-cache";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This test is auto-generated.
|
|
6
|
+
* Modifications will be overwritten on every `yarn test` run!
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
it("matches snapshot for workspace-api-www-turbo-cache local pipeline YAML", async () => {
|
|
10
|
+
expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
|
|
11
|
+
});
|
|
@@ -12,13 +12,12 @@ const config: Config = {
|
|
|
12
12
|
myWorkspace: {
|
|
13
13
|
type: "node",
|
|
14
14
|
cache: {
|
|
15
|
-
paths: [".
|
|
15
|
+
paths: [".turbo"],
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
components: {
|
|
20
20
|
api: {
|
|
21
|
-
dotEnv: true,
|
|
22
21
|
dir: "api",
|
|
23
22
|
build: {
|
|
24
23
|
from: "myWorkspace",
|
|
@@ -29,10 +28,12 @@ const config: Config = {
|
|
|
29
28
|
deploy: DEPLOY_CONFIG,
|
|
30
29
|
},
|
|
31
30
|
www: {
|
|
32
|
-
dotEnv: true,
|
|
33
31
|
dir: "www",
|
|
34
32
|
build: {
|
|
35
33
|
from: "myWorkspace",
|
|
34
|
+
cache: {
|
|
35
|
+
paths: [".next/cache"],
|
|
36
|
+
},
|
|
36
37
|
},
|
|
37
38
|
deploy: DEPLOY_CONFIG,
|
|
38
39
|
vars: {
|
|
@@ -15,7 +15,6 @@ const config: Config = {
|
|
|
15
15
|
},
|
|
16
16
|
components: {
|
|
17
17
|
api: {
|
|
18
|
-
dotEnv: true,
|
|
19
18
|
dir: "api",
|
|
20
19
|
build: {
|
|
21
20
|
from: "myWorkspace",
|
|
@@ -23,10 +22,12 @@ const config: Config = {
|
|
|
23
22
|
deploy: DEPLOY_CONFIG,
|
|
24
23
|
},
|
|
25
24
|
www: {
|
|
26
|
-
dotEnv: true,
|
|
27
25
|
dir: "www",
|
|
28
26
|
build: {
|
|
29
27
|
from: "myWorkspace",
|
|
28
|
+
cache: {
|
|
29
|
+
paths: [".next/cache"],
|
|
30
|
+
},
|
|
30
31
|
},
|
|
31
32
|
deploy: DEPLOY_CONFIG,
|
|
32
33
|
vars: {
|
package/package.json
CHANGED
|
@@ -53,11 +53,10 @@
|
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
55
|
"license": "MIT",
|
|
56
|
-
"version": "
|
|
56
|
+
"version": "2.0.0",
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build:tsc": "yarn tsc",
|
|
59
|
-
"build": "yarn build:compile && yarn build:inline-variables
|
|
60
|
-
"build:bundle": "./scripts/bundle",
|
|
59
|
+
"build": "yarn build:compile && yarn build:inline-variables",
|
|
61
60
|
"build:compile": "yarn tsc",
|
|
62
61
|
"build:inline-variables": "yarn babel --keep-file-extension --extensions \".ts,.js\" --config-file ./babel-inline.json dist --out-dir dist",
|
|
63
62
|
"build:watch": "yarn tsc -w",
|
|
@@ -69,9 +68,6 @@
|
|
|
69
68
|
"types": "dist/index.d.ts",
|
|
70
69
|
"main": "dist/index.js",
|
|
71
70
|
"sideEffects": false,
|
|
72
|
-
"bin": {
|
|
73
|
-
"catladder-gitlab": "./bin/catladder-gitlab.js"
|
|
74
|
-
},
|
|
75
71
|
"devDependencies": {
|
|
76
72
|
"@babel/cli": "^7.16.0",
|
|
77
73
|
"@babel/core": "^7.0.0-0",
|
|
@@ -12,6 +12,16 @@ export class BashExpression {
|
|
|
12
12
|
return this.value.toString();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
public replace(
|
|
16
|
+
searchValue: any,
|
|
17
|
+
|
|
18
|
+
replacer: (substring: string, ...args: any[]) => string,
|
|
19
|
+
) {
|
|
20
|
+
return new BashExpression(
|
|
21
|
+
this.value.toString().replace(searchValue, replacer),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
/**
|
|
16
26
|
*
|
|
17
27
|
* @returns a bash expression to lowercase the string
|
|
@@ -66,16 +76,3 @@ export const joinBashExpressions = (
|
|
|
66
76
|
return parts.join(joiner);
|
|
67
77
|
}
|
|
68
78
|
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* escapes a string or bash expression for bash
|
|
72
|
-
* it mainly escapes double quotes
|
|
73
|
-
*/
|
|
74
|
-
export const bashEscape = (value: StringOrBashExpression | any) => {
|
|
75
|
-
if (value instanceof BashExpression) {
|
|
76
|
-
return value.toString(); // no need to escape bash expressions, as we want them to evaluate
|
|
77
|
-
}
|
|
78
|
-
// we wrap it in double quotes, so we need to escape them
|
|
79
|
-
if (typeof value === "string") return value.replace(/"/g, '\\"');
|
|
80
|
-
return value;
|
|
81
|
-
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { registerGlobalScriptFunction } from "../globalScriptFunctions";
|
|
2
|
+
import type { VariableValue } from "../variables/VariableValue";
|
|
3
|
+
import { VariableValueContainingReferences } from "../variables/VariableValueContainingReferences";
|
|
4
|
+
import { BashExpression } from "./BashExpression";
|
|
5
|
+
|
|
6
|
+
export type QuotesEscapeMode = "single" | "double";
|
|
7
|
+
|
|
8
|
+
export type EscapeOptions = {
|
|
9
|
+
quotes?: QuotesEscapeMode | false;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* escapes a string or bash expression for bash
|
|
13
|
+
* it either can escape single or double quotes (double is default)
|
|
14
|
+
*/
|
|
15
|
+
export const bashEscape = (
|
|
16
|
+
value: VariableValue | any,
|
|
17
|
+
options: EscapeOptions = {
|
|
18
|
+
quotes: "double",
|
|
19
|
+
},
|
|
20
|
+
) => {
|
|
21
|
+
if (value instanceof BashExpression) {
|
|
22
|
+
// no need to escape
|
|
23
|
+
return escapeBashExpression(value, options);
|
|
24
|
+
}
|
|
25
|
+
if (value instanceof VariableValueContainingReferences) {
|
|
26
|
+
return value.toString(options);
|
|
27
|
+
}
|
|
28
|
+
return escapeString(value, options);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const escapeString = (
|
|
32
|
+
value: string | null | undefined,
|
|
33
|
+
{ quotes }: EscapeOptions = {
|
|
34
|
+
quotes: "double",
|
|
35
|
+
},
|
|
36
|
+
) => {
|
|
37
|
+
const quoteEscaped = quotes
|
|
38
|
+
? quotes === "single"
|
|
39
|
+
? escapeSingleQuotes(value)
|
|
40
|
+
: escapeDoubleQuotes(value)
|
|
41
|
+
: value;
|
|
42
|
+
|
|
43
|
+
return quoteEscaped;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const escapeBashExpression = (
|
|
47
|
+
value: BashExpression,
|
|
48
|
+
options: EscapeOptions,
|
|
49
|
+
) => {
|
|
50
|
+
// no need to escape, we just return the string
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const escapeDoubleQuotes = (value: string | null | undefined) =>
|
|
55
|
+
value?.toString().replace(/"/g, '\\"');
|
|
56
|
+
|
|
57
|
+
export const escapeSingleQuotes = (value: string | null | undefined) =>
|
|
58
|
+
value?.toString().replace(/'/g, "\\'");
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* escape env vars for .env files.
|
|
63
|
+
* unfortunatly, the format has many limitations. In order to be very forgiving, we need to do some magic here:
|
|
64
|
+
*
|
|
65
|
+
* - when the value contains no newlines, we are fine
|
|
66
|
+
* - if the value contains newlines, we need to wrap it in quotes. And thats where the problem begins:
|
|
67
|
+
* - you can't escape quotes. this is a limitation of dotenv and node
|
|
68
|
+
* - you can have inner quotes, but they break in node.js (not in dotenv though), see https://github.com/nodejs/node/issues/54134
|
|
69
|
+
* - so we need to quote cleverly
|
|
70
|
+
* - to make things worse, we need to check whether we have a simple stirng or a bash expression, that needs to be evalulated first...
|
|
71
|
+
*
|
|
72
|
+
* what an absolute nightmare.
|
|
73
|
+
*
|
|
74
|
+
* - other languages are currently only partially supported, since most .env implementations are slightly different
|
|
75
|
+
*/
|
|
76
|
+
export const escapeForDotEnv = (
|
|
77
|
+
value: VariableValue | undefined | null,
|
|
78
|
+
): string => {
|
|
79
|
+
if (value === undefined || value === null) {
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
// if string contains newlines, we need to wrap it in quotes
|
|
84
|
+
// we additionaly escape newlines, that give best compatibility
|
|
85
|
+
if (value.includes("\n")) {
|
|
86
|
+
const newlinesReplaces = value.replace(/\n/g, "\\n");
|
|
87
|
+
|
|
88
|
+
// default to ", but if this is not possible, we try to use ' or `
|
|
89
|
+
const quote = value.includes(`"`)
|
|
90
|
+
? value.includes(`'`)
|
|
91
|
+
? value.includes("`")
|
|
92
|
+
? // If all quote types are present, default to double quotes. This works in dotenv, but not in node.js because of the bug mentioned abouve
|
|
93
|
+
'"'
|
|
94
|
+
: "`"
|
|
95
|
+
: "'"
|
|
96
|
+
: '"';
|
|
97
|
+
|
|
98
|
+
// if we found a quote, we can wrap the string in it
|
|
99
|
+
return `${quote}${newlinesReplaces}${quote}`;
|
|
100
|
+
} else {
|
|
101
|
+
// otherwise we can return as is
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
} else if (value instanceof BashExpression) {
|
|
105
|
+
return escapeBashExpressionForDotEnv(value);
|
|
106
|
+
} else if (value instanceof VariableValueContainingReferences) {
|
|
107
|
+
// instead of doing it part-wise, we just do it all at once
|
|
108
|
+
|
|
109
|
+
const containsAnyBashExpression = value.parts.some(
|
|
110
|
+
(part) => part instanceof BashExpression,
|
|
111
|
+
);
|
|
112
|
+
if (!containsAnyBashExpression) {
|
|
113
|
+
return escapeForDotEnv(
|
|
114
|
+
value.toString({
|
|
115
|
+
quotes: "double",
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
const result = escapeBashExpressionForDotEnv(
|
|
120
|
+
new BashExpression(
|
|
121
|
+
value.toString({
|
|
122
|
+
quotes: "double",
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// basically the same thing as above for bash
|
|
134
|
+
// thx chatgpt for this
|
|
135
|
+
const escapeForDotEnvScript = registerGlobalScriptFunction(
|
|
136
|
+
"escapeForDotEnv",
|
|
137
|
+
`
|
|
138
|
+
input="\${1:-$(cat)}"
|
|
139
|
+
input="\${input//$'\\n'/\\\\n}"
|
|
140
|
+
if [[ "$input" == *\\\\n* ]]; then
|
|
141
|
+
if [[ "$input" == *\\"* && "$input" == *\\'* && "$input" == *\\\`* ]]; then
|
|
142
|
+
printf "\\"%s\\"\\n" "$input" ${/* fallback to double quotes */ ""}
|
|
143
|
+
elif [[ "$input" == *\\"* && "$input" == *\\'* ]]; then
|
|
144
|
+
printf "\`%s\`\\n" "$input"
|
|
145
|
+
elif [[ "$input" == *\\"* ]]; then
|
|
146
|
+
printf "'%s'\\n" "$input"
|
|
147
|
+
else
|
|
148
|
+
printf "\\"%s\\"\\n" "$input"
|
|
149
|
+
fi
|
|
150
|
+
else
|
|
151
|
+
printf "%s\\n" "$input"
|
|
152
|
+
fi
|
|
153
|
+
`,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const escapeBashExpressionForDotEnv = (value: BashExpression) => {
|
|
157
|
+
return value.transformWithCommand(escapeForDotEnvScript.name).toString();
|
|
158
|
+
};
|
package/src/bash/bashYaml.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ScalarTag } from "yaml";
|
|
2
2
|
import { stringify } from "yaml";
|
|
3
3
|
import { BashExpression } from "./BashExpression";
|
|
4
|
+
import { VariableValueContainingReferences } from "../variables/VariableValueContainingReferences";
|
|
4
5
|
|
|
5
6
|
const bashExpressionType: ScalarTag = {
|
|
6
7
|
tag: "",
|
|
@@ -12,12 +13,45 @@ const bashExpressionType: ScalarTag = {
|
|
|
12
13
|
// we create a BLOCK_LITERAL
|
|
13
14
|
// but because bash will interpret the value, it may resolve to a multiline string
|
|
14
15
|
// so we need to indent every line using sed
|
|
15
|
-
return
|
|
16
|
+
return (
|
|
17
|
+
"|-\n" +
|
|
18
|
+
ctx.indent +
|
|
19
|
+
indentNewlinesInBashExpression(node.value, ctx.indent)
|
|
20
|
+
);
|
|
16
21
|
},
|
|
17
22
|
|
|
18
23
|
identify: (v: any) => v instanceof BashExpression,
|
|
19
24
|
};
|
|
20
25
|
|
|
26
|
+
const indentNewlinesInBashExpression = (
|
|
27
|
+
expression: BashExpression,
|
|
28
|
+
indent: string,
|
|
29
|
+
) => {
|
|
30
|
+
return expression.transformWithCommand(`sed '1!s/^/${indent}/'`);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const variableContainingReferences: ScalarTag = {
|
|
34
|
+
tag: "",
|
|
35
|
+
resolve: (str) => {
|
|
36
|
+
// not really needed,but let's make typescript happy
|
|
37
|
+
return new VariableValueContainingReferences(str);
|
|
38
|
+
},
|
|
39
|
+
stringify(node: any, ctx: any) {
|
|
40
|
+
const value: VariableValueContainingReferences = node.value;
|
|
41
|
+
const stringified = value.parts
|
|
42
|
+
.map((part) =>
|
|
43
|
+
part instanceof BashExpression
|
|
44
|
+
? indentNewlinesInBashExpression(part, ctx.indent)
|
|
45
|
+
: // indent every new line
|
|
46
|
+
part.toString().replace(/\n/g, `\n${ctx.indent}`),
|
|
47
|
+
)
|
|
48
|
+
.join("");
|
|
49
|
+
return "|-\n" + ctx.indent + stringified;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
identify: (v: any) => v instanceof VariableValueContainingReferences,
|
|
53
|
+
};
|
|
54
|
+
|
|
21
55
|
/***
|
|
22
56
|
* creates a yaml string that can be used in bash scripts
|
|
23
57
|
* it handles BashExpressions correctly so that they can be evaluated in bash
|
|
@@ -26,7 +60,7 @@ export const yamlBashString = (value: any) => {
|
|
|
26
60
|
return stringify(value, {
|
|
27
61
|
defaultStringType: "BLOCK_LITERAL",
|
|
28
62
|
defaultKeyType: "PLAIN",
|
|
29
|
-
customTags: [bashExpressionType],
|
|
63
|
+
customTags: [bashExpressionType, variableContainingReferences],
|
|
30
64
|
aliasDuplicateObjects: false,
|
|
31
65
|
lineWidth: 0,
|
|
32
66
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnspecifiedEnvVars } from "../types";
|
|
2
2
|
import { isNil } from "lodash";
|
|
3
|
-
import { bashEscape } from "./
|
|
3
|
+
import { bashEscape } from "./bashEscape";
|
|
4
4
|
|
|
5
5
|
export const getInjectVarsScript = (vars?: UnspecifiedEnvVars) => {
|
|
6
6
|
if (!vars) return [];
|
|
@@ -8,5 +8,14 @@ export const getInjectVarsScript = (vars?: UnspecifiedEnvVars) => {
|
|
|
8
8
|
return Object.entries(vars)
|
|
9
9
|
.filter(([, value]) => !isNil(value))
|
|
10
10
|
|
|
11
|
-
.map(
|
|
11
|
+
.map(
|
|
12
|
+
([key, value]) =>
|
|
13
|
+
`export ${key}="${
|
|
14
|
+
value
|
|
15
|
+
? bashEscape(value, {
|
|
16
|
+
quotes: "double",
|
|
17
|
+
})
|
|
18
|
+
: ""
|
|
19
|
+
}"`,
|
|
20
|
+
);
|
|
12
21
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isNil } from "lodash";
|
|
2
|
+
import { escapeForDotEnv } from "../../bash/bashEscape";
|
|
3
|
+
import { ALL_BUILD_VARIABLES } from "../../context/getBuildInfoVariables";
|
|
2
4
|
import type { ComponentContext } from "../../types";
|
|
3
5
|
import { collapseableSection } from "../../utils/gitlab";
|
|
4
|
-
import { ALL_BUILD_VARIABLES } from "../../context/getBuildInfoVariables";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* writes a .env file in the components folder
|
|
@@ -18,14 +19,13 @@ export const writeDotEnv = (context: ComponentContext) => {
|
|
|
18
19
|
// filter out build variables, since they may interfer with caching like turbo
|
|
19
20
|
// build variables are rarely used anyway and we may treat them differently in the future
|
|
20
21
|
.filter(([key]) => !ALL_BUILD_VARIABLES.includes(key))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
22
|
+
|
|
23
|
+
.map(([key, value]) => `${key}=${escapeForDotEnv(value)}`)
|
|
24
24
|
.join("\n");
|
|
25
25
|
|
|
26
26
|
return collapseableSection(
|
|
27
27
|
"write-dotenv-" + context.name,
|
|
28
|
-
"write dot env",
|
|
28
|
+
"write dot env for " + context.name,
|
|
29
29
|
)([
|
|
30
30
|
`cat <<EOF > ${context.build.dir}/.env
|
|
31
31
|
${keyValueString}
|
|
@@ -36,5 +36,5 @@ EOF`,
|
|
|
36
36
|
export const componentContextNeedsBuildTimeDotEnv = (
|
|
37
37
|
context: ComponentContext,
|
|
38
38
|
) => {
|
|
39
|
-
return context.componentConfig.dotEnv === true; // don't build when set to `local`
|
|
39
|
+
return (context.componentConfig.dotEnv ?? true) === true; // don't build when set to `local`
|
|
40
40
|
};
|