setup the registry config

This commit is contained in:
mbecker20
2022-03-19 15:40:15 -07:00
parent 048905997a
commit 3d60bb16ec
8 changed files with 214 additions and 49 deletions

View File

@@ -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"
},

View File

@@ -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<Config>({});
@@ -16,30 +17,30 @@ init().then(({ flags, dockerInstalled }) => {
const App = () => {
const { current, next } = useMainSequence();
const [periphery, setPeriphery] = useState<boolean | undefined>(
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 ? [<Mongo />, <Registry />] : [];
const peripheryPages: ReactNode[] = periphery ? [] : [];
const pages: ReactNode[] = [
<Intro />,
dockerInstalled ? undefined : <Docker />,
<DeploymentConfig deployment="mongo-db" onFinish={next} />,
!flags.core && !flags.periphery
? <Periphery setPeriphery={setPeriphery} />
: undefined,
...(periphery === true ? peripheryPages : []),
...(periphery === false ? corePages : []),
!flags.core && !flags.periphery ? (
<Periphery setPeriphery={setPeriphery} />
) : undefined,
...peripheryPages,
...corePages,
<Confirm
next={() => {
setInstalling(true);
next();
}}
/>,
].filter(val => val ? true : false);
].filter((val) => (val ? true : false));
return (
<Box flexDirection="column">

View File

@@ -1,13 +0,0 @@
import React from "react";
import { Box } from "ink";
import { Config, SetConfig } from "../types";
const Mongo = () => {
return (
<Box>
</Box>
);
}
export default Mongo;

View File

@@ -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 (
<Box>
</Box>
);
}
export default Registry;

View File

@@ -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<boolean>();
const [mongoURL, setMongoURL] = useState(DEFAULT_MONGO_URL);
const [confirm, setConfirm] = useState(false);
useEsc(() => {
if (!setup && confirm) {
setConfirm(false);
}
})
if (setup === undefined) {
return (
<YesNo
label={
<Text>
do you need to set up{" "}
<Text color="cyan" bold>
mongo db
</Text>{" "}
locally?{" "}
</Text>
}
onSelect={(res) => setSetup(res === "yes")}
vertical
/>
);
}
if (setup) {
return (
<Box flexDirection="column">
<Text color="cyan" bold>
mongo db config
</Text>
<Newline />
<DeploymentConfig
deployment="mongo-db"
onFinish={({ name, port, volume, restart }) => {
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();
}}
/>
</Box>
);
} else {
if (confirm) {
return (
<Box flexDirection="column">
<Text color="green">
mongo url: <Text color="white">{mongoURL}</Text>
</Text>
<Newline />
<EnterToContinue
onEnter={() => {
set("mongo", { url: mongoURL });
next();
}}
/>
</Box>
);
} else {
return (
<Text color="green">
mongo url:{" "}
<Text color="white">
<TextInput
value={mongoURL}
onChange={setMongoURL}
onSubmit={() => setConfirm(true)}
/>
</Text>
</Text>
);
}
}
};
export default Mongo;

View File

@@ -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<boolean>();
const [regURL, setRegURL] = useState(DEFAULT_REGISTRY_URL);
const [confirm, setConfirm] = useState(false);
useEsc(() => {
if (!setup && confirm) {
setConfirm(false);
}
});
if (setup === undefined) {
return (
<YesNo
label={
<Text>
do you need to set up a{" "}
<Text color="cyan" bold>
docker registry
</Text>{" "}
locally?{" "}
</Text>
}
onSelect={(res) => setSetup(res === "yes")}
vertical
/>
);
}
if (setup) {
return (
<Box flexDirection="column">
<Text color="cyan" bold>
registry config
</Text>
<Newline />
<DeploymentConfig
deployment="registry"
onFinish={({ name, port, volume, restart }) => {
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();
}}
/>
</Box>
);
} else {
if (confirm) {
return (
<Box flexDirection="column">
<Text color="green">
registry url: <Text color="white">{regURL}</Text>
</Text>
<Newline />
<EnterToContinue
onEnter={() => {
set("registry", { url: regURL });
next();
}}
/>
</Box>
);
} else {
return (
<Text color="green">
registry url:{" "}
<Text color="white">
<TextInput
value={regURL}
onChange={setRegURL}
onSubmit={() => setConfirm(true)}
/>
</Text>
</Text>
);
}
}
};
export default Registry;

View File

@@ -1 +1,3 @@
export const DEFAULT_PORT = 9000;
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/";

4
cli/src/types.d.ts vendored
View File

@@ -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;
};
};