import { AlertBlock } from "@/components/shared/alert-block"; import { CodeEditor } from "@/components/shared/code-editor"; import { Button } from "@/components/ui/button"; import { DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { AlertTriangle } from "lucide-react"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; interface Props { composeId: string; } const schema = z.object({ suffix: z.string(), randomize: z.boolean().optional(), }); type Schema = z.infer; export const RandomizeCompose = ({ composeId }: Props) => { const utils = api.useUtils(); const [compose, setCompose] = useState(""); const [_isOpen, _setIsOpen] = useState(false); const { mutateAsync, error, isError } = api.compose.randomizeCompose.useMutation(); const { mutateAsync: updateCompose } = api.compose.update.useMutation(); const { data, refetch } = api.compose.one.useQuery( { composeId }, { enabled: !!composeId }, ); const form = useForm({ defaultValues: { suffix: "", randomize: false, }, resolver: zodResolver(schema), }); const suffix = form.watch("suffix"); useEffect(() => { randomizeCompose(); if (data) { form.reset({ suffix: data?.suffix || "", randomize: data?.randomize || false, }); } }, [form, form.reset, form.formState.isSubmitSuccessful, data]); const onSubmit = async (formData: Schema) => { await updateCompose({ composeId, suffix: formData?.suffix || "", randomize: formData?.randomize || false, }) .then(async (_data) => { await randomizeCompose(); await refetch(); toast.success("Compose updated"); }) .catch(() => { toast.error("Error randomizing the compose"); }); }; const randomizeCompose = async () => { await mutateAsync({ composeId, suffix, }).then(async (data) => { await utils.project.all.invalidate(); setCompose(data); }); }; return (
Randomize Compose (Experimental) Use this in case you want to deploy the same compose file and you have conflicts with some property like volumes, networks, etc.
This will randomize the compose file and will add a suffix to the property to avoid conflicts
  • volumes
  • networks
  • services
  • configs
  • secrets
When you activate this option, we will include a env `COMPOSE_PREFIX` variable to the compose file so you can use it in your compose file.
{isError && {error?.message}}
{isError && (
{error?.message}
)}
( Suffix )} /> (
Apply Randomize Apply randomize to the compose file.
)} />
						
					
); };