add initial docs

This commit is contained in:
mbecker20
2022-03-18 08:59:12 -07:00
parent 7130da485b
commit 0cbb90760b
13 changed files with 149 additions and 44 deletions
-3
View File
@@ -1,6 +1,5 @@
import React, { ReactNode, useState } from "react";
import { Box, Newline, Text, useInput } from "ink";
import Builds from "./components/Builds";
import FinalConfig from "./components/FinalConfig";
import { useConfig, useSequence } from "./hooks";
import { Config } from "./types";
@@ -17,7 +16,6 @@ const App = () => {
const [periphery, setPeriphery] = useState<boolean>();
const [installing, setInstalling] = useState(false);
const [config, setConfig] = useConfig<Config>({
useBuilds: false,
mongoURL: "",
registryURL: "",
});
@@ -25,7 +23,6 @@ const App = () => {
const corePages: ReactNode[] = [
<Mongo setConfig={setConfig} next={next} />,
<Registry setConfig={setConfig} next={next} />,
<Builds setConfig={setConfig} next={next} />,
];
const peripheryPages: ReactNode[] = [];
-33
View File
@@ -1,33 +0,0 @@
import { Box, Newline, Text } from "ink";
import React from "react";
import { SetConfig } from "../types";
import Selector from "./util/Selector";
const Builds = (p: { setConfig: SetConfig; next: () => void }) => {
return (
<Box flexDirection="column">
<Text>Would you like to enable docker build services?</Text>
<Text>
This will create a{" "}
<Text color="blue" bold>
docker registry
</Text>{" "}
and enable Monitor to act as a{" "}
<Text color="blue" bold>
build server
</Text>
.
</Text>
<Newline />
<Selector
items={["yes", "no"]}
onSelect={(item) => {
p.setConfig("useBuilds", item === "yes");
p.next();
}}
/>
</Box>
);
};
export default Builds;
-4
View File
@@ -35,10 +35,6 @@ const FinalConfig = (p: {
<Text color="green">
registry url: <Text color="white">{p.config.registryURL}</Text>
</Text>
<Text color={p.config.useBuilds ? "green" : "red"}>
use builds:{" "}
<Text color="white">{p.config.useBuilds ? "yes" : "no"}</Text>
</Text>
</Box>
<Newline />
<Text>
+5
View File
@@ -79,6 +79,11 @@ const Mongo = ({
</Text>
</Box>
<Newline />
<Text color="gray">
note: remember to specify the database name in the url, ie
mongodb://localhost:27017<Text color="green">/monitor</Text>
</Text>
<Newline />
{confirm && (
<Text>
press{" "}
+3
View File
@@ -0,0 +1,3 @@
export function toDashedName(name: string) {
return name.toLowerCase().replaceAll(" ", "-");
}
+44
View File
@@ -0,0 +1,44 @@
import { Deployment } from "@monitor/types";
import { model, Schema } from "mongoose";
export default function deploymentModel() {
const Conversion = new Schema({
local: String,
container: String,
});
const Volume = new Schema({
variable: String,
value: String,
});
const EnvironmentVar = new Schema({
variable: String,
value: String,
});
const schema = new Schema<Deployment>({
name: { type: String, unique: true, index: true },
containerName: { type: String, unique: true, index: true }, // for auto pull of frontend repo as well
owner: { type: String, index: true },
serverID: { type: String, index: true },
buildID: { type: String, index: true }, // if deploying a monitor build
/* to create docker run command */
image: String, // used if deploying an external image (from docker hub)
latest: Boolean, // if custom image, use this to add :latest
ports: [Conversion],
volumes: [Volume],
environment: [EnvironmentVar],
network: String,
restart: String,
postImage: String, // interpolated into run command after the image String
containerUser: String, // after -u in the run command
/* to manage repo for static frontend, mounted as a volume */
repo: String,
branch: { type: String, default: "master" },
accessToken: String,
containerMount: String, // the file path to mount repo on inside the container
});
return model("Deployment", schema)
}
+54
View File
@@ -0,0 +1,54 @@
import { Deployment } from "@monitor/types";
import mongoose from "mongoose";
import deploymentModel from "./deployment";
import serverModel from "./server";
import userModel from "./user";
export async function addInitialDocs(mongoURL: string, localMongo: boolean, localRegistry: boolean) {
await mongoose.connect(mongoURL);
const servers = serverModel();
const deployments = deploymentModel();
const users = userModel();
const coreServer = {
name: "Core Server",
address: "localhost",
passkey: "passkey",
enabled: true,
isCore: true,
};
const coreServerID = (await servers.create(coreServer)).toObject()._id;
const coreDeployment: Deployment = {
name: "Monitor Core",
containerName: "monitor-core",
image: "mbecker2020/monitor-core",
latest: true,
serverID: coreServerID,
owner: "admin",
};
deployments.create(coreDeployment);
if (localMongo) {
const mongoDeployment: Deployment = {
name: "Mongo DB",
containerName: "mongo-db",
image: "mongo",
latest: true,
owner: "admin",
};
deployments.create(mongoDeployment);
}
if (localRegistry) {
const registryDeployment: Deployment = {
name: "Registry",
containerName: "registry",
image: "registry:2",
serverID: coreServerID,
owner: "admin",
};
deployments.create(registryDeployment);
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Server } from "@monitor/types";
import { model, Schema } from "mongoose";
export default function serverModel() {
const schema = new Schema<Server>({
name: { type: String, unique: true },
address: String,
passkey: String,
enabled: { type: Boolean, default: true },
isCore: Boolean,
});
return model("Server", schema);
}
+14
View File
@@ -0,0 +1,14 @@
import { User } from "@monitor/types";
import { Schema, model } from "mongoose";
export default function userModel() {
const schema = new Schema<User>({
username: { type: String, index: true, required: true },
permissions: { type: Number, default: 0 },
password: String,
avatar: String,
githubID: { type: Number, index: true },
});
return model("User", schema);
}
-1
View File
@@ -1,5 +1,4 @@
export type Config = {
useBuilds: boolean; // will set up the registry and enable docker build functionality
mongoURL: string;
registryURL: string;
};