mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: compose app
This commit is contained in:
@@ -31,11 +31,6 @@ import {
|
||||
removeDirectoryCode,
|
||||
removeMonitoringDirectory,
|
||||
} from "@/server/utils/filesystem/directory";
|
||||
import {
|
||||
generateSSHKey,
|
||||
readSSHPublicKey,
|
||||
removeSSHKey,
|
||||
} from "@/server/utils/filesystem/ssh";
|
||||
import {
|
||||
readConfig,
|
||||
removeTraefikConfig,
|
||||
@@ -130,7 +125,6 @@ export const applicationRouter = createTRPCRouter({
|
||||
async () => await removeMonitoringDirectory(application?.appName),
|
||||
async () => await removeTraefikConfig(application?.appName),
|
||||
async () => await removeService(application?.appName),
|
||||
async () => await removeSSHKey(application?.appName),
|
||||
];
|
||||
|
||||
for (const operation of cleanupOperations) {
|
||||
@@ -240,32 +234,6 @@ export const applicationRouter = createTRPCRouter({
|
||||
applicationStatus: "idle",
|
||||
});
|
||||
|
||||
return true;
|
||||
}),
|
||||
generateSSHKey: protectedProcedure
|
||||
.input(apiFindOneApplication)
|
||||
.mutation(async ({ input }) => {
|
||||
const application = await findApplicationById(input.applicationId);
|
||||
try {
|
||||
await generateSSHKey(application.appName);
|
||||
const file = await readSSHPublicKey(application.appName);
|
||||
|
||||
// await updateApplication(input.applicationId, {
|
||||
// customGitSSHKey: file,
|
||||
// });
|
||||
} catch (error) {}
|
||||
|
||||
return true;
|
||||
}),
|
||||
removeSSHKey: protectedProcedure
|
||||
.input(apiFindOneApplication)
|
||||
.mutation(async ({ input }) => {
|
||||
const application = await findApplicationById(input.applicationId);
|
||||
await removeSSHKey(application.appName);
|
||||
// await updateApplication(input.applicationId, {
|
||||
// customGitSSHKey: null,
|
||||
// });
|
||||
|
||||
return true;
|
||||
}),
|
||||
markRunning: protectedProcedure
|
||||
|
||||
@@ -16,11 +16,6 @@ import { myQueue } from "@/server/queues/queueSetup";
|
||||
import { createCommand } from "@/server/utils/builders/compose";
|
||||
import { randomizeComposeFile } from "@/server/utils/docker/compose";
|
||||
import { removeComposeDirectory } from "@/server/utils/filesystem/directory";
|
||||
import {
|
||||
generateSSHKey,
|
||||
readSSHPublicKey,
|
||||
removeSSHKey,
|
||||
} from "@/server/utils/filesystem/ssh";
|
||||
import { templates } from "@/templates/templates";
|
||||
import type { TemplatesKeys } from "@/templates/types/templates-data.type";
|
||||
import {
|
||||
@@ -102,7 +97,6 @@ export const composeRouter = createTRPCRouter({
|
||||
async () => await removeCompose(composeResult),
|
||||
async () => await removeDeploymentsByComposeId(composeResult),
|
||||
async () => await removeComposeDirectory(composeResult.appName),
|
||||
async () => await removeSSHKey(composeResult.appName),
|
||||
];
|
||||
|
||||
for (const operation of cleanupOperations) {
|
||||
@@ -181,38 +175,12 @@ export const composeRouter = createTRPCRouter({
|
||||
const command = createCommand(compose);
|
||||
return `docker ${command}`;
|
||||
}),
|
||||
generateSSHKey: protectedProcedure
|
||||
.input(apiFindCompose)
|
||||
.mutation(async ({ input }) => {
|
||||
const compose = await findComposeById(input.composeId);
|
||||
try {
|
||||
await generateSSHKey(compose.appName);
|
||||
const file = await readSSHPublicKey(compose.appName);
|
||||
|
||||
await updateCompose(input.composeId, {
|
||||
customGitSSHKey: file,
|
||||
});
|
||||
} catch (error) {}
|
||||
|
||||
return true;
|
||||
}),
|
||||
refreshToken: protectedProcedure
|
||||
.input(apiFindCompose)
|
||||
.mutation(async ({ input }) => {
|
||||
await updateCompose(input.composeId, {
|
||||
refreshToken: nanoid(),
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
removeSSHKey: protectedProcedure
|
||||
.input(apiFindCompose)
|
||||
.mutation(async ({ input }) => {
|
||||
const compose = await findComposeById(input.composeId);
|
||||
await removeSSHKey(compose.appName);
|
||||
await updateCompose(input.composeId, {
|
||||
customGitSSHKey: null,
|
||||
});
|
||||
|
||||
return true;
|
||||
}),
|
||||
deployTemplate: protectedProcedure
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { sshKeys } from "@/server/db/schema/ssh-key";
|
||||
import { generatePassword } from "@/templates/utils";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { boolean, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
|
||||
@@ -41,7 +42,12 @@ export const compose = pgTable("compose", {
|
||||
// Git
|
||||
customGitUrl: text("customGitUrl"),
|
||||
customGitBranch: text("customGitBranch"),
|
||||
customGitSSHKey: text("customGitSSHKey"),
|
||||
customGitSSHKeyId: text("customGitSSHKeyId").references(
|
||||
() => sshKeys.sshKeyId,
|
||||
{
|
||||
onDelete: "set null",
|
||||
},
|
||||
),
|
||||
//
|
||||
command: text("command").notNull().default(""),
|
||||
//
|
||||
@@ -62,6 +68,10 @@ export const composeRelations = relations(compose, ({ one, many }) => ({
|
||||
}),
|
||||
deployments: many(deployments),
|
||||
mounts: many(mounts),
|
||||
customGitSSHKey: one(sshKeys, {
|
||||
fields: [compose.customGitSSHKeyId],
|
||||
references: [sshKeys.sshKeyId],
|
||||
}),
|
||||
}));
|
||||
|
||||
const createSchema = createInsertSchema(compose, {
|
||||
@@ -70,6 +80,7 @@ const createSchema = createInsertSchema(compose, {
|
||||
env: z.string().optional(),
|
||||
composeFile: z.string().min(1),
|
||||
projectId: z.string(),
|
||||
customGitSSHKeyId: z.string().optional(),
|
||||
command: z.string().optional(),
|
||||
composePath: z.string().min(1),
|
||||
composeType: z.enum(["docker-compose", "stack"]).optional(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { applications } from "@/server/db/schema/application";
|
||||
import { compose } from "@/server/db/schema/compose";
|
||||
import { sshKeyCreate } from "@/server/db/validations";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text, time } from "drizzle-orm/pg-core";
|
||||
@@ -21,6 +22,7 @@ export const sshKeys = pgTable("ssh-key", {
|
||||
|
||||
export const sshKeysRelations = relations(sshKeys, ({ many }) => ({
|
||||
applications: many(applications),
|
||||
compose: many(compose),
|
||||
}));
|
||||
|
||||
const createSchema = createInsertSchema(
|
||||
|
||||
@@ -39,7 +39,7 @@ export const cloneGitRepository = async (
|
||||
writeStream.write(
|
||||
`\nCloning Repo Custom ${customGitUrl} to ${outputPath}: ✅\n`,
|
||||
);
|
||||
console.log(customGitSSHKeyId);
|
||||
|
||||
await spawnAsync(
|
||||
"git",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user