feat: add docker registry upload

This commit is contained in:
Mauricio Siu
2024-05-13 01:18:27 -06:00
parent e9245cee2c
commit 6c792564ae
41 changed files with 18267 additions and 1072 deletions

View File

@@ -1,13 +1,14 @@
import type { Config } from "drizzle-kit";
import { defineConfig } from "drizzle-kit";
console.log("> Generating PG Schema:", process.env.DATABASE_URL);
export default {
export default defineConfig({
schema: "./server/db/schema/index.ts",
driver: "pg",
dialect: "postgresql",
dbCredentials: {
connectionString: process.env.DATABASE_URL || "",
url: process.env.DATABASE_URL || "",
},
verbose: true,
strict: true,
out: "drizzle",
} satisfies Config;
migrations: {
table: "migrations",
schema: "public",
},
});

View File

@@ -12,6 +12,7 @@ import { applicationStatus } from "./shared";
import { ports } from "./port";
import { boolean, integer, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
import { generateAppName } from "./utils";
import { registry } from "./registry";
export const sourceType = pgEnum("sourceType", ["docker", "git", "github"]);
@@ -60,6 +61,7 @@ export const applications = pgTable("application", {
customGitBuildPath: text("customGitBuildPath"),
customGitSSHKey: text("customGitSSHKey"),
dockerfile: text("dockerfile"),
replicas: integer("replicas").default(1).notNull(),
applicationStatus: applicationStatus("applicationStatus")
.notNull()
.default("idle"),
@@ -67,6 +69,9 @@ export const applications = pgTable("application", {
createdAt: text("createdAt")
.notNull()
.$defaultFn(() => new Date().toISOString()),
registryId: text("registryId").references(() => registry.registryId, {
onDelete: "set null",
}),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
@@ -85,6 +90,10 @@ export const applicationsRelations = relations(
redirects: many(redirects),
security: many(security),
ports: many(ports),
registry: one(registry, {
fields: [applications.registryId],
references: [registry.registryId],
}),
}),
);

View File

@@ -5,6 +5,7 @@ import { boolean, pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core";
import { auth } from "./auth";
import { admins } from "./admin";
import { z } from "zod";
import { applications } from "./application";
/**
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
* database instance for multiple projects.
@@ -19,6 +20,7 @@ export const registry = pgTable("registry", {
.primaryKey()
.$defaultFn(() => nanoid()),
registryName: text("registryName").notNull(),
imagePrefix: text("imagePrefix"),
username: text("username").notNull(),
password: text("password").notNull(),
registryUrl: text("registryUrl").notNull(),
@@ -31,11 +33,12 @@ export const registry = pgTable("registry", {
.references(() => admins.adminId, { onDelete: "cascade" }),
});
export const registryRelations = relations(registry, ({ one }) => ({
export const registryRelations = relations(registry, ({ one, many }) => ({
admin: one(admins, {
fields: [registry.adminId],
references: [admins.adminId],
}),
applications: many(applications),
}));
const createSchema = createInsertSchema(registry, {
@@ -45,6 +48,8 @@ const createSchema = createInsertSchema(registry, {
registryUrl: z.string().min(1),
adminId: z.string().min(1),
registryId: z.string().min(1),
registryType: z.enum(["selfHosted", "cloud"]),
imagePrefix: z.string().nullable().optional(),
});
export const apiCreateRegistry = createSchema
@@ -53,8 +58,9 @@ export const apiCreateRegistry = createSchema
registryName: z.string().min(1),
username: z.string().min(1),
password: z.string().min(1),
registryUrl: z.string().min(1),
adminId: z.string().min(1),
registryUrl: z.string(),
registryType: z.enum(["selfHosted", "cloud"]),
imagePrefix: z.string().nullable().optional(),
})
.required();
@@ -82,6 +88,8 @@ export const apiUpdateRegistry = createSchema
export const apiEnableSelfHostedRegistry = createSchema
.pick({
adminId: true,
registryUrl: true,
username: true,
password: true,
})
.required();