@catladder/pipeline 1.98.2 → 1.99.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,49 @@
1
+ import type { Config } from "../src";
2
+ import { createAllPipelines } from "./__utils__/helpers";
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
+
22
+ values: {
23
+ application: {
24
+ command: "node main.js",
25
+ },
26
+ mongodb: {
27
+ enabled: true,
28
+ architecture: "replicaset",
29
+ persistence: {
30
+ storageClass: "premium-rwo",
31
+ },
32
+ tolerations: [
33
+ {
34
+ key: "mongodb",
35
+ operator: "Equal",
36
+ value: "true",
37
+ effect: "NoSchedule",
38
+ },
39
+ ],
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ };
46
+
47
+ it("matches snapshot", async () => {
48
+ expect(await createAllPipelines(config)).toMatchSnapshot();
49
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catladder/pipeline",
3
- "version": "1.98.2",
3
+ "version": "1.99.1",
4
4
  "scripts": {
5
5
  "build:tsc": "yarn tsc",
6
6
  "build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
@@ -7,7 +7,7 @@ import { join } from "path";
7
7
  import { isOfBuildType } from "../types";
8
8
  import { getNextCache, getNodeCache, getYarnCache } from "./cache";
9
9
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
10
- import { getYarnInstall, getYarnInstallCommand } from "./yarn";
10
+ import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
11
11
  import type { CatladderJob } from "../../types/jobs";
12
12
 
13
13
  export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
@@ -55,13 +55,8 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
55
55
  cache: [...getYarnCache(context, "pull")],
56
56
  variables: {
57
57
  // only required for non static
58
- YARN_INSTALL: getYarnInstallCommand(context, {
59
- prodOnly: true,
60
- }),
61
- YARN_INSTALL_WITHOUT_SCRIPTS: getYarnInstallCommand(context, {
62
- prodOnly: true,
63
- noScripts: true,
64
- }),
58
+ DOCKER_COPY_AND_INSTALL_APP:
59
+ getDockerAppCopyAndBuildScript(context),
65
60
  DOCKER_COPY_WORKSPACE_FILES:
66
61
  context.packageManagerInfo?.pathsToCopyInDocker
67
62
  .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
@@ -1,33 +1,16 @@
1
1
  import type { Context } from "../../types";
2
2
 
3
- export const getYarnInstallCommand = (
4
- context: Context,
5
- options?: {
6
- prodOnly?: boolean;
7
- noScripts?: boolean;
8
- }
9
- ) => {
3
+ const YARN_INSTALL_CLASSIC = `yarn install --frozen-lockfile`;
4
+
5
+ // FIXME: check why and when rebuild is needed
6
+ const YARN_BERRY_PROD_REBUILD = `yarn workspaces focus --production && yarn rebuild`;
7
+
8
+ const getYarnInstallCommand = (context: Context) => {
10
9
  if (context.packageManagerInfo?.isClassic) {
11
- return `yarn install --frozen-lockfile ${
12
- options?.prodOnly ? "--production" : ""
13
- } ${options?.noScripts ? "--ignore-scripts" : ""}`;
10
+ return YARN_INSTALL_CLASSIC;
14
11
  }
15
- // is modern
16
12
 
17
- // yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
18
- // trying to import those fail on this version
19
- const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) =>
20
- context.packageManagerInfo?.version.startsWith(v)
21
- );
22
- return options?.prodOnly
23
- ? `${options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""}${
24
- doesNotShipWithBuiltInPlugins
25
- ? "yarn plugin import workspace-tools && "
26
- : " "
27
- }yarn workspaces focus --production && yarn rebuild` // needs yarn plugin import workspace-tools
28
- : `${
29
- options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
30
- }yarn install --immutable`;
13
+ return `yarn install --immutable`;
31
14
  };
32
15
 
33
16
  export const ensureNodeVersion = (context: Context) => [
@@ -38,3 +21,33 @@ export const getYarnInstall = (context: Context) => [
38
21
  ...ensureNodeVersion(context),
39
22
  getYarnInstallCommand(context),
40
23
  ];
24
+
25
+ const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`;
26
+
27
+ export const getDockerAppCopyAndBuildScript = (context: Context) => {
28
+ if (context.packageManagerInfo?.isClassic) {
29
+ return `
30
+ RUN ${YARN_INSTALL_CLASSIC} --production --ignore-scripts
31
+ ${DOCKER_COPY_FILES}
32
+ RUN ${YARN_INSTALL_CLASSIC} --production
33
+ `.trim();
34
+ }
35
+
36
+ // yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
37
+ // trying to import those fail on this version
38
+ const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) =>
39
+ context.packageManagerInfo?.version.startsWith(v)
40
+ );
41
+ const maybeAddWorkspaceToolsCommand = doesNotShipWithBuiltInPlugins
42
+ ? "RUN yarn plugin import workspace-tools"
43
+ : "";
44
+
45
+ // copy first everything and then install
46
+ // rebuild first does not work as it will run postinstall and that might require files in the app
47
+ return `
48
+ ${DOCKER_COPY_FILES}
49
+ ${maybeAddWorkspaceToolsCommand}
50
+ RUN ${YARN_BERRY_PROD_REBUILD}
51
+
52
+ `.trim();
53
+ };
@@ -98,6 +98,19 @@ export type KubernetesWorkerDef = {
98
98
  };
99
99
  };
100
100
 
101
+ type KubernetesTolerationExists = {
102
+ operator: "Exists";
103
+ };
104
+
105
+ type KubernetesTolerationEqual = {
106
+ operator: "Equal";
107
+ value: string;
108
+ };
109
+
110
+ export type KubernetesToleration = {
111
+ key: string;
112
+ effect: "NoSchedule" | "PreferNoSchedule" | "NoExecute";
113
+ } & (KubernetesTolerationEqual | KubernetesTolerationExists);
101
114
  export type DeployConfigMongodbBase = {
102
115
  enabled?: boolean;
103
116
  dbName?: string;
@@ -113,6 +126,7 @@ export type DeployConfigMongodbBase = {
113
126
  size?: string;
114
127
  };
115
128
  resources?: KubernetesResourcesDef;
129
+ tolerations?: KubernetesToleration[];
116
130
  };
117
131
 
118
132
  export type DeployConfigMongodbStandalone = {
@@ -29,11 +29,12 @@ export const getPackageManagerInfo = async (
29
29
  ? join(workspaceRoot, "yarn.lock")
30
30
  : join(component.dir, "yarn.lock");
31
31
  const configFiles = [".yarnrc", ".yarnrc.yml", ".npmrc", ".yarn"]; // ".yarn" is yarn 2 folder
32
- const rcFiles = (
33
- componentIsInWorkspace
34
- ? configFiles
35
- : configFiles.map((f) => join(component.dir, f))
36
- ).filter((f) => existsSync(f));
32
+ // copy all those configFiles from workspace root and/or component folder
33
+
34
+ const configFilePaths = [
35
+ ...configFiles,
36
+ ...configFiles.map((f) => join(component.dir, f)),
37
+ ].filter((f) => existsSync(f));
37
38
 
38
39
  // get all folders that this workspace depend on
39
40
  // we will later copy them into the docker build
@@ -50,7 +51,7 @@ export const getPackageManagerInfo = async (
50
51
  packageJson,
51
52
  ...(workspacePackageJson ? [workspacePackageJson] : []),
52
53
  lockFile,
53
- ...rcFiles,
54
+ ...configFilePaths,
54
55
  ...workspaceDependencies,
55
56
  ];
56
57
  return {