Bläddra i källkod

require build context to be rel path

Ian Edwards 2 år sedan
förälder
incheckning
6172e21243
1 ändrade filer med 19 tillägg och 3 borttagningar
  1. 19 3
      dashboard/src/lib/porter-apps/build.ts

+ 19 - 3
dashboard/src/lib/porter-apps/build.ts

@@ -1,17 +1,33 @@
-import { buildpackSchema } from "main/home/app-dashboard/types/buildpack";
+import path from "path";
 import { z } from "zod";
 
+import { buildpackSchema } from "main/home/app-dashboard/types/buildpack";
+
 // buildValidator is used to validate inputs for build setting fields
 export const buildValidator = z.discriminatedUnion("method", [
   z.object({
     method: z.literal("pack"),
-    context: z.string().min(1).default("./").catch("./"),
+    context: z
+      .string()
+      .min(1)
+      .default("./")
+      .catch("./")
+      .refine((s) => !path.isAbsolute(s), {
+        message: "Context must be a relative path",
+      }),
     buildpacks: z.array(buildpackSchema).default([]),
     builder: z.string(),
   }),
   z.object({
     method: z.literal("docker"),
-    context: z.string().min(1).default("./").catch("./"),
+    context: z
+      .string()
+      .min(1)
+      .default("./")
+      .catch("./")
+      .refine((s) => !path.isAbsolute(s), {
+        message: "Context must be a relative path",
+      }),
     dockerfile: z.string().min(1).default("./Dockerfile").catch("./Dockerfile"),
   }),
 ]);