MCPcopy
hub / github.com/Dokploy/dokploy / cloneGitRepository

Function cloneGitRepository

packages/server/src/utils/providers/git.ts:20–88  ·  view source on GitHub ↗
({
	type = "application",
	...entity
}: CloneGitRepository)

Source from the content-addressed store, hash-verified

18}
19
20export const cloneGitRepository = async ({
21 type = "application",
22 ...entity
23}: CloneGitRepository) => {
24 let command = "set -e;";
25 const {
26 appName,
27 customGitUrl,
28 customGitBranch,
29 customGitSSHKeyId,
30 enableSubmodules,
31 serverId,
32 outputPathOverride,
33 } = entity;
34 const { SSH_PATH, COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId);
35
36 if (!customGitUrl || !customGitBranch) {
37 command += `echo "Error: ❌ Repository not found"; exit 1;`;
38 return command;
39 }
40
41 const temporalKeyPath = path.join("/tmp", "id_rsa");
42
43 if (customGitSSHKeyId) {
44 const sshKey = await findSSHKeyById(customGitSSHKeyId);
45
46 command += `
47 echo "${sshKey.privateKey}" > ${temporalKeyPath}
48 chmod 600 ${temporalKeyPath};
49 `;
50 }
51 const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
52 const outputPath = outputPathOverride ?? join(basePath, appName, "code");
53 const knownHostsPath = path.join(SSH_PATH, "known_hosts");
54
55 if (!isHttpOrHttps(customGitUrl)) {
56 if (!customGitSSHKeyId) {
57 command += `echo "Error: ❌ You are trying to clone a ssh repository without a ssh key, please set a ssh key"; exit 1;`;
58 return command;
59 }
60 command += addHostToKnownHostsCommand(customGitUrl);
61 }
62 command += `rm -rf ${outputPath};`;
63 command += `mkdir -p ${outputPath};`;
64 command += `echo "Cloning Repo Custom ${customGitUrl} to ${outputPath}: ✅";`;
65
66 if (customGitSSHKeyId) {
67 await updateSSHKeyById({
68 sshKeyId: customGitSSHKeyId,
69 lastUsedAt: new Date().toISOString(),
70 });
71 }
72
73 if (customGitSSHKeyId) {
74 const sshKey = await findSSHKeyById(customGitSSHKeyId);
75 const { port } = sanitizeRepoPathSSH(customGitUrl);
76 const gitSshCommand = `ssh -i /tmp/id_rsa${port ? ` -p ${port}` : ""} -o UserKnownHostsFile=${knownHostsPath}`;
77 command += `echo "${sshKey.privateKey}" > /tmp/id_rsa;`;

Callers 5

cloneComposeFunction · 0.90
ensurePatchRepoFunction · 0.90
deployComposeFunction · 0.90
deployApplicationFunction · 0.90

Calls 6

pathsFunction · 0.90
findSSHKeyByIdFunction · 0.90
updateSSHKeyByIdFunction · 0.90
isHttpOrHttpsFunction · 0.85
sanitizeRepoPathSSHFunction · 0.85

Tested by

no test coverage detected