@catladder/pipeline 3.31.0 → 3.32.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.
@@ -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.31.0",
56
+ "version": "3.32.1",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables",
@@ -8,6 +8,9 @@ import type { CatladderJob } from "../../types/jobs";
8
8
  import { uniq } from "lodash";
9
9
  import { componentContextNeedsBuildTimeDotEnv } from "../base/writeDotEnv";
10
10
 
11
+ const uniqueAndAlphabeticalSort = (arr: string[]): string[] => {
12
+ return uniq(arr).sort((a, b) => a.localeCompare(b));
13
+ };
11
14
  export const createBuildJobArtifacts = (
12
15
  context: Context,
13
16
  ): CatladderJob["artifacts"] => {
@@ -23,8 +26,10 @@ export const createBuildJobArtifacts = (
23
26
  )
24
27
  : getAllArtifactExcludePathsForComponent(context);
25
28
  return {
26
- paths: uniq(paths).sort((a, b) => a.localeCompare(b)),
27
- ...(exclude.length > 0 ? { exclude } : {}),
29
+ paths: uniqueAndAlphabeticalSort(paths),
30
+ ...(exclude.length > 0
31
+ ? { exclude: uniqueAndAlphabeticalSort(exclude) }
32
+ : {}),
28
33
  expire_in: "1 day",
29
34
  when: "always",
30
35
  reports:
@@ -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 = (
@@ -244,6 +244,16 @@ type BuildConfigDockerCustom = {
244
244
  * Depending on your Dockerfile you may want to change it to "component"
245
245
  */
246
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[];
247
257
  };
248
258
 
249
259
  export type BuildConfigDocker =