@catladder/pipeline 1.170.1 → 2.0.1
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 +1 -6
- package/dist/bash/BashExpression.js +2 -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 -40
- 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 +971 -765
- 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 → workspace-api-www-turbo-cache.test.ts} +2 -2
- 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/scripts/generate-examples-test.ts +0 -7
- package/src/bash/BashExpression.ts +0 -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 -49
- 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
package/src/build/types.ts
CHANGED
|
@@ -89,12 +89,6 @@ export type BuildConfigBase = {
|
|
|
89
89
|
* Can curently not reference other variables from other components
|
|
90
90
|
*/
|
|
91
91
|
jobVars?: EnvVars;
|
|
92
|
-
/**
|
|
93
|
-
* additional env vars for the buid jobs
|
|
94
|
-
*
|
|
95
|
-
* @deprecated use jobVars or runnerVariables
|
|
96
|
-
*/
|
|
97
|
-
extraVars?: Record<string, string>;
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* additional vars only for the runner.
|
|
@@ -239,13 +233,6 @@ export type BuildConfigDocker =
|
|
|
239
233
|
| BuildConfigDockerBuiltIn
|
|
240
234
|
| BuildConfigDockerCustom;
|
|
241
235
|
|
|
242
|
-
/**
|
|
243
|
-
* @deprecated this type is no longer used. Use {@link BuildConfigDocker} instead.
|
|
244
|
-
*/
|
|
245
|
-
export type BuildConfigCustomDocker =
|
|
246
|
-
| BuildConfigDockerCustom
|
|
247
|
-
| BuildConfigDockerBuiltInNgninx;
|
|
248
|
-
|
|
249
236
|
export type BuildConfigCustom = Omit<
|
|
250
237
|
BuildConfigBase,
|
|
251
238
|
"lint" | "test" | "audit"
|
|
@@ -108,7 +108,6 @@ export const createComponentContext = async (
|
|
|
108
108
|
const context: Omit<ComponentContext, "customJobs"> = {
|
|
109
109
|
type: "component",
|
|
110
110
|
name: ctx.componentName,
|
|
111
|
-
componentName: ctx.componentName,
|
|
112
111
|
env: ctx.env,
|
|
113
112
|
fullConfig: ctx.config,
|
|
114
113
|
componentConfig,
|
|
@@ -14,8 +14,8 @@ export const getEnvConfig = (
|
|
|
14
14
|
|
|
15
15
|
const envCustomizations = defaultConfig.env?.[env] ?? {};
|
|
16
16
|
if (envCustomizations === false) {
|
|
17
|
-
|
|
17
|
+
// env is disabled, still return the default config
|
|
18
|
+
return defaultConfig;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
20
|
return mergeWithMergingArrays(defaultConfig, envCustomizations);
|
|
21
21
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { merge } from "lodash";
|
|
2
1
|
import { DEPLOY_TYPES } from "../deploy";
|
|
3
2
|
import type {
|
|
4
3
|
ComponentContext,
|
|
@@ -11,12 +10,10 @@ import type { StringOrBashExpression } from "../bash/BashExpression";
|
|
|
11
10
|
import { joinBashExpressions } from "../bash/BashExpression";
|
|
12
11
|
import { isStandaloneBuildConfig } from "../build/types";
|
|
13
12
|
import type { EnvironmentContext } from "../types/environmentContext";
|
|
13
|
+
import { createVariableValueContainingReferencesFromString } from "../variables/VariableValueContainingReferences";
|
|
14
|
+
import { resolveAllReferences } from "../variables/resolveAllReferences";
|
|
14
15
|
import { getBuildInfoVariables } from "./getBuildInfoVariables";
|
|
15
16
|
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
16
|
-
import {
|
|
17
|
-
resolveReferences,
|
|
18
|
-
translateLegacyFromComponents,
|
|
19
|
-
} from "./resolveReferences";
|
|
20
17
|
import { transformJobOnlyVars } from "./transformJobOnlyVars";
|
|
21
18
|
import {
|
|
22
19
|
makeSecretEnvVarMapping,
|
|
@@ -43,18 +40,15 @@ type BasePredefinedVariables = ReturnType<typeof getBasePredefinedVariables>;
|
|
|
43
40
|
|
|
44
41
|
// we export so that we have later nice autocomplete
|
|
45
42
|
export type PredefinedVariables = BasePredefinedVariables & {
|
|
46
|
-
|
|
47
|
-
* undefined in rails, Rails before 6.1 (mis)uses the `HOST` environment variable to specify the IP to bind to
|
|
48
|
-
*/
|
|
49
|
-
HOST?: StringOrBashExpression;
|
|
43
|
+
HOSTNAME?: StringOrBashExpression;
|
|
50
44
|
ROOT_URL: StringOrBashExpression;
|
|
51
|
-
|
|
45
|
+
HOSTNAME_INTERNAL: StringOrBashExpression;
|
|
52
46
|
ROOT_URL_INTERNAL: StringOrBashExpression;
|
|
53
47
|
};
|
|
54
48
|
|
|
55
49
|
export const getEnvironmentVariables = async (
|
|
56
50
|
ctx: CreateComponentContextContext,
|
|
57
|
-
|
|
51
|
+
options: { shouldResolveReferences?: boolean } = {},
|
|
58
52
|
): Promise<EnvironmentVariables> => {
|
|
59
53
|
const environmentContext = getEnvironmentContext(ctx);
|
|
60
54
|
|
|
@@ -78,12 +72,8 @@ export const getEnvironmentVariables = async (
|
|
|
78
72
|
...basePredefinedVariables,
|
|
79
73
|
ENV_SHORT: "local",
|
|
80
74
|
ROOT_URL: url,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
buildConfigRaw.type === "rails"
|
|
84
|
-
? {}
|
|
85
|
-
: { HOST: host }),
|
|
86
|
-
HOST_INTERNAL: host,
|
|
75
|
+
HOSTNAME: host,
|
|
76
|
+
HOSTNAME_INTERNAL: host,
|
|
87
77
|
ROOT_URL_INTERNAL: "http://" + host,
|
|
88
78
|
PORT: port.toString(),
|
|
89
79
|
};
|
|
@@ -94,10 +84,10 @@ export const getEnvironmentVariables = async (
|
|
|
94
84
|
)
|
|
95
85
|
: {};
|
|
96
86
|
|
|
97
|
-
const
|
|
98
|
-
additionalEnvVars.
|
|
87
|
+
const HOSTNAME_INTERNAL =
|
|
88
|
+
additionalEnvVars.HOSTNAME_INTERNAL ?? "unknown-host.example.com";
|
|
99
89
|
|
|
100
|
-
host = envConfigRaw?.host ??
|
|
90
|
+
host = envConfigRaw?.host ?? HOSTNAME_INTERNAL;
|
|
101
91
|
url = joinBashExpressions(["https://", host]);
|
|
102
92
|
|
|
103
93
|
predefinedVariables = {
|
|
@@ -106,12 +96,11 @@ export const getEnvironmentVariables = async (
|
|
|
106
96
|
...(isStandaloneBuildConfig(buildConfigRaw) &&
|
|
107
97
|
buildConfigRaw.type === "rails"
|
|
108
98
|
? {}
|
|
109
|
-
: {
|
|
99
|
+
: { HOSTNAME: host }),
|
|
110
100
|
ROOT_URL: url,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
ROOT_URL_INTERNAL: joinBashExpressions(["https://", HOST_INTERNAL]),
|
|
101
|
+
HOSTNAME_INTERNAL,
|
|
102
|
+
|
|
103
|
+
ROOT_URL_INTERNAL: joinBashExpressions(["https://", HOSTNAME_INTERNAL]),
|
|
115
104
|
...additionalEnvVars,
|
|
116
105
|
};
|
|
117
106
|
}
|
|
@@ -132,39 +121,43 @@ export const getEnvironmentVariables = async (
|
|
|
132
121
|
componentName,
|
|
133
122
|
secretEnvVarKeys,
|
|
134
123
|
);
|
|
135
|
-
// this is deprecated, we now support: $componentname:FOO
|
|
136
|
-
const legacyFromComponents = envConfigRaw.vars?.fromComponents ?? {};
|
|
137
|
-
const publicEnvVarsRawWithLegacyFromComponents = merge(
|
|
138
|
-
{},
|
|
139
|
-
translateLegacyFromComponents(legacyFromComponents),
|
|
140
|
-
publicEnvVarsRaw,
|
|
141
|
-
);
|
|
142
124
|
|
|
143
|
-
const publicEnvVarsRawSanitized = stringifyValues(
|
|
144
|
-
|
|
125
|
+
const publicEnvVarsRawSanitized = stringifyValues(publicEnvVarsRaw);
|
|
126
|
+
|
|
127
|
+
const publicEnvVarsUnresolved = Object.fromEntries(
|
|
128
|
+
Object.entries(publicEnvVarsRawSanitized).map(([key, value]) => [
|
|
129
|
+
key,
|
|
130
|
+
createVariableValueContainingReferencesFromString(value, {
|
|
131
|
+
componentName: ctx.componentName,
|
|
132
|
+
}),
|
|
133
|
+
]),
|
|
145
134
|
);
|
|
146
135
|
|
|
147
|
-
const
|
|
136
|
+
const publicEnvVars =
|
|
137
|
+
options.shouldResolveReferences ?? true
|
|
138
|
+
? await resolveAllReferences(
|
|
139
|
+
publicEnvVarsUnresolved,
|
|
140
|
+
async (otherComponentName) => {
|
|
141
|
+
const { envVars: otherEnvVars } = await getEnvironmentVariables(
|
|
142
|
+
{
|
|
143
|
+
...ctx,
|
|
144
|
+
componentName: otherComponentName,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
shouldResolveReferences: false, // we already do this here with replaceAllReferences recursivly until re replaced all
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
return otherEnvVars;
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
: publicEnvVarsUnresolved;
|
|
154
|
+
|
|
155
|
+
const envVars = addIndexVar({
|
|
148
156
|
...predefinedVariables,
|
|
149
157
|
...secretEnvVars,
|
|
150
|
-
...
|
|
158
|
+
...publicEnvVars,
|
|
151
159
|
});
|
|
152
160
|
|
|
153
|
-
const envVars = (await resolveReferences(
|
|
154
|
-
envVarsRaw,
|
|
155
|
-
async (otherComponentName, alreadyVisited) => {
|
|
156
|
-
const { envVars: otherEnvVars } = await getEnvironmentVariables(
|
|
157
|
-
{
|
|
158
|
-
...ctx,
|
|
159
|
-
componentName: otherComponentName,
|
|
160
|
-
},
|
|
161
|
-
alreadyVisited,
|
|
162
|
-
);
|
|
163
|
-
return otherEnvVars;
|
|
164
|
-
},
|
|
165
|
-
alreadyVisited,
|
|
166
|
-
)) as typeof envVarsRaw;
|
|
167
|
-
|
|
168
161
|
return {
|
|
169
162
|
envVars,
|
|
170
163
|
secretEnvVarKeys,
|
|
@@ -111,7 +111,7 @@ export const createDeployJob = (
|
|
|
111
111
|
...context.environment.envVars,
|
|
112
112
|
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
113
113
|
...context.environment.jobOnlyVars.deploy.envVars,
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
...jobDefinition.variables,
|
|
116
116
|
},
|
|
117
117
|
runnerVariables: {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
ComponentContext,
|
|
4
|
-
UnspecifiedEnvVars,
|
|
5
|
-
} from "../../../types/context";
|
|
1
|
+
import { omit } from "lodash";
|
|
2
|
+
import type { ComponentContext } from "../../../types/context";
|
|
6
3
|
import { collapseableSection } from "../../../utils/gitlab";
|
|
7
4
|
import { getDependencyTrackUploadScript } from "../../sbom";
|
|
8
5
|
|
|
6
|
+
import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
|
|
7
|
+
import { writeBashYamlToFileScript } from "../../../bash/bashYaml";
|
|
9
8
|
import { getRemoveOldRevisionsAndImagesCommand } from "../cleanup";
|
|
10
9
|
import { getDatabaseCreateScript } from "../utils/database";
|
|
11
10
|
import { gcloudServiceAccountLoginCommands } from "../utils/gcloudServiceAccountLoginCommands";
|
|
@@ -19,14 +18,7 @@ import {
|
|
|
19
18
|
getCloudRunDeployConfig,
|
|
20
19
|
setGoogleProjectNumberScript,
|
|
21
20
|
} from "./common";
|
|
22
|
-
import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
|
|
23
|
-
import type { StringOrBashExpression } from "../../../bash/BashExpression";
|
|
24
|
-
import { BashExpression, bashEscape } from "../../../bash/BashExpression";
|
|
25
21
|
import { ENV_VARS_FILENAME } from "./constants";
|
|
26
|
-
import {
|
|
27
|
-
writeBashYamlToFileScript,
|
|
28
|
-
yamlBashString,
|
|
29
|
-
} from "../../../bash/bashYaml";
|
|
30
22
|
|
|
31
23
|
export function getCloudRunDeployScripts(context: ComponentContext) {
|
|
32
24
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
@@ -85,7 +85,7 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigCloudRun>
|
|
|
85
85
|
getAdditionalEnvVars: (ctx) => {
|
|
86
86
|
const { fullName, env, componentName, deployConfigRaw } = ctx;
|
|
87
87
|
|
|
88
|
-
const
|
|
88
|
+
const HOSTNAME_INTERNAL = joinBashExpressions(
|
|
89
89
|
[
|
|
90
90
|
fullName,
|
|
91
91
|
getBashVariable(
|
|
@@ -113,7 +113,7 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigCloudRun>
|
|
|
113
113
|
: {};
|
|
114
114
|
|
|
115
115
|
return {
|
|
116
|
-
|
|
116
|
+
HOSTNAME_INTERNAL,
|
|
117
117
|
...getCloudSqlVariables(ctx),
|
|
118
118
|
...jobTriggers,
|
|
119
119
|
DEPLOY_CLOUD_RUN_PROJECT_ID: deployConfigRaw
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StringOrBashExpression } from "../../../bash/BashExpression";
|
|
2
2
|
import { getSecretVarNameForContext } from "../../../context";
|
|
3
3
|
import type { ComponentContext } from "../../../types";
|
|
4
|
+
import type { VariableValue } from "../../../variables/VariableValue";
|
|
4
5
|
import { getFullDbName } from "../../cloudSql/utils";
|
|
5
6
|
import { isOfDeployType } from "../../types";
|
|
6
7
|
|
|
@@ -18,7 +19,7 @@ type CloudSqlValues = {
|
|
|
18
19
|
proxyCredentials: string;
|
|
19
20
|
|
|
20
21
|
instanceConnectionName: string;
|
|
21
|
-
fullDbName:
|
|
22
|
+
fullDbName: VariableValue;
|
|
22
23
|
dbUser: string;
|
|
23
24
|
};
|
|
24
25
|
export const createKubernetesCloudsqlBaseValues = (
|
|
@@ -41,21 +42,7 @@ export const createKubernetesCloudsqlBaseValues = (
|
|
|
41
42
|
context,
|
|
42
43
|
"cloudsqlProxyCredentials",
|
|
43
44
|
)}`;
|
|
44
|
-
if (config
|
|
45
|
-
const instanceConnectionName = `${config.projectId ?? "skynet-164509"}:${
|
|
46
|
-
config.region ?? "europe-west6"
|
|
47
|
-
}:${config.instanceId ?? context.environment.envVars.KUBE_NAMESPACE}`;
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
cloudsql: {
|
|
51
|
-
enabled: config.enabled,
|
|
52
|
-
dbUser: "postgres",
|
|
53
|
-
instanceConnectionName,
|
|
54
|
-
proxyCredentials,
|
|
55
|
-
fullDbName: context.environment.envVars.KUBE_APP_NAME ?? "",
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
} else if (config.type === "unmanaged") {
|
|
45
|
+
if (config.type === "unmanaged") {
|
|
59
46
|
return {
|
|
60
47
|
cloudsql: {
|
|
61
48
|
enabled: config.enabled,
|
|
@@ -29,7 +29,7 @@ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigKubernetes
|
|
|
29
29
|
fullConfig.domainCanonical ||
|
|
30
30
|
"panter.cloud";
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const HOSTNAME_INTERNAL = joinBashExpressions(
|
|
33
33
|
[
|
|
34
34
|
componentSlug,
|
|
35
35
|
...(envType === "review" && reviewSlug ? [reviewSlug] : []),
|
|
@@ -44,7 +44,7 @@ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<DeployConfigKubernetes
|
|
|
44
44
|
KUBE_NAMESPACE,
|
|
45
45
|
KUBE_APP_NAME,
|
|
46
46
|
KUBE_APP_NAME_PREFIX,
|
|
47
|
-
|
|
47
|
+
HOSTNAME_INTERNAL,
|
|
48
48
|
};
|
|
49
49
|
},
|
|
50
50
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StringOrBashExpression } from "../../bash/BashExpression";
|
|
2
1
|
import type { ComponentContext } from "../../types";
|
|
2
|
+
import type { VariableValue } from "../../variables/VariableValue";
|
|
3
3
|
import { isOfDeployType } from "../types";
|
|
4
4
|
|
|
5
5
|
const shouldGoIntoSecrets = (key: string, value: string | undefined) => {
|
|
@@ -23,8 +23,8 @@ export const createKubeEnv = (context: ComponentContext) => {
|
|
|
23
23
|
const allEnvVars = context.environment.envVars;
|
|
24
24
|
|
|
25
25
|
const env = Object.entries(allEnvVars).reduce<{
|
|
26
|
-
secret: Record<string,
|
|
27
|
-
public: Record<string,
|
|
26
|
+
secret: Record<string, VariableValue>;
|
|
27
|
+
public: Record<string, VariableValue>;
|
|
28
28
|
}>(
|
|
29
29
|
(acc, [key, value]) => {
|
|
30
30
|
if (shouldGoIntoSecrets(key, value?.toString())) {
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
|
|
12
12
|
import { createKubeEnv } from "./kubeEnv";
|
|
13
13
|
import { createMongodbBaseConfig } from "./mongodb";
|
|
14
|
-
import { processSecretsAsFiles } from "./processSecretsAsFiles";
|
|
15
14
|
|
|
16
15
|
const createAppConfig = (
|
|
17
16
|
context: ComponentContext,
|
|
@@ -87,14 +86,12 @@ export const createKubeValues = (context: ComponentContext) => {
|
|
|
87
86
|
: {},
|
|
88
87
|
);
|
|
89
88
|
|
|
90
|
-
const kubeValues =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
cronjobs: removeFalsy(cronjobs),
|
|
89
|
+
const kubeValues = mergeWithMergingArrays(defaultKubeValues, {
|
|
90
|
+
jobs: removeFalsy(jobs),
|
|
91
|
+
cronjobs: removeFalsy(cronjobs),
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
93
|
+
...rest,
|
|
94
|
+
});
|
|
98
95
|
|
|
99
96
|
return kubeValues;
|
|
100
97
|
};
|
package/src/deploy/types/base.ts
CHANGED
|
@@ -25,12 +25,6 @@ export type DeployConfigBase = {
|
|
|
25
25
|
*/
|
|
26
26
|
jobVars?: EnvVars;
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* additional env vars for the deploy job
|
|
30
|
-
*
|
|
31
|
-
* @deprecated use deploy.jobVars for deploy job specific variables
|
|
32
|
-
*/
|
|
33
|
-
extraVars?: Record<string, string>;
|
|
34
28
|
/**
|
|
35
29
|
* additional vars only for the runner.
|
|
36
30
|
* Also if you use services: that require env vars, you need to set them here.
|
|
@@ -164,33 +164,6 @@ export type DeployConfigMongodbReplicaset = {
|
|
|
164
164
|
export type DeployConfigMongodb = DeployConfigMongodbBase &
|
|
165
165
|
(DeployConfigMongodbStandalone | DeployConfigMongodbReplicaset);
|
|
166
166
|
|
|
167
|
-
/**
|
|
168
|
-
* @deprecated use config with instanceConnectionName
|
|
169
|
-
*/
|
|
170
|
-
type DeployConfigKubernetesValuesCloudSQLLegacy = {
|
|
171
|
-
enabled: boolean;
|
|
172
|
-
/**
|
|
173
|
-
* @deprecated use config with instanceConnectionName
|
|
174
|
-
*/
|
|
175
|
-
instanceId?: string;
|
|
176
|
-
/**
|
|
177
|
-
* @deprecated use config with instanceConnectionName
|
|
178
|
-
*/
|
|
179
|
-
projectId?: string;
|
|
180
|
-
/**
|
|
181
|
-
* @deprecated use config with instanceConnectionName
|
|
182
|
-
*/
|
|
183
|
-
region?: string;
|
|
184
|
-
/**
|
|
185
|
-
* @deprecated use type "unmanaged".
|
|
186
|
-
*
|
|
187
|
-
* Be aware that "unmanaged" is not fully backward compatible with "legacy".
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*/
|
|
191
|
-
type?: "legacy";
|
|
192
|
-
};
|
|
193
|
-
|
|
194
167
|
export type DeployConfigKubernetesValuesCloudSQLUnmanaged = {
|
|
195
168
|
enabled: boolean;
|
|
196
169
|
instanceConnectionName: string;
|
|
@@ -220,8 +193,7 @@ export type DeployConfigKubernetesValuesCloudSQLUnmanaged = {
|
|
|
220
193
|
dbBaseName?: string;
|
|
221
194
|
};
|
|
222
195
|
export type DeployConfigKubernetesValuesCloudSQL =
|
|
223
|
-
|
|
224
|
-
| DeployConfigKubernetesValuesCloudSQLUnmanaged;
|
|
196
|
+
DeployConfigKubernetesValuesCloudSQLUnmanaged;
|
|
225
197
|
export type DeployConfigKubernetesValues = AllowUnknownProps<{
|
|
226
198
|
/**
|
|
227
199
|
* enable cloudsql db. Currently you have to manually set it up
|
|
@@ -358,13 +330,6 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
|
|
|
358
330
|
mapServiceUrlToEnv?: {
|
|
359
331
|
[envVar: string]: string;
|
|
360
332
|
};
|
|
361
|
-
/**
|
|
362
|
-
* Mount secrets as files in the filesystem.
|
|
363
|
-
* These secrets are still available as env vars, but will contain the path of the file instead
|
|
364
|
-
*
|
|
365
|
-
* @deprecated this will be removed in the future, because its very niche and not used
|
|
366
|
-
*/
|
|
367
|
-
secretsAsFile?: string[];
|
|
368
333
|
}>;
|
|
369
334
|
|
|
370
335
|
export type DeployConfigKubernetes = {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class GlobalScriptFunction {
|
|
2
|
+
constructor(
|
|
3
|
+
public name: string,
|
|
4
|
+
public script: string,
|
|
5
|
+
) {}
|
|
6
|
+
|
|
7
|
+
toBashFunction() {
|
|
8
|
+
return `function ${this.name} () {
|
|
9
|
+
${this.script.trim()}
|
|
10
|
+
}`.trim();
|
|
11
|
+
}
|
|
12
|
+
invoke(...args: string[]) {
|
|
13
|
+
return `${this.name} ${args.join(" ")}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const globalScriptFunctions = new Map<string, GlobalScriptFunction>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* registers a global script function
|
|
21
|
+
* only use that in top-level scopes as it will attach the function to the global scope
|
|
22
|
+
*/
|
|
23
|
+
export const registerGlobalScriptFunction = (name: string, script: string) => {
|
|
24
|
+
if (globalScriptFunctions.has(name)) {
|
|
25
|
+
throw new Error(`Global script function ${name} already exists`);
|
|
26
|
+
}
|
|
27
|
+
const scriptFunction = new GlobalScriptFunction(name, script);
|
|
28
|
+
globalScriptFunctions.set(name, scriptFunction);
|
|
29
|
+
return scriptFunction;
|
|
30
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -106,7 +106,6 @@ export const makeGitlabJob = (
|
|
|
106
106
|
environment,
|
|
107
107
|
envMode,
|
|
108
108
|
needsStages,
|
|
109
|
-
needsOtherComponent,
|
|
110
109
|
name,
|
|
111
110
|
needs,
|
|
112
111
|
jobTags,
|
|
@@ -310,7 +309,7 @@ function deduplicateNeeds(needs: GitlabJobDef["needs"]): GitlabJobDef["needs"] {
|
|
|
310
309
|
|
|
311
310
|
function getGitlabNeedsForComponentJob(
|
|
312
311
|
context: ComponentContext,
|
|
313
|
-
{ needsStages, needs
|
|
312
|
+
{ needsStages, needs }: CatladderJob<string>,
|
|
314
313
|
allJobs: AllCatladderJobs,
|
|
315
314
|
): GitlabJobDef["needs"] {
|
|
316
315
|
const needsFromStages = needsStages?.flatMap<CatladderJobNeed>((n) => {
|
|
@@ -353,8 +352,6 @@ function getGitlabNeedsForComponentJob(
|
|
|
353
352
|
const cleanedNeeds: CatladderJob["needs"] = [
|
|
354
353
|
...(needsFromStages ?? []),
|
|
355
354
|
...(needs ?? []),
|
|
356
|
-
// pull in legacy needs from other component, which is now identical to needs
|
|
357
|
-
...(needsOtherComponent ?? []),
|
|
358
355
|
];
|
|
359
356
|
|
|
360
357
|
return cleanedNeeds
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getRunnerImage } from "../../runner";
|
|
2
2
|
import type { Pipeline } from "../../types";
|
|
3
|
-
|
|
3
|
+
import { globalScriptFunctions } from "../../globalScriptFunctions";
|
|
4
4
|
type PickRequired<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
|
|
5
5
|
|
|
6
6
|
export const createGitlabPipelineWithDefaults = ({
|
|
7
7
|
image,
|
|
8
8
|
variables,
|
|
9
|
+
before_script,
|
|
9
10
|
...config
|
|
10
11
|
}: PickRequired<
|
|
11
12
|
Partial<Pipeline<"gitlab">>,
|
|
@@ -22,6 +23,12 @@ export const createGitlabPipelineWithDefaults = ({
|
|
|
22
23
|
GIT_DEPTH: "1", // no need the full depth
|
|
23
24
|
...(variables ?? {}),
|
|
24
25
|
},
|
|
26
|
+
before_script: [
|
|
27
|
+
...[...globalScriptFunctions.values()].map((script) =>
|
|
28
|
+
script.toBashFunction(),
|
|
29
|
+
),
|
|
30
|
+
...(before_script ?? []),
|
|
31
|
+
],
|
|
25
32
|
|
|
26
33
|
...config,
|
|
27
34
|
};
|
|
@@ -49,11 +49,13 @@ export const getPackageManagerInfoForComponent = async (
|
|
|
49
49
|
: [];
|
|
50
50
|
|
|
51
51
|
const pathsToCopyInDocker = [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
...new Set([
|
|
53
|
+
packageJson,
|
|
54
|
+
...(workspacePackageJson ? [workspacePackageJson] : []),
|
|
55
|
+
lockFile,
|
|
56
|
+
...configFilePaths,
|
|
57
|
+
...currentWorkspaceDependencies,
|
|
58
|
+
]),
|
|
57
59
|
];
|
|
58
60
|
return {
|
|
59
61
|
...baseInfo,
|
package/src/runner/index.ts
CHANGED
package/src/types/config.ts
CHANGED
|
@@ -73,14 +73,6 @@ export type EnvVars = {
|
|
|
73
73
|
* secret env vars. These vars can be managed with catladder/cli
|
|
74
74
|
*/
|
|
75
75
|
secret?: string[];
|
|
76
|
-
/**
|
|
77
|
-
* @deprecated, use ${componentName:variableName} instead
|
|
78
|
-
*
|
|
79
|
-
* With fromComponents you can inject env vars from other components.
|
|
80
|
-
*/
|
|
81
|
-
fromComponents?: {
|
|
82
|
-
[otherApp: string]: Record<string, string>;
|
|
83
|
-
};
|
|
84
76
|
};
|
|
85
77
|
|
|
86
78
|
export type DefaultEnvConfig = {
|
|
@@ -169,12 +161,14 @@ export type ComponentConfig<C extends ConfigProps = never> = {
|
|
|
169
161
|
* Use this in combination with @dotenvx/dotenvx or node 20 to start apps locally with .env files
|
|
170
162
|
* During build and runtime, it relies on the env vars set in the environment
|
|
171
163
|
*
|
|
164
|
+
* @defaultValue true
|
|
165
|
+
*
|
|
172
166
|
*/
|
|
173
167
|
dotEnv?: boolean | "local";
|
|
174
168
|
/**
|
|
175
169
|
* whether to create a env.d.ts localy and during build jobs
|
|
176
170
|
*
|
|
177
|
-
*
|
|
171
|
+
* @defaultValue true
|
|
178
172
|
*/
|
|
179
173
|
envDTs?: boolean;
|
|
180
174
|
} & DefaultEnvConfig;
|
|
@@ -184,6 +178,9 @@ export type ConfigProps = {
|
|
|
184
178
|
};
|
|
185
179
|
|
|
186
180
|
export type Config<C extends ConfigProps = never> = {
|
|
181
|
+
/**
|
|
182
|
+
* the pipeline type to generate, defaults to gitlab
|
|
183
|
+
*/
|
|
187
184
|
pipelineType?: PipelineType;
|
|
188
185
|
|
|
189
186
|
/**
|
package/src/types/context.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from "../build";
|
|
7
7
|
import type { PredefinedVariables, SecretEnvVar } from "../context";
|
|
8
8
|
import type { DeployConfig } from "../deploy";
|
|
9
|
+
import type { VariableValue } from "../variables/VariableValue";
|
|
9
10
|
import type {
|
|
10
11
|
ComponentConfig,
|
|
11
12
|
Config,
|
|
@@ -17,7 +18,7 @@ import type { PipelineType } from "./pipeline";
|
|
|
17
18
|
|
|
18
19
|
export type UnspecifiedEnvVars = Record<
|
|
19
20
|
string,
|
|
20
|
-
|
|
21
|
+
VariableValue | undefined | null
|
|
21
22
|
>;
|
|
22
23
|
|
|
23
24
|
export type EnvironmentEnvVars<
|
|
@@ -46,10 +47,7 @@ export type Environment = {
|
|
|
46
47
|
* the full name of the app. We use this as RELEASE_NAME in kubernetes and the service name in google cloud run
|
|
47
48
|
*/
|
|
48
49
|
fullName: StringOrBashExpression;
|
|
49
|
-
|
|
50
|
-
* @deprecated this is the same as context.env, use that instead
|
|
51
|
-
*/
|
|
52
|
-
shortName: string;
|
|
50
|
+
|
|
53
51
|
/**
|
|
54
52
|
* the environment slug without component name.
|
|
55
53
|
*/
|
|
@@ -158,10 +156,6 @@ export type ComponentContext<
|
|
|
158
156
|
* the name of the component
|
|
159
157
|
*/
|
|
160
158
|
name: string;
|
|
161
|
-
/**
|
|
162
|
-
* @deprecated use name instead
|
|
163
|
-
*/
|
|
164
|
-
componentName: string;
|
|
165
159
|
|
|
166
160
|
/**
|
|
167
161
|
* the merged component config.
|