فهرست منبع

remove build from validate call if it has not changed

Ian Edwards 2 سال پیش
والد
کامیت
bfb3077d8a
2فایلهای تغییر یافته به همراه53 افزوده شده و 24 حذف شده
  1. 27 2
      dashboard/src/lib/hooks/useAppValidation.ts
  2. 26 22
      dashboard/src/lib/porter-apps/index.ts

+ 27 - 2
dashboard/src/lib/hooks/useAppValidation.ts

@@ -1,8 +1,9 @@
-import { PorterApp } from "@porter-dev/api-contracts";
+import { Build, PorterApp } from "@porter-dev/api-contracts";
 import {
   PorterAppFormData,
   SourceOptions,
   clientAppToProto,
+  clientBuildToProto,
 } from "lib/porter-apps";
 import { useCallback, useContext } from "react";
 import { Context } from "shared/Context";
@@ -10,6 +11,20 @@ import api from "shared/api";
 import { match } from "ts-pattern";
 import { z } from "zod";
 
+const didBuildChange = (
+  current: PorterAppFormData["app"]["build"],
+  previous?: PorterApp["build"]
+) => {
+  if (!previous) {
+    return true;
+  }
+
+  const currentAsProto = clientBuildToProto(current);
+  currentAsProto.commitSha = previous.commitSha;
+
+  return !Build.equals(currentAsProto, previous);
+};
+
 export const useAppValidation = ({
   deploymentTargetID,
   creating = false,
@@ -76,7 +91,17 @@ export const useAppValidation = ({
         prevRevision?.env || {}
       );
 
-      const proto = clientAppToProto(data);
+      const buildChanged = didBuildChange(data.app.build, prevRevision?.build);
+      const initialProto = clientAppToProto(data);
+
+      const proto = buildChanged
+        ? initialProto
+        : new PorterApp({
+            ...initialProto,
+            build: undefined,
+            image: undefined,
+          });
+
       const commit_sha = await match(data.source)
         .with({ type: "github" }, async (src) => {
           if (!creating) {

+ 26 - 22
dashboard/src/lib/porter-apps/index.ts

@@ -144,22 +144,26 @@ export function serviceOverrides({
   };
 }
 
-const clientBuildToProto = (build: BuildOptions) => {
+export const clientBuildToProto = (build: BuildOptions) => {
   return match(build)
-    .with({ method: "pack" }, (b) =>
-      Object.freeze({
-        method: "pack",
-        context: b.context,
-        buildpacks: b.buildpacks.map((b) => b.buildpack),
-        builder: b.builder,
-      })
+    .with(
+      { method: "pack" },
+      (b) =>
+        new Build({
+          method: "pack",
+          context: b.context,
+          buildpacks: b.buildpacks.map((b) => b.buildpack),
+          builder: b.builder,
+        })
     )
-    .with({ method: "docker" }, (b) =>
-      Object.freeze({
-        method: "docker",
-        context: b.context,
-        dockerfile: b.dockerfile,
-      })
+    .with(
+      { method: "docker" },
+      (b) =>
+        new Build({
+          method: "docker",
+          context: b.context,
+          dockerfile: b.dockerfile,
+        })
     )
     .exhaustive();
 };
@@ -308,15 +312,15 @@ export function clientAppFromProto(
   const predeployOverrides = serializeService(overrides.predeploy);
   const predeploy = proto.predeploy
     ? [
-      deserializeService({
-        service: serializedServiceFromProto({
-          name: "pre-deploy",
-          service: proto.predeploy,
-          isPredeploy: true,
+        deserializeService({
+          service: serializedServiceFromProto({
+            name: "pre-deploy",
+            service: proto.predeploy,
+            isPredeploy: true,
+          }),
+          override: predeployOverrides,
         }),
-        override: predeployOverrides,
-      }),
-    ]
+      ]
     : undefined;
 
   return {