@catladder/pipeline 3.30.5 โ†’ 3.32.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.
@@ -0,0 +1,12 @@
1
+ import { it, expect } from "vitest";
2
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
3
+ import config from "./custom-docker-file";
4
+
5
+ /**
6
+ * This test is auto-generated.
7
+ * Modifications will be overwritten on every `yarn test` run!
8
+ */
9
+
10
+ it("matches snapshot for custom-docker-file local pipeline YAML", async () => {
11
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
12
+ });
@@ -0,0 +1,36 @@
1
+ import type { Config } from "../src";
2
+
3
+ const config = {
4
+ appName: "test-app",
5
+ customerName: "pan",
6
+ components: {
7
+ www: {
8
+ dir: "www",
9
+ build: {
10
+ type: "node",
11
+ jobImage: "foo",
12
+ docker: {
13
+ type: "custom",
14
+ dockerfileContent: [
15
+ "FROM node:22",
16
+ "USER node",
17
+ "$DOCKER_COPY_WORKSPACE_FILES",
18
+ "WORKDIR /app/$APP_DIR",
19
+ "$DOCKER_COPY_AND_INSTALL_APP",
20
+ ],
21
+ },
22
+ },
23
+ deploy: {
24
+ type: "google-cloudrun",
25
+ projectId: "asdf",
26
+ region: "asia-east1",
27
+ },
28
+ },
29
+ },
30
+ } satisfies Config;
31
+
32
+ export default config;
33
+
34
+ export const information = {
35
+ title: "Custom Dockerfile",
36
+ };
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "3.30.5",
56
+ "version": "3.32.0",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables",
@@ -88,6 +88,6 @@
88
88
  "yaml": "^2.5.0"
89
89
  },
90
90
  "dependencies": {
91
- "tsx": "^4.19.0"
91
+ "tsx": "^4.21.0"
92
92
  }
93
93
  }
@@ -32,7 +32,6 @@ export const createCustomTestJobs = (
32
32
  APP_PATH: context.build.dir,
33
33
  ...context.environment.jobOnlyVars.build.envVars,
34
34
  },
35
- runnerVariables: RUNNER_CUSTOM_TEST_VARIABLES,
36
35
  services: buildConfig.jobServices,
37
36
  cache: createJobCacheFromConfig(context, buildConfig),
38
37
  stage: "test",
@@ -42,6 +41,10 @@ export const createCustomTestJobs = (
42
41
  ? {
43
42
  name: "๐Ÿ›ก audit",
44
43
  ...base,
44
+ runnerVariables: {
45
+ ...RUNNER_CUSTOM_TEST_VARIABLES,
46
+ ...(buildConfig.audit?.runnerVariables ?? {}),
47
+ },
45
48
  image: buildConfig.audit?.jobImage ?? buildConfig.jobImage,
46
49
  cache: undefined,
47
50
  script: [...ensureArray(buildConfig.audit?.command)],
@@ -59,6 +62,10 @@ export const createCustomTestJobs = (
59
62
  name: "๐Ÿ‘ฎ lint",
60
63
 
61
64
  ...base,
65
+ runnerVariables: {
66
+ ...RUNNER_CUSTOM_TEST_VARIABLES,
67
+ ...(buildConfig.lint?.runnerVariables ?? {}),
68
+ },
62
69
  image: buildConfig.lint?.jobImage ?? buildConfig.jobImage,
63
70
  script: [...ensureArray(buildConfig.lint?.command)],
64
71
  ...createArtifactsConfig(
@@ -73,6 +80,10 @@ export const createCustomTestJobs = (
73
80
  name: "๐Ÿงช test",
74
81
 
75
82
  ...base,
83
+ runnerVariables: {
84
+ ...RUNNER_CUSTOM_TEST_VARIABLES,
85
+ ...(buildConfig.test?.runnerVariables ?? {}),
86
+ },
76
87
  image: buildConfig.test?.jobImage ?? buildConfig.jobImage,
77
88
  script: [...ensureArray(buildConfig.test?.command)],
78
89
  ...createArtifactsConfig(
@@ -166,19 +166,39 @@ const BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS = {
166
166
  [type in BuildConfigDocker["type"]]: string | null;
167
167
  };
168
168
 
169
- export const getDockerBuildScriptWithBuiltInDockerFile = (
169
+ const getEnsureDockerFileScript = (
170
170
  context: ComponentContextWithBuild,
171
- defaultType?: BuildConfigDocker["type"],
171
+ fallbackType?: BuildConfigDocker["type"],
172
172
  ) => {
173
- const type =
173
+ if (
174
174
  "docker" in context.build.config &&
175
175
  context.build.config.docker &&
176
176
  "type" in context.build.config.docker
177
- ? context.build.config.docker?.type
178
- : defaultType;
177
+ ) {
178
+ if (context.build.config.docker?.type === "custom") {
179
+ if (context.build.config.docker?.dockerfileContent) {
180
+ // we need to create a script that creates a Dockerfile in the current directory
181
+ return `
182
+ echo "Creating Dockerfile"
183
+ cat >$APP_DIR/Dockerfile <<EOF
184
+ ${context.build.config.docker?.dockerfileContent?.join("\n")}
185
+ EOF`;
186
+ }
187
+ }
188
+
189
+ const type = context.build.config.docker?.type ?? fallbackType;
190
+ return type ? BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS[type] : null;
191
+ }
192
+ return fallbackType ? BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS[fallbackType] : null;
193
+ };
194
+
195
+ export const getDockerBuildScriptWithBuiltInDockerFile = (
196
+ context: ComponentContextWithBuild,
197
+ fallbackType?: BuildConfigDocker["type"],
198
+ ) => {
179
199
  return getDockerBuildDefaultScript(
180
200
  context,
181
- type ? BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS[type] : null,
201
+ getEnsureDockerFileScript(context, fallbackType),
182
202
  );
183
203
  };
184
204
  export const getDockerBuildDefaultScript = (
@@ -39,7 +39,6 @@ export const createNodeTestJobs = (
39
39
  : {}),
40
40
  },
41
41
 
42
- runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
43
42
  stage: "test",
44
43
  needs: [],
45
44
  };
@@ -50,6 +49,10 @@ export const createNodeTestJobs = (
50
49
  ? {
51
50
  name: "๐Ÿ›ก audit",
52
51
  ...base,
52
+ runnerVariables: {
53
+ ...NODE_RUNNER_BUILD_VARIABLES,
54
+ ...(buildConfig.audit?.runnerVariables ?? {}),
55
+ },
53
56
  image: buildConfig.audit?.jobImage ?? defaultImage,
54
57
  cache: undefined, // audit does not need yarn install and no cache
55
58
  script: [
@@ -68,12 +71,15 @@ export const createNodeTestJobs = (
68
71
  ),
69
72
  }
70
73
  : null;
71
-
72
74
  const lintJob: CatladderJob | null =
73
75
  buildConfig.lint !== false
74
76
  ? {
75
77
  name: "๐Ÿ‘ฎ lint",
76
78
  ...base,
79
+ runnerVariables: {
80
+ ...NODE_RUNNER_BUILD_VARIABLES,
81
+ ...(buildConfig.lint?.runnerVariables ?? {}),
82
+ },
77
83
  image: buildConfig.lint?.jobImage ?? defaultImage,
78
84
  cache: createJobCacheFromCacheConfigs(context, getNodeCache(context)),
79
85
  script: [
@@ -95,6 +101,10 @@ export const createNodeTestJobs = (
95
101
  name: "๐Ÿงช test",
96
102
 
97
103
  ...base,
104
+ runnerVariables: {
105
+ ...NODE_RUNNER_BUILD_VARIABLES,
106
+ ...(buildConfig.test?.runnerVariables ?? {}),
107
+ },
98
108
  image:
99
109
  buildConfig.test?.jobImage ?? getRunnerImage("jobs-testing-chrome"),
100
110
  cache: createJobCacheFromCacheConfigs(context, getNodeCache(context)),
@@ -76,6 +76,11 @@ export type TestJobCustom = {
76
76
  * {@link TestJobCustom.artifacts}.reports.junit is merged with {@link TestJobCustom.artifactsReports} in case both given.
77
77
  */
78
78
  artifacts?: Artifacts;
79
+
80
+ /**
81
+ * additional vars for this job runner
82
+ */
83
+ runnerVariables?: Record<string, string>;
79
84
  };
80
85
 
81
86
  export type BuildConfigBase = {
@@ -239,6 +244,16 @@ type BuildConfigDockerCustom = {
239
244
  * Depending on your Dockerfile you may want to change it to "component"
240
245
  */
241
246
  buildContextLocation?: "root" | "component";
247
+
248
+ /**
249
+ * EXPERIMENTAL: custom docker file content
250
+ *
251
+ * you can use some predefined variables:
252
+ * - $DOCKER_COPY_WORKSPACE_FILES
253
+ * - $DOCKER_COPY_AND_INSTALL_APP
254
+ * - and all default variables
255
+ */
256
+ dockerfileContent?: string[];
242
257
  };
243
258
 
244
259
  export type BuildConfigDocker =
@@ -403,7 +418,7 @@ export type WorkspaceBuildConfigBase = {
403
418
  */
404
419
  audit?: false | TestJobCustom;
405
420
  /**
406
- * additional vars only for the runner.
421
+ * additional vars only for the build job.
407
422
  * Also if you use services: that require env vars, you need to set them here.
408
423
  *
409
424
  */
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
2
 
3
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
3
4
  const tsx = require("tsx/cjs/api");
4
5
 
5
6
  import { parse } from "yaml";
@@ -10,7 +11,7 @@ import type { Config } from "../types";
10
11
  const fullPath = (directory: string, ext: string) =>
11
12
  directory + "/catladder." + ext;
12
13
 
13
- export const readConfig = async (
14
+ const readConfigInternal = async (
14
15
  directory: string = process.cwd(),
15
16
  ): Promise<{ config: Config; path: string; ext: string } | null> => {
16
17
  const found = ["ts", "js", "yml", "yaml"].find((extension) =>
@@ -39,3 +40,23 @@ export const readConfig = async (
39
40
  }
40
41
  return null;
41
42
  };
43
+
44
+ export const readConfig = async (
45
+ directory: string = process.cwd(),
46
+ ): Promise<{ config: Config; path: string; ext: string } | null> => {
47
+ try {
48
+ return await readConfigInternal(directory);
49
+ } catch (error) {
50
+ console.error(`Error reading config in ${directory}:`, error);
51
+ console.error(`
52
+ This may happen due to various reasons:
53
+ - Syntax errors in your catladder.ts file
54
+ - tsx (the TypeScript loader used by catladder) needs to understand the syntax in your project.
55
+ If your project uses newer TypeScript/JavaScript syntax, you may need to update catladder
56
+ to get a newer version of tsx that supports it.
57
+ - Missing or incorrect dependencies in your project
58
+ - TypeScript configuration issues in your tsconfig.json
59
+ `);
60
+ return null;
61
+ }
62
+ };