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);
}
// await executeCommand(compose.serverId, command);
command += await getBuildComposeCommand(compose, deployment.logPath);
console.log(command);
// console.log(buildCommand);
try {
const { stderr, stdout } = await execAsyncRemote(
compose.serverId,
command,
);
console.log(stderr);
console.log(stdout);
} catch (error) {
console.log(error);
}
Promise.resolve()
.then(() => {
return execAsyncRemote(compose.serverId, command);
})
.then(() => {
return getBuildComposeCommand(compose, deployment.logPath);
})
.then(() => {
console.log(" ---- done ----");
});
} else {
if (compose.sourceType === "github") {
await cloneGithubRepository(compose, deployment.logPath, true);

View File

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

View File

@@ -144,7 +144,7 @@ export const writeDomainsToComposeRemote = async (
try {
if (compose.serverId) {
const composeString = dump(composeConverted, { lineWidth: 1000 });
return `echo "${composeString}" >> ${path};`;
return `printf '%s' '${composeString.replace(/'/g, "'\\''")}' > ${path}`;
}
} catch (error) {
throw error;
@@ -160,7 +160,7 @@ export const addDomainToCompose = async (
let result: ComposeSpecification | null;
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 {
result = await loadDockerCompose(compose);
}

View File

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

View File

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