From a5eb4b0a7251f4fae6ea7a46e56e2f6d6a834dd8 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:00:35 -0600 Subject: [PATCH] fix(compose): delete content when is remote server --- apps/dokploy/server/utils/providers/bitbucket.ts | 10 +++++----- apps/dokploy/server/utils/providers/github.ts | 10 +++++----- apps/dokploy/server/utils/providers/gitlab.ts | 10 +++++----- apps/dokploy/server/utils/providers/raw.ts | 1 + 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/dokploy/server/utils/providers/bitbucket.ts b/apps/dokploy/server/utils/providers/bitbucket.ts index c6eb0bbdd..3cbb4125a 100644 --- a/apps/dokploy/server/utils/providers/bitbucket.ts +++ b/apps/dokploy/server/utils/providers/bitbucket.ts @@ -147,15 +147,15 @@ export const cloneRawBitbucketRepositoryRemote = async (compose: Compose) => { const bitbucketProvider = await findBitbucketById(bitbucketId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - await recreateDirectory(outputPath); const repoclone = `bitbucket.org/${bitbucketOwner}/${bitbucketRepository}.git`; const cloneUrl = `https://${bitbucketProvider?.bitbucketUsername}:${bitbucketProvider?.appPassword}@${repoclone}`; try { - await execAsyncRemote( - serverId, - `git clone --branch ${bitbucketBranch} --depth 1 ${cloneUrl} ${outputPath}`, - ); + const command = ` + rm -rf ${outputPath}; + git clone --branch ${bitbucketBranch} --depth 1 ${cloneUrl} ${outputPath} + `; + await execAsyncRemote(serverId, command); } catch (error) { throw error; } diff --git a/apps/dokploy/server/utils/providers/github.ts b/apps/dokploy/server/utils/providers/github.ts index 68a401b2e..e828d010b 100644 --- a/apps/dokploy/server/utils/providers/github.ts +++ b/apps/dokploy/server/utils/providers/github.ts @@ -271,13 +271,13 @@ export const cloneRawGithubRepositoryRemote = async (compose: Compose) => { const octokit = authGithub(githubProvider); const token = await getGithubToken(octokit); const repoclone = `github.com/${owner}/${repository}.git`; - await recreateDirectory(outputPath); const cloneUrl = `https://oauth2:${token}@${repoclone}`; try { - await execAsyncRemote( - serverId, - `git clone --branch ${branch} --depth 1 ${cloneUrl} ${outputPath}`, - ); + const command = ` + rm -rf ${outputPath}; + git clone --branch ${branch} --depth 1 ${cloneUrl} ${outputPath} + `; + await execAsyncRemote(serverId, command); } catch (error) { throw error; } diff --git a/apps/dokploy/server/utils/providers/gitlab.ts b/apps/dokploy/server/utils/providers/gitlab.ts index 95649f5d5..43f868d45 100644 --- a/apps/dokploy/server/utils/providers/gitlab.ts +++ b/apps/dokploy/server/utils/providers/gitlab.ts @@ -390,14 +390,14 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => { await refreshGitlabToken(gitlabId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - await recreateDirectory(outputPath); const repoclone = `gitlab.com/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; try { - await execAsyncRemote( - serverId, - `git clone --branch ${branch} --depth 1 ${cloneUrl} ${outputPath}`, - ); + const command = ` + rm -rf ${outputPath}; + git clone --branch ${branch} --depth 1 ${cloneUrl} ${outputPath} + `; + await execAsyncRemote(serverId, command); } catch (error) { throw error; } diff --git a/apps/dokploy/server/utils/providers/raw.ts b/apps/dokploy/server/utils/providers/raw.ts index f0fdcb5c1..238216fa0 100644 --- a/apps/dokploy/server/utils/providers/raw.ts +++ b/apps/dokploy/server/utils/providers/raw.ts @@ -70,6 +70,7 @@ export const createComposeFileRawRemote = async (compose: Compose) => { try { const encodedContent = encodeBase64(composeFile); const command = ` + rm -rf ${outputPath}; mkdir -p ${outputPath}; echo "${encodedContent}" | base64 -d > "${filePath}"; `;