chore: only make this apply to compose files

This commit is contained in:
djknaeckebrot
2024-12-23 08:27:45 +01:00
parent 3b4214e040
commit be2e70a17e

View File

@@ -83,7 +83,7 @@ export const createCompose = async (input: typeof apiCreateCompose._type) => {
}; };
export const createComposeByTemplate = async ( export const createComposeByTemplate = async (
input: typeof compose.$inferInsert, input: typeof compose.$inferInsert
) => { ) => {
const appName = cleanAppName(input.appName); const appName = cleanAppName(input.appName);
if (appName) { if (appName) {
@@ -140,7 +140,7 @@ export const findComposeById = async (composeId: string) => {
export const loadServices = async ( export const loadServices = async (
composeId: string, composeId: string,
type: "fetch" | "cache" = "fetch", type: "fetch" | "cache" = "fetch"
) => { ) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
@@ -163,7 +163,7 @@ export const loadServices = async (
if (compose.randomize && composeData) { if (compose.randomize && composeData) {
const randomizedCompose = randomizeSpecificationFile( const randomizedCompose = randomizeSpecificationFile(
composeData, composeData,
compose.suffix, compose.suffix
); );
composeData = randomizedCompose; composeData = randomizedCompose;
} }
@@ -182,7 +182,7 @@ export const loadServices = async (
export const updateCompose = async ( export const updateCompose = async (
composeId: string, composeId: string,
composeData: Partial<Compose>, composeData: Partial<Compose>
) => { ) => {
const { appName, ...rest } = composeData; const { appName, ...rest } = composeData;
const composeResult = await db const composeResult = await db
@@ -206,7 +206,9 @@ export const deployCompose = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${compose.projectId}/services/compose/${compose.composeId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${
compose.projectId
}/services/compose/${compose.composeId}?tab=deployments`;
const deployment = await createDeploymentCompose({ const deployment = await createDeploymentCompose({
composeId: composeId, composeId: composeId,
title: titleLog, title: titleLog,
@@ -308,7 +310,9 @@ export const deployRemoteCompose = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${compose.projectId}/services/compose/${compose.composeId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${
compose.projectId
}/services/compose/${compose.composeId}?tab=deployments`;
const deployment = await createDeploymentCompose({ const deployment = await createDeploymentCompose({
composeId: composeId, composeId: composeId,
title: titleLog, title: titleLog,
@@ -329,19 +333,19 @@ export const deployRemoteCompose = async ({
command += await getGitlabCloneCommand( command += await getGitlabCloneCommand(
compose, compose,
deployment.logPath, deployment.logPath,
true, true
); );
} else if (compose.sourceType === "bitbucket") { } else if (compose.sourceType === "bitbucket") {
command += await getBitbucketCloneCommand( command += await getBitbucketCloneCommand(
compose, compose,
deployment.logPath, deployment.logPath,
true, true
); );
} else if (compose.sourceType === "git") { } else if (compose.sourceType === "git") {
command += await getCustomGitCloneCommand( command += await getCustomGitCloneCommand(
compose, compose,
deployment.logPath, deployment.logPath,
true, true
); );
} else if (compose.sourceType === "raw") { } else if (compose.sourceType === "raw") {
command += getCreateComposeFileCommand(compose, deployment.logPath); command += getCreateComposeFileCommand(compose, deployment.logPath);
@@ -372,7 +376,7 @@ export const deployRemoteCompose = async ({
` `
echo "\n\n===================================EXTRA LOGS============================================" >> ${deployment.logPath}; echo "\n\n===================================EXTRA LOGS============================================" >> ${deployment.logPath};
echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath}; echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath};
echo "${encodedContent}" | base64 -d >> "${deployment.logPath}";`, echo "${encodedContent}" | base64 -d >> "${deployment.logPath}";`
); );
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
await updateCompose(composeId, { await updateCompose(composeId, {
@@ -425,7 +429,7 @@ export const rebuildRemoteCompose = async ({
` `
echo "\n\n===================================EXTRA LOGS============================================" >> ${deployment.logPath}; echo "\n\n===================================EXTRA LOGS============================================" >> ${deployment.logPath};
echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath}; echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath};
echo "${encodedContent}" | base64 -d >> "${deployment.logPath}";`, echo "${encodedContent}" | base64 -d >> "${deployment.logPath}";`
); );
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
await updateCompose(composeId, { await updateCompose(composeId, {
@@ -439,7 +443,7 @@ export const rebuildRemoteCompose = async ({
export const removeCompose = async ( export const removeCompose = async (
compose: Compose, compose: Compose,
deleteVolumes: boolean, deleteVolumes: boolean
) => { ) => {
try { try {
const { COMPOSE_PATH } = paths(!!compose.serverId); const { COMPOSE_PATH } = paths(!!compose.serverId);
@@ -448,14 +452,7 @@ export const removeCompose = async (
console.log("API: DELETE VOLUMES=", deleteVolumes); console.log("API: DELETE VOLUMES=", deleteVolumes);
if (compose.composeType === "stack") { if (compose.composeType === "stack") {
const listVolumesCommand = `docker volume ls --format \"{{.Name}}\" | grep ${compose.appName}`; const command = `cd ${projectPath} && docker stack rm ${compose.appName} && rm -rf ${projectPath}`;
const removeVolumesCommand = `${listVolumesCommand} | xargs -r docker volume rm`;
let command: string;
if (deleteVolumes) {
command = `cd ${projectPath} && docker stack rm ${compose.appName} && ${removeVolumesCommand} && rm -rf ${projectPath}`;
} else {
command = `cd ${projectPath} && docker stack rm ${compose.appName} && rm -rf ${projectPath}`;
}
if (compose.serverId) { if (compose.serverId) {
await execAsyncRemote(compose.serverId, command); await execAsyncRemote(compose.serverId, command);
@@ -496,7 +493,11 @@ export const startCompose = async (composeId: string) => {
if (compose.serverId) { if (compose.serverId) {
await execAsyncRemote( await execAsyncRemote(
compose.serverId, compose.serverId,
`cd ${join(COMPOSE_PATH, compose.appName, "code")} && docker compose -p ${compose.appName} up -d`, `cd ${join(
COMPOSE_PATH,
compose.appName,
"code"
)} && docker compose -p ${compose.appName} up -d`
); );
} else { } else {
await execAsync(`docker compose -p ${compose.appName} up -d`, { await execAsync(`docker compose -p ${compose.appName} up -d`, {
@@ -526,7 +527,9 @@ export const stopCompose = async (composeId: string) => {
if (compose.serverId) { if (compose.serverId) {
await execAsyncRemote( await execAsyncRemote(
compose.serverId, compose.serverId,
`cd ${join(COMPOSE_PATH, compose.appName)} && docker compose -p ${compose.appName} stop`, `cd ${join(COMPOSE_PATH, compose.appName)} && docker compose -p ${
compose.appName
} stop`
); );
} else { } else {
await execAsync(`docker compose -p ${compose.appName} stop`, { await execAsync(`docker compose -p ${compose.appName} stop`, {