fix remote clone

This commit is contained in:
mbecker20
2022-04-02 15:53:31 -07:00
parent 43e18f93be
commit 2ee204d4c8
4 changed files with 38 additions and 18 deletions

View File

@@ -45,6 +45,7 @@ async function updateBuild(
}
// maybe do something more with deployments
}
(build.owners as any) = false;
await app.builds.updateOne({ _id: build._id }, build);
addBuildUpdate(
app,

View File

@@ -1,6 +1,7 @@
import { Deployment, User } from "@monitor/types";
import { clone, execute, mergeCommandLogError } from "@monitor/util";
import { FastifyInstance } from "fastify";
import { join } from "path";
import { CLONE_DEPLOYMENT_REPO } from "@monitor/util";
import { DEPLOYMENT_REPO_PATH, SECRETS } from "../../config";
import { clonePeriphery } from "../../util/periphery/git";
@@ -19,6 +20,7 @@ async function cloneRepo(
subfolder,
githubAccount,
onPull,
onClone,
_id,
} = deployment;
const server =
@@ -39,20 +41,32 @@ async function cloneRepo(
return;
}
const cloneCle = server.isCore
? await clonePeriphery(server, deployment)
: await clone(
? await clone(
repo!,
DEPLOYMENT_REPO_PATH + containerName!,
subfolder,
branch,
githubAccount && SECRETS.GITHUB_ACCOUNTS[githubAccount]
);
)
: await clonePeriphery(server, deployment);
const onCloneCle =
!server && onClone
? await execute(
`cd ${join(
DEPLOYMENT_REPO_PATH,
containerName!,
onClone.path || ""
)} && ${onClone.command}`
)
: undefined;
const onPullCle =
!server && onPull
? await execute(
`cd ${DEPLOYMENT_REPO_PATH + containerName!}${
onPull.path ? (onPull.path[0] === "/" ? "" : "/") : ""
}${onPull.path ? onPull.path : ""} && ${onPull.command}`
`cd ${join(
DEPLOYMENT_REPO_PATH,
containerName!,
onPull.path || ""
)} && ${onPull.command}`
)
: undefined;
const { command, log, isError } = mergeCommandLogError(
@@ -60,7 +74,11 @@ async function cloneRepo(
name: "clone",
cle: cloneCle,
},
{ name: "post clone", cle: onPullCle }
{
name: "on clone",
cle: onCloneCle,
},
{ name: "on pull", cle: onPullCle }
);
addDeploymentUpdate(
app,

View File

@@ -3,7 +3,7 @@ import { deploymentChangelog, prettyStringify, UPDATE_DEPLOYMENT } from "@monito
import { FastifyInstance } from "fastify";
import { remove } from "fs-extra";
import { DEPLOYMENT_REPO_PATH, PERMISSIONS_DENY_LOG } from "../../config";
import { clonePeriphery } from "../../util/periphery/git";
import { clonePeriphery, deleteRepoPeriphery } from "../../util/periphery/git";
import { addDeploymentUpdate } from "../../util/updates";
import cloneRepo from "./clone";
@@ -38,14 +38,10 @@ async function updateDeployment(
? undefined
: await app.servers.findById(deployment.serverID!);
if (deployment.repo) {
if (server) {
await clonePeriphery(server, deployment);
} else {
await cloneRepo(app, user, deployment);
}
await cloneRepo(app, user, deployment);
} else {
if (server) {
// need to make this route
await deleteRepoPeriphery(server, deployment);
} else {
await remove(DEPLOYMENT_REPO_PATH + deployment.containerName); // need to have this on periphery as well
}

View File

@@ -75,8 +75,13 @@ export function mergeCommandLogError(
name: string;
cle: CommandLogError;
}[];
const onlyOne = _cle.length === 1;
const command = _cle.reduce((prev, curr) => {
return prev + (prev && "\n\n") + `${curr.name}: ${curr.cle.command}`;
return (
prev +
(prev && "\n\n") +
`${onlyOne ? curr.name + ": " : ""}${curr.cle.command}`
);
}, "");
const log = _cle.reduce(
(log, curr) => {
@@ -84,13 +89,13 @@ export function mergeCommandLogError(
log.stdout +
(log.stdout && (curr.cle.log.stdout ? "\n\n" : "")) +
curr.cle.log.stdout
? `${curr.name}:\n${curr.cle.log.stdout}`
? `${onlyOne ? curr.name + ":\n" : ""}${curr.cle.log.stdout}`
: "";
log.stderr =
log.stderr +
(log.stderr && (curr.cle.log.stderr ? "\n\n" : "")) +
curr.cle.log.stderr
? `${curr.name}:\n${curr.cle.log.stderr}`
? `${onlyOne ? curr.name + ":\n" : ""}${curr.cle.log.stderr}`
: "";
return log;
},
@@ -110,4 +115,4 @@ export function trailingSlash(str: string) {
export function prettyStringify(json: any) {
return JSON.stringify(json, undefined, 2);
}
}