From afb9f74faa2d96e0f7e3b6861d38d275b52ce29f Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Tue, 17 Oct 2023 12:46:49 -0400 Subject: [PATCH] make run command optional if using dockerfile (#3820) --- .../services-settings/tabs/Main.tsx | 98 +++++++++++-------- .../services-settings/tabs/WebTabs.tsx | 1 - 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/Main.tsx b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/Main.tsx index 1811f885e3..c9b7bc3fe6 100644 --- a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/Main.tsx +++ b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/Main.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from "react"; +import React, { useCallback, useMemo } from "react"; import cronstrue from "cronstrue"; import {Controller, useFormContext} from "react-hook-form"; @@ -9,6 +9,8 @@ import { ClientService } from "lib/porter-apps/services"; import Text from "components/porter/Text"; import Link from "components/porter/Link"; import Checkbox from "components/porter/Checkbox"; +import { match } from "ts-pattern"; +import Tooltip from "components/porter/Tooltip"; type MainTabProps = { index: number; @@ -22,6 +24,12 @@ const MainTab: React.FC = ({ index, service, isPredeploy = false } const run = watch(`app.services.${index}.run.value`); const predeployRun = watch(`app.predeploy.${index}.run.value`); + const build = watch("app.build"); + const source = watch("source"); + const isRunCommandOptional = useMemo(() => { + return build.method === "docker" || source.type === "docker-registry"; + }, [build.method, source.type]); + const getScheduleDescription = useCallback((cron: string) => { try { return ( @@ -39,36 +47,42 @@ const MainTab: React.FC = ({ index, service, isPredeploy = false } } }, []); - const getValidStartCommand = useCallback((run: string) => { - if (run && (run.includes("&&") || run.includes(";"))) { - return ( - <> - - Multiple commands are not supported at this time. To run multiple commands, move all commands into a script that can be run from a single endpoint. - - ); - } else { - return ( - <> - ); - } - }, []); + const isStartCommandValid = useMemo(() => { + const runCommand = isPredeploy ? predeployRun : run; + return runCommand.includes("&&") || runCommand.includes(";"); + }, [isPredeploy, predeployRun, run]); + // if your Docker image has a CMD or ENTRYPOINT return ( <> + {isRunCommandOptional ? + + Start command (optional) + + : + Start command (required) + } + - - {getValidStartCommand(isPredeploy ? predeployRun :run)} - {service.config.type === "job" && ( + {isStartCommandValid && + <> + + Chained commands are not supported at this time. To run multiple commands, move all commands into a script that can be run from a single endpoint (e.g. bash ./run.sh). + + } + {match(service.config) + .with({ type: "job" }, (jobConfig) => ( <> = ({ index, service, isPredeploy = false } label="Cron schedule" placeholder="ex: */5 * * * *" width="300px" - disabled={service.config.cron.readOnly} + disabled={jobConfig.cron.readOnly} disabledTooltip={ "You may only edit this field in your porter.yaml." } @@ -85,27 +99,29 @@ const MainTab: React.FC = ({ index, service, isPredeploy = false } {getScheduleDescription(cron)} - - ( - { - onChange(!value); - }} - disabledTooltip={ - "You may only edit this field in your porter.yaml." - } - > - Suspend cron job - - )} - /> + + ( + { + onChange(!value); + }} + disabledTooltip={ + "You may only edit this field in your porter.yaml." + } + > + Suspend cron job + + )} + /> - )} + )) + .otherwise(() => null) + } ); }; diff --git a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/WebTabs.tsx b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/WebTabs.tsx index fd00419aca..16fbe01f81 100644 --- a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/WebTabs.tsx +++ b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/WebTabs.tsx @@ -7,7 +7,6 @@ import Networking from "./Networking"; import MainTab from "./Main"; import Resources from "./Resources"; import Health from "./Health"; -import { useLatestRevision } from "main/home/app-dashboard/app-view/LatestRevisionContext"; interface Props { index: number;