feat(remote): add docker compose remote

This commit is contained in:
Mauricio Siu
2024-09-12 01:33:33 -06:00
parent a8d714c20d
commit bf58ae0f0f
5 changed files with 30 additions and 24 deletions

View File

@@ -241,22 +241,16 @@ export const deployCompose = async ({
command += getCreateComposeFileCommand(compose); command += getCreateComposeFileCommand(compose);
} }
// await executeCommand(compose.serverId, command); Promise.resolve()
command += await getBuildComposeCommand(compose, deployment.logPath); .then(() => {
return execAsyncRemote(compose.serverId, command);
console.log(command); })
.then(() => {
// console.log(buildCommand); return getBuildComposeCommand(compose, deployment.logPath);
try { })
const { stderr, stdout } = await execAsyncRemote( .then(() => {
compose.serverId, console.log(" ---- done ----");
command, });
);
console.log(stderr);
console.log(stdout);
} catch (error) {
console.log(error);
}
} else { } else {
if (compose.sourceType === "github") { if (compose.sourceType === "github") {
await cloneGithubRepository(compose, deployment.logPath, true); await cloneGithubRepository(compose, deployment.logPath, true);

View File

@@ -14,6 +14,7 @@ import {
} from "../docker/domain"; } from "../docker/domain";
import { prepareEnvironmentVariables } from "../docker/utils"; import { prepareEnvironmentVariables } from "../docker/utils";
import { spawnAsync } from "../process/spawnAsync"; import { spawnAsync } from "../process/spawnAsync";
import { execAsyncRemote } from "../process/execAsync";
export type ComposeNested = InferResultType< export type ComposeNested = InferResultType<
"compose", "compose",
@@ -97,12 +98,16 @@ Compose Type: ${composeType} ✅`;
}); });
const bashCommand = ` const bashCommand = `
${newCompose}
echo "${logBox}" >> ${logPath}; echo "${logBox}" >> ${logPath};
${newCompose}
${envCommand}
cd ${projectPath} || exit 1; cd ${projectPath} || exit 1;
docker ${command.split(" ").join(" ")} >> ${logPath} 2>&1; docker ${command.split(" ").join(" ")} >> ${logPath} 2>&1;
echo "Docker Compose Deployed: ✅" >> ${logPath}; echo "Docker Compose Deployed: ✅" >> ${logPath};
`; `;
await execAsyncRemote(compose.serverId, bashCommand);
return bashCommand; return bashCommand;
}; };
@@ -180,7 +185,7 @@ export const getCreateEnvFileCommand = (compose: ComposeNested) => {
const envFileContent = prepareEnvironmentVariables(envContent).join("\n"); const envFileContent = prepareEnvironmentVariables(envContent).join("\n");
return ` return `
mkdir -p ${envFilePath}; mkdir -p ${envFilePath};
echo "${envFileContent}" > ${envFilePath} 2>/dev/null; echo "${envFileContent}" > ${envFilePath};
`; `;
}; };

View File

@@ -144,7 +144,7 @@ export const writeDomainsToComposeRemote = async (
try { try {
if (compose.serverId) { if (compose.serverId) {
const composeString = dump(composeConverted, { lineWidth: 1000 }); const composeString = dump(composeConverted, { lineWidth: 1000 });
return `echo "${composeString}" >> ${path};`; return `printf '%s' '${composeString.replace(/'/g, "'\\''")}' > ${path}`;
} }
} catch (error) { } catch (error) {
throw error; throw error;
@@ -160,7 +160,7 @@ export const addDomainToCompose = async (
let result: ComposeSpecification | null; let result: ComposeSpecification | null;
if (compose.serverId) { if (compose.serverId) {
result = await loadDockerComposeRemote(compose); result = await loadDockerComposeRemote(compose); // aca hay que ir al servidor e ir a traer el compose file al servidor
} else { } else {
result = await loadDockerCompose(compose); result = await loadDockerCompose(compose);
} }

View File

@@ -94,11 +94,18 @@ export const getCustomGitCloneCommand = async (
customGitUrl?: string | null; customGitUrl?: string | null;
customGitBranch?: string | null; customGitBranch?: string | null;
customGitSSHKeyId?: string | null; customGitSSHKeyId?: string | null;
serverId: string | null;
}, },
logPath: string, logPath: string,
isCompose = false, isCompose = false,
) => { ) => {
const { appName, customGitUrl, customGitBranch, customGitSSHKeyId } = entity; const {
appName,
customGitUrl,
customGitBranch,
customGitSSHKeyId,
serverId,
} = entity;
if (!customGitUrl || !customGitBranch) { if (!customGitUrl || !customGitBranch) {
throw new TRPCError({ throw new TRPCError({
@@ -141,7 +148,7 @@ export const getCustomGitCloneCommand = async (
fi fi
`, `,
); );
command.push(`echo "Cloned Custom Git ${customGitUrl}: ✅" >> ${logPath}`); command.push(`echo "Cloned Custom Git ${customGitUrl}: ✅" >> ${logPath};`);
return command.join("\n"); return command.join("\n");
} catch (error) { } catch (error) {
console.log(error); console.log(error);

View File

@@ -11,7 +11,7 @@ export const connectSSH = async (serverId: string) => {
return new Promise<Client>((resolve, reject) => { return new Promise<Client>((resolve, reject) => {
client client
.on("ready", () => resolve(client)) .once("ready", () => resolve(client))
.on("error", reject) .on("error", reject)
.connect({ .connect({
host: server.ipAddress, host: server.ipAddress,