mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-07 04:22:16 +00:00
Merge pull request #2164 from croatialu/fix/gitlab-deployments
fix(gitlab): Support dynamically generating clone URLs based on protocols
This commit is contained in:
@@ -84,6 +84,24 @@ export type ApplicationWithGitlab = InferResultType<
|
|||||||
|
|
||||||
export type ComposeWithGitlab = InferResultType<"compose", { gitlab: true }>;
|
export type ComposeWithGitlab = InferResultType<"compose", { gitlab: true }>;
|
||||||
|
|
||||||
|
export type GitlabInfo =
|
||||||
|
| ApplicationWithGitlab["gitlab"]
|
||||||
|
| ComposeWithGitlab["gitlab"];
|
||||||
|
|
||||||
|
const getGitlabRepoClone = (
|
||||||
|
gitlab: GitlabInfo,
|
||||||
|
gitlabPathNamespace: string | null,
|
||||||
|
) => {
|
||||||
|
const repoClone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`;
|
||||||
|
return repoClone;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGitlabCloneUrl = (gitlab: GitlabInfo, repoClone: string) => {
|
||||||
|
const isSecure = gitlab?.gitlabUrl.startsWith("https://");
|
||||||
|
const cloneUrl = `http${isSecure ? "s" : ""}://oauth2:${gitlab?.accessToken}@${repoClone}`;
|
||||||
|
return cloneUrl;
|
||||||
|
};
|
||||||
|
|
||||||
export const cloneGitlabRepository = async (
|
export const cloneGitlabRepository = async (
|
||||||
entity: ApplicationWithGitlab | ComposeWithGitlab,
|
entity: ApplicationWithGitlab | ComposeWithGitlab,
|
||||||
logPath: string,
|
logPath: string,
|
||||||
@@ -128,11 +146,10 @@ export const cloneGitlabRepository = async (
|
|||||||
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
|
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
|
||||||
const outputPath = join(basePath, appName, "code");
|
const outputPath = join(basePath, appName, "code");
|
||||||
await recreateDirectory(outputPath);
|
await recreateDirectory(outputPath);
|
||||||
const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`;
|
const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace);
|
||||||
const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`;
|
const cloneUrl = getGitlabCloneUrl(gitlab, repoClone);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`);
|
writeStream.write(`\nCloning Repo ${repoClone} to ${outputPath}: ✅\n`);
|
||||||
const cloneArgs = [
|
const cloneArgs = [
|
||||||
"clone",
|
"clone",
|
||||||
"--branch",
|
"--branch",
|
||||||
@@ -150,7 +167,7 @@ export const cloneGitlabRepository = async (
|
|||||||
writeStream.write(data);
|
writeStream.write(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
writeStream.write(`\nCloned ${repoclone}: ✅\n`);
|
writeStream.write(`\nCloned ${repoClone}: ✅\n`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
writeStream.write(`ERROR Cloning: ${error}: ❌`);
|
writeStream.write(`ERROR Cloning: ${error}: ❌`);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -221,17 +238,16 @@ export const getGitlabCloneCommand = async (
|
|||||||
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
|
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
|
||||||
const outputPath = join(basePath, appName, "code");
|
const outputPath = join(basePath, appName, "code");
|
||||||
await recreateDirectory(outputPath);
|
await recreateDirectory(outputPath);
|
||||||
const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`;
|
const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace);
|
||||||
const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`;
|
const cloneUrl = getGitlabCloneUrl(gitlab, repoClone);
|
||||||
|
|
||||||
const cloneCommand = `
|
const cloneCommand = `
|
||||||
rm -rf ${outputPath};
|
rm -rf ${outputPath};
|
||||||
mkdir -p ${outputPath};
|
mkdir -p ${outputPath};
|
||||||
if ! git clone --branch ${gitlabBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} --progress ${cloneUrl} ${outputPath} >> ${logPath} 2>&1; then
|
if ! git clone --branch ${gitlabBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} --progress ${cloneUrl} ${outputPath} >> ${logPath} 2>&1; then
|
||||||
echo "❌ [ERROR] Fail to clone the repository ${repoclone}" >> ${logPath};
|
echo "❌ [ERROR] Fail to clone the repository ${repoClone}" >> ${logPath};
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
echo "Cloned ${repoclone} to ${outputPath}: ✅" >> ${logPath};
|
echo "Cloned ${repoClone} to ${outputPath}: ✅" >> ${logPath};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return cloneCommand;
|
return cloneCommand;
|
||||||
@@ -340,11 +356,8 @@ export const cloneRawGitlabRepository = async (entity: Compose) => {
|
|||||||
const basePath = COMPOSE_PATH;
|
const basePath = COMPOSE_PATH;
|
||||||
const outputPath = join(basePath, appName, "code");
|
const outputPath = join(basePath, appName, "code");
|
||||||
await recreateDirectory(outputPath);
|
await recreateDirectory(outputPath);
|
||||||
const gitlabUrl = gitlabProvider.gitlabUrl;
|
const repoClone = getGitlabRepoClone(gitlabProvider, gitlabPathNamespace);
|
||||||
// What happen with oauth in self hosted instances?
|
const cloneUrl = getGitlabCloneUrl(gitlabProvider, repoClone);
|
||||||
const repoclone = `${gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`;
|
|
||||||
const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cloneArgs = [
|
const cloneArgs = [
|
||||||
"clone",
|
"clone",
|
||||||
@@ -390,8 +403,8 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => {
|
|||||||
await refreshGitlabToken(gitlabId);
|
await refreshGitlabToken(gitlabId);
|
||||||
const basePath = COMPOSE_PATH;
|
const basePath = COMPOSE_PATH;
|
||||||
const outputPath = join(basePath, appName, "code");
|
const outputPath = join(basePath, appName, "code");
|
||||||
const repoclone = `${gitlabProvider.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`;
|
const repoClone = getGitlabRepoClone(gitlabProvider, gitlabPathNamespace);
|
||||||
const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`;
|
const cloneUrl = getGitlabCloneUrl(gitlabProvider, repoClone);
|
||||||
try {
|
try {
|
||||||
const command = `
|
const command = `
|
||||||
rm -rf ${outputPath};
|
rm -rf ${outputPath};
|
||||||
|
|||||||
Reference in New Issue
Block a user