From 1a0bfbbcf945c3cc05daa08e241aabf1ffadcc3b Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sat, 19 Mar 2022 18:26:06 -0700 Subject: [PATCH] add deploy funcs --- cli/src/config.ts | 4 +++- cli/src/util/helpers/deploy.ts | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 cli/src/util/helpers/deploy.ts diff --git a/cli/src/config.ts b/cli/src/config.ts index aaf9b3cb8..fd53007e4 100644 --- a/cli/src/config.ts +++ b/cli/src/config.ts @@ -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/"; \ No newline at end of file +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"; \ No newline at end of file diff --git a/cli/src/util/helpers/deploy.ts b/cli/src/util/helpers/deploy.ts new file mode 100644 index 000000000..de68d9107 --- /dev/null +++ b/cli/src/util/helpers/deploy.ts @@ -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); +}