From 3d60bb16ece6d3fb77676fb15a218bd78ee459fc Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sat, 19 Mar 2022 15:40:15 -0700 Subject: [PATCH] setup the registry config --- cli/package.json | 2 +- cli/src/cli.tsx | 21 ++-- cli/src/components/Mongo.tsx | 13 --- cli/src/components/Registry.tsx | 20 ---- .../components/deployment-config/Mongo.tsx | 99 +++++++++++++++++ .../components/deployment-config/Registry.tsx | 100 ++++++++++++++++++ cli/src/config.ts | 4 +- cli/src/types.d.ts | 4 - 8 files changed, 214 insertions(+), 49 deletions(-) delete mode 100644 cli/src/components/Mongo.tsx delete mode 100644 cli/src/components/Registry.tsx create mode 100644 cli/src/components/deployment-config/Mongo.tsx create mode 100644 cli/src/components/deployment-config/Registry.tsx diff --git a/cli/package.json b/cli/package.json index 0d6826a9d..e22f6b0ba 100644 --- a/cli/package.json +++ b/cli/package.json @@ -6,7 +6,7 @@ "license": "MIT", "bin": "cli.js", "scripts": { - "start": "yarn build && build/cli.js", + "start": "yarn build && build/cli.js --core", "build": "vite build && node post-build.mjs && chmod +x build/cli.js", "publish-cli": "yarn build && cd build && npm publish --access=public && node update-version.mjs" }, diff --git a/cli/src/cli.tsx b/cli/src/cli.tsx index 17cc695b2..a15466c08 100644 --- a/cli/src/cli.tsx +++ b/cli/src/cli.tsx @@ -7,7 +7,8 @@ import Periphery from "./components/Periphery"; import Confirm from "./components/Confirm"; import { createUseConfig, createUseSequence } from "./util/state"; import { Config } from "./types"; -import DeploymentConfig from "./components/deployment-config/DeploymentConfig"; +import Mongo from "./components/deployment-config/Mongo"; +import Registry from "./components/deployment-config/Registry"; export const useMainSequence = createUseSequence(); export const useConfig = createUseConfig({}); @@ -16,30 +17,30 @@ init().then(({ flags, dockerInstalled }) => { const App = () => { const { current, next } = useMainSequence(); const [periphery, setPeriphery] = useState( - flags.core ? true : flags.periphery ? false : undefined + flags.core ? false : flags.periphery ? true : undefined ); const [installing, setInstalling] = useState(false); - const corePages: ReactNode[] = periphery === false ? [] : []; + const corePages: ReactNode[] = + periphery === false ? [, ] : []; const peripheryPages: ReactNode[] = periphery ? [] : []; const pages: ReactNode[] = [ , dockerInstalled ? undefined : , - , - !flags.core && !flags.periphery - ? - : undefined, - ...(periphery === true ? peripheryPages : []), - ...(periphery === false ? corePages : []), + !flags.core && !flags.periphery ? ( + + ) : undefined, + ...peripheryPages, + ...corePages, { setInstalling(true); next(); }} />, - ].filter(val => val ? true : false); + ].filter((val) => (val ? true : false)); return ( diff --git a/cli/src/components/Mongo.tsx b/cli/src/components/Mongo.tsx deleted file mode 100644 index 232ba4d0d..000000000 --- a/cli/src/components/Mongo.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from "react"; -import { Box } from "ink"; -import { Config, SetConfig } from "../types"; - -const Mongo = () => { - return ( - - - - ); -} - -export default Mongo; \ No newline at end of file diff --git a/cli/src/components/Registry.tsx b/cli/src/components/Registry.tsx deleted file mode 100644 index f1cb2e880..000000000 --- a/cli/src/components/Registry.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from "react"; -import { Box } from "ink"; -import { useConfig, useMainSequence } from "../cli"; -import { createUseSequence } from "../util/state"; - -const useRegisterySequence = createUseSequence(); - -const Registry = () => { - const { prev } = useMainSequence(); - const { current } = useRegisterySequence(); - const { config, set } = useConfig(); - - return ( - - - - ); -} - -export default Registry; \ No newline at end of file diff --git a/cli/src/components/deployment-config/Mongo.tsx b/cli/src/components/deployment-config/Mongo.tsx new file mode 100644 index 000000000..a1ff66a41 --- /dev/null +++ b/cli/src/components/deployment-config/Mongo.tsx @@ -0,0 +1,99 @@ +import React, { useState } from "react"; +import { Box, Newline, Text } from "ink"; +import TextInput from "ink-text-input"; +import { useConfig, useMainSequence } from "../../cli"; +import YesNo from "../util/YesNo"; +import DeploymentConfig from "./DeploymentConfig"; +import EnterToContinue from "../util/EnterToContinue"; +import { DEFAULT_MONGO_URL } from "../../config"; +import { useEsc } from "../../util/hooks"; + +const Mongo = () => { + const { set } = useConfig(); + const { next } = useMainSequence(); + const [setup, setSetup] = useState(); + const [mongoURL, setMongoURL] = useState(DEFAULT_MONGO_URL); + const [confirm, setConfirm] = useState(false); + + useEsc(() => { + if (!setup && confirm) { + setConfirm(false); + } + }) + + if (setup === undefined) { + return ( + + do you need to set up{" "} + + mongo db + {" "} + locally?{" "} + + } + onSelect={(res) => setSetup(res === "yes")} + vertical + /> + ); + } + + if (setup) { + return ( + + + mongo db config + + + { + set("mongo", { + url: `mongodb://127.0.0.1:${port}/monitor`, + startConfig: { + name, + port: Number(port), + volume: volume as string | false, + restart: restart as string, + }, + }); + next(); + }} + /> + + ); + } else { + if (confirm) { + return ( + + + mongo url: {mongoURL} + + + { + set("mongo", { url: mongoURL }); + next(); + }} + /> + + ); + } else { + return ( + + mongo url:{" "} + + setConfirm(true)} + /> + + + ); + } + } +}; + +export default Mongo; diff --git a/cli/src/components/deployment-config/Registry.tsx b/cli/src/components/deployment-config/Registry.tsx new file mode 100644 index 000000000..16d5648f4 --- /dev/null +++ b/cli/src/components/deployment-config/Registry.tsx @@ -0,0 +1,100 @@ +import React, { useState } from "react"; +import { Box, Newline, Text } from "ink"; +import TextInput from "ink-text-input"; +import { useConfig, useMainSequence } from "../../cli"; +import YesNo from "../util/YesNo"; +import DeploymentConfig from "./DeploymentConfig"; +import EnterToContinue from "../util/EnterToContinue"; +import { DEFAULT_REGISTRY_URL } from "../../config"; +import { useEsc } from "../../util/hooks"; + +const Registry = () => { + const { set } = useConfig(); + const { next } = useMainSequence(); + const [setup, setSetup] = useState(); + const [regURL, setRegURL] = useState(DEFAULT_REGISTRY_URL); + const [confirm, setConfirm] = useState(false); + + useEsc(() => { + if (!setup && confirm) { + setConfirm(false); + } + }); + + if (setup === undefined) { + return ( + + do you need to set up a{" "} + + docker registry + {" "} + locally?{" "} + + } + onSelect={(res) => setSetup(res === "yes")} + vertical + /> + ); + } + + if (setup) { + return ( + + + registry config + + + { + set("registry", { + exists: true, + url: `http://127.0.0.1:${port}/`, + startConfig: { + name, + port: Number(port), + volume: volume as string | false, + restart: restart as string, + }, + }); + next(); + }} + /> + + ); + } else { + if (confirm) { + return ( + + + registry url: {regURL} + + + { + set("registry", { url: regURL }); + next(); + }} + /> + + ); + } else { + return ( + + registry url:{" "} + + setConfirm(true)} + /> + + + ); + } + } +}; + +export default Registry; diff --git a/cli/src/config.ts b/cli/src/config.ts index 4c829c331..aaf9b3cb8 100644 --- a/cli/src/config.ts +++ b/cli/src/config.ts @@ -1 +1,3 @@ -export const DEFAULT_PORT = 9000; \ No newline at end of file +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 diff --git a/cli/src/types.d.ts b/cli/src/types.d.ts index 4e404b533..c03b65d2a 100644 --- a/cli/src/types.d.ts +++ b/cli/src/types.d.ts @@ -12,15 +12,11 @@ export type Config = { }; mongo?: { url: string; - deploymentConfig?: { - // if mongo container already exists locally running on docker and should be added as a monitor managed deployment - }; startConfig?: StartConfig; }; registry?: { exists: boolean; // if this is false, dont use a registry and builds will be disabled url?: string; - deploymentConfig?: {}; startConfig?: StartConfig; }; };