mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge remote-tracking branch 'origin/feature/delete-docker-volumes' into feature/delete-docker-volumes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -31,6 +32,7 @@ const deleteApplicationSchema = z.object({
|
||||
projectName: z.string().min(1, {
|
||||
message: "Application name is required",
|
||||
}),
|
||||
deleteVolumes: z.boolean(),
|
||||
});
|
||||
|
||||
type DeleteApplication = z.infer<typeof deleteApplicationSchema>;
|
||||
@@ -50,6 +52,7 @@ export const DeleteApplication = ({ applicationId }: Props) => {
|
||||
const form = useForm<DeleteApplication>({
|
||||
defaultValues: {
|
||||
projectName: "",
|
||||
deleteVolumes: false,
|
||||
},
|
||||
resolver: zodResolver(deleteApplicationSchema),
|
||||
});
|
||||
@@ -59,6 +62,7 @@ export const DeleteApplication = ({ applicationId }: Props) => {
|
||||
if (formData.projectName === expectedName) {
|
||||
await mutateAsync({
|
||||
applicationId,
|
||||
deleteVolumes: formData.deleteVolumes,
|
||||
})
|
||||
.then((data) => {
|
||||
push(`/dashboard/project/${data?.projectId}`);
|
||||
@@ -134,6 +138,27 @@ export const DeleteApplication = ({ applicationId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="deleteVolumes"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<div className="flex items-center">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
<FormLabel className="ml-2">
|
||||
Delete volumes associated with this compose
|
||||
</FormLabel>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import { db } from "@/server/db";
|
||||
import {
|
||||
apiCreateApplication,
|
||||
apiDeleteApplication,
|
||||
apiFindMonitoringStats,
|
||||
apiFindOneApplication,
|
||||
apiReloadApplication,
|
||||
@@ -142,7 +143,7 @@ export const applicationRouter = createTRPCRouter({
|
||||
}),
|
||||
|
||||
delete: protectedProcedure
|
||||
.input(apiFindOneApplication)
|
||||
.input(apiDeleteApplication)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
if (ctx.user.rol === "user") {
|
||||
await checkServiceAccess(
|
||||
@@ -178,7 +179,11 @@ export const applicationRouter = createTRPCRouter({
|
||||
async () =>
|
||||
await removeTraefikConfig(application.appName, application.serverId),
|
||||
async () =>
|
||||
await removeService(application?.appName, application.serverId),
|
||||
await removeService(
|
||||
application?.appName,
|
||||
application.serverId,
|
||||
input.deleteVolumes,
|
||||
),
|
||||
];
|
||||
|
||||
for (const operation of cleanupOperations) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { github } from "./github";
|
||||
import { gitlab } from "./gitlab";
|
||||
import { mounts } from "./mount";
|
||||
import { ports } from "./port";
|
||||
import { previewDeployments } from "./preview-deployments";
|
||||
import { projects } from "./project";
|
||||
import { redirects } from "./redirects";
|
||||
import { registry } from "./registry";
|
||||
@@ -25,7 +26,6 @@ import { server } from "./server";
|
||||
import { applicationStatus, certificateType } from "./shared";
|
||||
import { sshKeys } from "./ssh-key";
|
||||
import { generateAppName } from "./utils";
|
||||
import { previewDeployments } from "./preview-deployments";
|
||||
|
||||
export const sourceType = pgEnum("sourceType", [
|
||||
"docker",
|
||||
@@ -518,3 +518,8 @@ export const apiUpdateApplication = createSchema
|
||||
applicationId: z.string().min(1),
|
||||
})
|
||||
.omit({ serverId: true });
|
||||
|
||||
export const apiDeleteApplication = z.object({
|
||||
applicationId: z.string().min(1),
|
||||
deleteVolumes: z.boolean(),
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ interface RegistryAuth {
|
||||
export const pullImage = async (
|
||||
dockerImage: string,
|
||||
onData?: (data: any) => void,
|
||||
authConfig?: Partial<RegistryAuth>,
|
||||
authConfig?: Partial<RegistryAuth>
|
||||
): Promise<void> => {
|
||||
try {
|
||||
if (!dockerImage) {
|
||||
@@ -41,7 +41,7 @@ export const pullImage = async (
|
||||
"-p",
|
||||
authConfig.password,
|
||||
],
|
||||
onData,
|
||||
onData
|
||||
);
|
||||
}
|
||||
await spawnAsync("docker", ["pull", dockerImage], onData);
|
||||
@@ -54,7 +54,7 @@ export const pullRemoteImage = async (
|
||||
dockerImage: string,
|
||||
serverId: string,
|
||||
onData?: (data: any) => void,
|
||||
authConfig?: Partial<RegistryAuth>,
|
||||
authConfig?: Partial<RegistryAuth>
|
||||
): Promise<void> => {
|
||||
try {
|
||||
if (!dockerImage) {
|
||||
@@ -85,9 +85,9 @@ export const pullRemoteImage = async (
|
||||
},
|
||||
(event) => {
|
||||
onData?.(event);
|
||||
},
|
||||
}
|
||||
);
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -185,7 +185,7 @@ export const cleanUpInactiveContainers = async () => {
|
||||
try {
|
||||
const containers = await docker.listContainers({ all: true });
|
||||
const inactiveContainers = containers.filter(
|
||||
(container) => container.State !== "running",
|
||||
(container) => container.State !== "running"
|
||||
);
|
||||
|
||||
for (const container of inactiveContainers) {
|
||||
@@ -210,7 +210,7 @@ export const cleanUpSystemPrune = async (serverId?: string) => {
|
||||
if (serverId) {
|
||||
await execAsyncRemote(
|
||||
serverId,
|
||||
"docker system prune --all --force --volumes",
|
||||
"docker system prune --all --force --volumes"
|
||||
);
|
||||
} else {
|
||||
await execAsync("docker system prune --all --force --volumes");
|
||||
@@ -238,9 +238,17 @@ export const startServiceRemote = async (serverId: string, appName: string) => {
|
||||
export const removeService = async (
|
||||
appName: string,
|
||||
serverId?: string | null,
|
||||
deleteVolumes = false
|
||||
) => {
|
||||
try {
|
||||
const command = `docker service rm ${appName}`;
|
||||
let command: string;
|
||||
|
||||
if (deleteVolumes) {
|
||||
command = `docker service rm --force ${appName}`;
|
||||
} else {
|
||||
command = `docker service rm ${appName}`;
|
||||
}
|
||||
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, command);
|
||||
} else {
|
||||
@@ -253,7 +261,7 @@ export const removeService = async (
|
||||
|
||||
export const prepareEnvironmentVariables = (
|
||||
serviceEnv: string | null,
|
||||
projectEnv?: string | null,
|
||||
projectEnv?: string | null
|
||||
) => {
|
||||
const projectVars = parse(projectEnv ?? "");
|
||||
const serviceVars = parse(serviceEnv ?? "");
|
||||
@@ -421,7 +429,7 @@ export const generateFileMounts = (
|
||||
| MariadbNested
|
||||
| MysqlNested
|
||||
| PostgresNested
|
||||
| RedisNested,
|
||||
| RedisNested
|
||||
) => {
|
||||
const { mounts } = service;
|
||||
const { APPLICATIONS_PATH } = paths(!!service.serverId);
|
||||
@@ -447,7 +455,7 @@ export const generateFileMounts = (
|
||||
export const createFile = async (
|
||||
outputPath: string,
|
||||
filePath: string,
|
||||
content: string,
|
||||
content: string
|
||||
) => {
|
||||
try {
|
||||
const fullPath = path.join(outputPath, filePath);
|
||||
@@ -469,7 +477,7 @@ export const encodeBase64 = (content: string) =>
|
||||
export const getCreateFileCommand = (
|
||||
outputPath: string,
|
||||
filePath: string,
|
||||
content: string,
|
||||
content: string
|
||||
) => {
|
||||
const fullPath = path.join(outputPath, filePath);
|
||||
if (fullPath.endsWith(path.sep) || filePath.endsWith("/")) {
|
||||
@@ -509,7 +517,7 @@ export const getServiceContainer = async (appName: string) => {
|
||||
|
||||
export const getRemoteServiceContainer = async (
|
||||
serverId: string,
|
||||
appName: string,
|
||||
appName: string
|
||||
) => {
|
||||
try {
|
||||
const filter = {
|
||||
|
||||
Reference in New Issue
Block a user