From 2ee204d4c8a4aa62d4061c68ff7a395765cedc28 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sat, 2 Apr 2022 15:53:31 -0700 Subject: [PATCH] fix remote clone --- core/src/messages/builds/update.ts | 1 + core/src/messages/deployments/clone.ts | 32 +++++++++++++++++++------ core/src/messages/deployments/update.ts | 10 +++----- util/helpers.ts | 13 ++++++---- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/core/src/messages/builds/update.ts b/core/src/messages/builds/update.ts index 99d01f4b0..f45f60ea0 100644 --- a/core/src/messages/builds/update.ts +++ b/core/src/messages/builds/update.ts @@ -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, diff --git a/core/src/messages/deployments/clone.ts b/core/src/messages/deployments/clone.ts index 3b60c6706..ac95c86ac 100644 --- a/core/src/messages/deployments/clone.ts +++ b/core/src/messages/deployments/clone.ts @@ -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, diff --git a/core/src/messages/deployments/update.ts b/core/src/messages/deployments/update.ts index 30883b4c4..2027d028d 100644 --- a/core/src/messages/deployments/update.ts +++ b/core/src/messages/deployments/update.ts @@ -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 } diff --git a/util/helpers.ts b/util/helpers.ts index b868b88e4..fbc916f2e 100644 --- a/util/helpers.ts +++ b/util/helpers.ts @@ -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); -} \ No newline at end of file +}