improve queries to just take server as input

This commit is contained in:
mbecker20
2022-03-16 14:40:21 -07:00
parent 6f1479e9ae
commit 4250e93b60
5 changed files with 89 additions and 33 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ async function cloneRepo(
deployment;
const server = serverID ? await app.servers.findById(serverID) : undefined;
const { command, log, isError } = server
? await clonePeriphery(server.address, server.passkey, deployment)
? await clonePeriphery(server, deployment)
: await clone(
repo!,
DEPLOYMENT_REPO_PATH + containerName!,
+61
View File
@@ -0,0 +1,61 @@
import { User } from "@monitor/types";
import { dockerRun } from "@monitor/util";
import { FastifyInstance } from "fastify";
import { DEPLOY } from ".";
import { PERMISSIONS_DENY_LOG, SYSROOT } from "../../config";
import { deletePeripheryContainer } from "../../util/periphery/container";
import { deployPeriphery } from "../../util/periphery/deploy";
import { addDeploymentUpdate } from "../../util/updates";
async function deployDeployment(
app: FastifyInstance,
user: User,
{ deploymentID, note }: { deploymentID: string; note?: string },
) {
const deployment = await app.deployments.findById(deploymentID);
if (!deployment) return;
if (user.permissions! < 2 && user.username !== deployment.owner) {
addDeploymentUpdate(
app,
deploymentID,
DEPLOY,
"Deploy (DENIED)",
PERMISSIONS_DENY_LOG,
user.username,
note,
true
);
return;
}
const server = deployment.serverID
? await app.servers.findById(deployment.serverID)
: undefined;
if (server) {
// delete the container on periphery
await deletePeripheryContainer(server, deployment.containerName!);
} else {
}
const { command, log, isError } = server
? await deployPeriphery(server, deployment)
: await dockerRun(
deployment,
SYSROOT,
deployment.repo && deployment.containerMount
? {
repoFolder: SYSROOT + "/repos",
containerMount: deployment.containerMount,
}
: undefined
);
addDeploymentUpdate(
app,
deploymentID,
DEPLOY,
command,
log,
user.username,
note,
isError
)
}
+13 -18
View File
@@ -1,8 +1,8 @@
import { Collection, CommandLogError, ContainerStatus, Log } from "@monitor/types";
import { Collection, CommandLogError, ContainerStatus, Log, Server } from "@monitor/types";
import axios from "axios";
export async function getPeripheryContainers(url: string, passkey: string) {
return (await axios.get(`${url}/containers`, {
export async function getPeripheryContainers({ address, passkey }: Server) {
return (await axios.get(`http://${address}/containers`, {
headers: {
Authorization: passkey,
},
@@ -10,11 +10,10 @@ export async function getPeripheryContainers(url: string, passkey: string) {
}
export async function getPeripheryContainer(
url: string,
passkey: string,
{ address, passkey }: Server,
name: string
) {
return (await axios.get(`${url}/container/${name}`, {
return (await axios.get(`http://${address}/container/${name}`, {
headers: {
Authorization: passkey,
},
@@ -22,11 +21,10 @@ export async function getPeripheryContainer(
}
export async function getPeripheryContainerLog(
url: string,
passkey: string,
{ address, passkey }: Server,
name: string
) {
return (await axios.get(`${url}/container/log/${name}`, {
return (await axios.get(`http://${address}/container/log/${name}`, {
headers: {
Authorization: passkey,
},
@@ -34,11 +32,10 @@ export async function getPeripheryContainerLog(
}
export async function startPeripheryContainer(
url: string,
passkey: string,
{ address, passkey }: Server,
name: string
) {
return (await axios.get(`${url}/container/start/${name}`, {
return (await axios.get(`http://${address}/container/start/${name}`, {
headers: {
Authorization: passkey,
},
@@ -46,11 +43,10 @@ export async function startPeripheryContainer(
}
export async function stopPeripheryContainer(
url: string,
passkey: string,
{ address, passkey }: Server,
name: string
) {
return (await axios.get(`${url}/container/stop/${name}`, {
return (await axios.get(`http://${address}/container/stop/${name}`, {
headers: {
Authorization: passkey,
},
@@ -58,11 +54,10 @@ export async function stopPeripheryContainer(
}
export async function deletePeripheryContainer(
url: string,
passkey: string,
{ address, passkey }: Server,
name: string
) {
return (await axios.get(`${url}/container/delete/${name}`, {
return (await axios.get(`http://${address}/container/delete/${name}`, {
headers: {
Authorization: passkey,
},
+7 -4
View File
@@ -1,9 +1,12 @@
import { CommandLogError, Deployment } from "@monitor/types";
import { CommandLogError, Deployment, Server } from "@monitor/types";
import axios from "axios";
export async function deployPeriphery(url: string, passkey: string, deployment: Deployment) {
return (await axios.post(
`${url}/deploy`,
export async function deployPeriphery(
{ address, passkey }: Server,
deployment: Deployment
) {
return (await axios.post(
`http://${address}/deploy`,
{ deployment },
{
headers: {
+7 -10
View File
@@ -1,13 +1,12 @@
import { CommandLogError, Deployment } from "@monitor/types";
import { CommandLogError, Deployment, Server } from "@monitor/types";
import axios from "axios";
export async function clonePeriphery(
url: string,
passkey: string,
{ address, passkey }: Server,
deployment: Deployment
) {
return (await axios.post(
`${url}/repo/clone`,
`http://${address}/repo/clone`,
{ deployment },
{
headers: {
@@ -18,12 +17,11 @@ export async function clonePeriphery(
}
export async function pullPeriphery(
url: string,
passkey: string,
{ address, passkey }: Server,
deployment: Deployment
) {
return (await axios.post(
`${url}/repo/pull`,
`http://${address}/repo/pull`,
{ deployment },
{
headers: {
@@ -34,12 +32,11 @@ export async function pullPeriphery(
}
export async function deleteRepoPeriphery(
url: string,
passkey: string,
{ address, passkey }: Server,
deployment: Deployment
) {
return (await axios.post(
`${url}/repo/delete`,
`http://${address}/repo/delete`,
{ deployment },
{
headers: {