add deploy funcs

This commit is contained in:
mbecker20
2022-03-19 18:26:06 -07:00
parent c2941327a5
commit 1a0bfbbcf9
2 changed files with 43 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
export const DEFAULT_PORT = 9000;
export const DEFAULT_MONGO_URL = "mongodb://127.0.0.1:27017/monitor";
export const DEFAULT_REGISTRY_URL = "http://127.0.0.1:5000/";
export const DEFAULT_REGISTRY_URL = "http://127.0.0.1:5000/";
export const CORE_IMAGE = "mbecker2020/monitor-core";
export const PERIPHERY_IMAGE = "mbecker2020/monitor-periphery";

View File

@@ -0,0 +1,40 @@
import { CORE_IMAGE } from "../../config";
import { Config, CoreConfig, StartConfig } from "../../types";
import { execute } from "./execute";
import { toDashedName } from "./general";
export async function deployCore({ core, mongo, registry }: Config) {
const { name, hostNetwork, secretVolume, port } = core!;
const nameConfig = `--name ${toDashedName(name)}`;
const volume = `-v ${secretVolume}:/secrets`;
const network = hostNetwork ? '--network="host"' : `-p ${port}:9000`;
const env = `-e MONGO_URL=${mongo?.url} -e REGISTRY_URL=${registry?.url}${
hostNetwork ? ` -e PORT=${port}` : ""
}`;
const command = `docker run -d ${nameConfig} ${volume} ${network} ${env} ${CORE_IMAGE}`;
return await execute(command);
}
export async function deployMongo({
name,
port,
volume,
restart,
}: StartConfig) {
const command = `docker run -d --name ${name} -p ${port}:27017${
volume ? ` -v ${volume}:/data/db` : ""
} --restart ${restart} mongo:latest`;
return await execute(command);
}
export async function deployRegistry({
name,
port,
volume,
restart,
}: StartConfig) {
const command = `docker run -d --name ${name} -p ${port}:5000${
volume ? ` -v ${volume}:/var/lib/registry` : ""
} --restart ${restart} registry:2`;
return await execute(command);
}