mirror of
https://github.com/moghtech/komodo.git
synced 2026-10-28 08:00:37 +00:00
add db schema
This commit is contained in:
Vendored
+22
@@ -13,5 +13,27 @@
|
||||
"",
|
||||
"export default ${1:$TM_FILENAME_BASE};"
|
||||
]
|
||||
},
|
||||
|
||||
"schema": {
|
||||
"scope": "typescript",
|
||||
"prefix": "schema",
|
||||
"body": [
|
||||
"import { FastifyInstance } from \"fastify\";",
|
||||
"import fp from \"fastify-plugin\";",
|
||||
"import { Schema } from \"mongoose\";",
|
||||
"",
|
||||
"const ${2:$TM_FILENAME_BASE} = fp((app: FastifyInstance, _: {}, done: () => void) => {",
|
||||
"\tconst schema = new Schema({",
|
||||
"\t\t${0}",
|
||||
"\t});",
|
||||
"\t",
|
||||
"\tapp.decorate(\"${2:$TM_FILENAME_BASE}\", app.mongoose.model(\"${1}\", schema));",
|
||||
"\t",
|
||||
"\tdone();",
|
||||
"});",
|
||||
"",
|
||||
"export default ${2:$TM_FILENAME_BASE};"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import mongoose, { Model } from "mongoose";
|
||||
import { MONGO_URL } from "../config";
|
||||
import { User } from "@monitor/types";
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyInstance {
|
||||
mongoose: typeof mongoose;
|
||||
users: Model<User>;
|
||||
}
|
||||
}
|
||||
|
||||
const db = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
mongoose.connect(MONGO_URL);
|
||||
|
||||
app.decorate("mongoose", mongoose);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
export default db;
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import fastify from "fastify";
|
||||
import fastifyCors from "fastify-cors";
|
||||
import auth from "./auth";
|
||||
import auth from "./util/auth";
|
||||
import { LOG, PORT } from "./config";
|
||||
import db from "./db";
|
||||
import ws from "./ws";
|
||||
import db from "./util/db";
|
||||
import ws from "./util/ws";
|
||||
|
||||
const app = fastify({ logger: LOG })
|
||||
.register(fastifyCors)
|
||||
|
||||
@@ -2,7 +2,7 @@ import axios from "axios";
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fastifyOauth2, { OAuth2Namespace } from "fastify-oauth2";
|
||||
import fp from "fastify-plugin";
|
||||
import { HOST, SECRETS, TOKEN_EXPIRES_IN } from "../config";
|
||||
import { HOST, SECRETS, TOKEN_EXPIRES_IN } from "../../config";
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyInstance {
|
||||
@@ -2,7 +2,7 @@ import { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fastifyJwt from "fastify-jwt";
|
||||
import fp from "fastify-plugin";
|
||||
import { SECRETS } from "../config";
|
||||
import { SECRETS } from "../../config";
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyInstance {
|
||||
@@ -2,7 +2,7 @@ import { User } from "@monitor/types";
|
||||
import { compare, hash } from "bcrypt";
|
||||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import { PASSWORD_SALT_ROUNDS, TOKEN_EXPIRES_IN } from "../config";
|
||||
import { PASSWORD_SALT_ROUNDS, TOKEN_EXPIRES_IN } from "../../config";
|
||||
|
||||
const local = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
app.post(
|
||||
@@ -0,0 +1,25 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import { Schema } from "mongoose";
|
||||
|
||||
const builds = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
const schema = new Schema({
|
||||
name: { type: String, unique: true, index: true },
|
||||
/* repo related */
|
||||
repo: String,
|
||||
branch: String,
|
||||
accessToken: String, // to gain access to private repos
|
||||
/* build related */
|
||||
buildPath: String, // build folder relative to repo root
|
||||
dockerfilePath: String, // relative to buildPath
|
||||
pullName: { type: String, index: true }, // derived on build creation
|
||||
imageName: String, // derived on build creation
|
||||
owner: { type: String, index: true }, // userID / username
|
||||
});
|
||||
|
||||
app.decorate("builds", app.mongoose.model("Build", schema));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
export default builds;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import { Schema } from "mongoose";
|
||||
import { Conversion, EnvironmentVar, Volume } from "./misc";
|
||||
|
||||
const deployments = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
const schema = new Schema({
|
||||
name: { type: String, unique: true, index: true },
|
||||
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,
|
||||
accessToken: String,
|
||||
pullName: { type: String, index: true }, // for auto pull of repo
|
||||
containerMount: String, // the file path to mount repo on inside the container
|
||||
});
|
||||
|
||||
app.decorate("deployments", app.mongoose.model("Deployment", schema));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
export default deployments;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import mongoose, { Model } from "mongoose";
|
||||
import { MONGO_URL } from "../../config";
|
||||
import { Build, Deployment, Update, User } from "@monitor/types";
|
||||
import users from "./users";
|
||||
import updates from "./updates";
|
||||
import deployments from "./deployments";
|
||||
import builds from "./builds";
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyInstance {
|
||||
mongoose: typeof mongoose;
|
||||
users: Model<User>;
|
||||
deployments: Model<Deployment>;
|
||||
builds: Model<Build>;
|
||||
updates: Model<Update>;
|
||||
}
|
||||
}
|
||||
|
||||
const db = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
mongoose.connect(MONGO_URL);
|
||||
|
||||
app.decorate("mongoose", mongoose);
|
||||
|
||||
app
|
||||
.register(users)
|
||||
.register(deployments)
|
||||
.register(builds)
|
||||
.register(updates);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Schema } from "mongoose";
|
||||
|
||||
export const Conversion = new Schema({
|
||||
local: String,
|
||||
container: String,
|
||||
});
|
||||
|
||||
export const Volume = new Schema({
|
||||
variable: String,
|
||||
value: String,
|
||||
});
|
||||
|
||||
export const EnvironmentVar = new Schema({
|
||||
variable: String,
|
||||
value: String,
|
||||
});
|
||||
|
||||
export const Log = new Schema({
|
||||
stdout: String,
|
||||
stderr: String,
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fp from "fastify-plugin";
|
||||
import { Schema } from "mongoose";
|
||||
import { Log } from "./misc";
|
||||
|
||||
const updates = fp((app: FastifyInstance, _: {}, done: () => void) => {
|
||||
const schema = new Schema({
|
||||
buildID: { type: String, index: true },
|
||||
deploymentID: { type: String, index: true },
|
||||
serverID: { type: String, index: true },
|
||||
operation: { type: String, index: true },
|
||||
command: String,
|
||||
log: Log,
|
||||
timestamp: Number,
|
||||
note: String,
|
||||
isError: Boolean,
|
||||
operator: { type: String, index: true }, // the userID or username
|
||||
});
|
||||
|
||||
app.decorate("updates", app.mongoose.model("Update", schema));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
export default updates;
|
||||
Reference in New Issue
Block a user