mirror of
https://github.com/moghtech/komodo.git
synced 2026-02-15 09:30:51 -06:00
add initial docs
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"dependencies": {
|
||||
"ink": "^3.2.0",
|
||||
"meow": "^10.1.2",
|
||||
"mongoose": "^6.2.7",
|
||||
"react": "^17.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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[] = [];
|
||||
|
||||
@@ -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;
|
||||
@@ -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>
|
||||
|
||||
@@ -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
cli/src/helpers/general.ts
Normal file
3
cli/src/helpers/general.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function toDashedName(name: string) {
|
||||
return name.toLowerCase().replaceAll(" ", "-");
|
||||
}
|
||||
44
cli/src/helpers/mongoose/deployment.ts
Normal file
44
cli/src/helpers/mongoose/deployment.ts
Normal 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
cli/src/helpers/mongoose/mongoose.ts
Normal file
54
cli/src/helpers/mongoose/mongoose.ts
Normal 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
cli/src/helpers/mongoose/server.ts
Normal file
14
cli/src/helpers/mongoose/server.ts
Normal 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
cli/src/helpers/mongoose/user.ts
Normal file
14
cli/src/helpers/mongoose/user.ts
Normal 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
cli/src/types.d.ts
vendored
1
cli/src/types.d.ts
vendored
@@ -1,5 +1,4 @@
|
||||
export type Config = {
|
||||
useBuilds: boolean; // will set up the registry and enable docker build functionality
|
||||
mongoURL: string;
|
||||
registryURL: string;
|
||||
};
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
"docker-run-core": "cd core && yarn docker-run",
|
||||
"build-periphery": "cd periphery && yarn build",
|
||||
"start-frontend": "cd frontend && yarn start",
|
||||
"build-frontend": "cd frontend && yarn build",
|
||||
"run-mongo": "docker run -d --name mongo -p 27017:27017 mongo:latest",
|
||||
"run-registry": "docker run -d --name registry --network=\"host\" registry:2"
|
||||
"build-frontend": "cd frontend && yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.6.2"
|
||||
|
||||
13
yarn.lock
13
yarn.lock
@@ -1942,6 +1942,19 @@ mongoose@^6.2.6:
|
||||
ms "2.1.3"
|
||||
sift "16.0.0"
|
||||
|
||||
mongoose@^6.2.7:
|
||||
version "6.2.7"
|
||||
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-6.2.7.tgz#d8ea2fce4c19200d316c3ac4a8377f3af4fb4450"
|
||||
integrity sha512-yqTZcM3u0+aLzl6cirtXy6vr24kt+kFyTucCQ3pyncvO1jGn/M1R09qkC/v54QoPXeVJdpcuS5eQWn0NLlDvKA==
|
||||
dependencies:
|
||||
bson "^4.2.2"
|
||||
kareem "2.3.4"
|
||||
mongodb "4.3.1"
|
||||
mpath "0.8.4"
|
||||
mquery "4.0.2"
|
||||
ms "2.1.3"
|
||||
sift "16.0.0"
|
||||
|
||||
mpath@0.8.4:
|
||||
version "0.8.4"
|
||||
resolved "https://registry.yarnpkg.com/mpath/-/mpath-0.8.4.tgz#6b566d9581621d9e931dd3b142ed3618e7599313"
|
||||
|
||||
Reference in New Issue
Block a user