chore: production setup

This commit is contained in:
Nicolas Meienberger
2025-09-27 14:10:15 +02:00
parent 9f3fb8a302
commit 88e310cc4f
18 changed files with 213 additions and 58 deletions

View File

@@ -3,11 +3,9 @@ import "dotenv/config";
const envSchema = type({
NODE_ENV: type.enumerated("development", "production", "test").default("development"),
VOLUME_ROOT: "string",
}).pipe((s) => ({
__prod__: s.NODE_ENV === "production",
environment: s.NODE_ENV,
volumeRootHost: s.VOLUME_ROOT,
}));
const parseConfig = (env: unknown) => {

View File

@@ -1,14 +1,22 @@
import "dotenv/config";
import { Database } from "bun:sqlite";
import path from "node:path";
import { drizzle } from "drizzle-orm/bun-sqlite";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import * as schema from "./schema";
import { DATABASE_URL } from "../core/constants";
import * as schema from "./schema";
const sqlite = new Database(DATABASE_URL);
export const db = drizzle({ client: sqlite, schema });
export const runDbMigrations = () => {
migrate(db, { migrationsFolder: "./drizzle" });
let migrationsFolder = path.join("/app", "assets", "migrations");
const { NODE_ENV } = process.env;
if (NODE_ENV !== "production") {
migrationsFolder = path.join("/app", "apps", "server", "drizzle");
}
migrate(db, { migrationsFolder });
};

View File

@@ -1,6 +1,7 @@
import * as fs from "node:fs/promises";
import { Scalar } from "@scalar/hono-api-reference";
import { Hono } from "hono";
import { serveStatic } from "hono/bun";
import { logger as honoLogger } from "hono/logger";
import { openAPISpecs } from "hono-openapi";
import { runDbMigrations } from "./db/db";
@@ -31,6 +32,7 @@ export const scalarDescriptor = Scalar({
const driver = new Hono().use(honoLogger()).route("/", driverController);
const app = new Hono()
.use(honoLogger())
.get("*", serveStatic({ root: "./assets/frontend" }))
.get("healthcheck", (c) => c.json({ status: "ok" }))
.basePath("/api/v1")
.route("/volumes", volumeController);
@@ -38,10 +40,6 @@ const app = new Hono()
app.get("/openapi.json", generalDescriptor(app));
app.get("/docs", scalarDescriptor);
app.get("/", (c) => {
return c.json({ message: "Welcome to the Ironmount API" });
});
app.onError((err, c) => {
logger.error(`${c.req.url}: ${err.message}`);
@@ -56,24 +54,21 @@ app.onError((err, c) => {
const socketPath = "/run/docker/plugins/ironmount.sock";
(async () => {
await fs.mkdir("/run/docker/plugins", { recursive: true });
await fs.mkdir("/run/docker/plugins", { recursive: true });
runDbMigrations();
runDbMigrations();
Bun.serve({
unix: socketPath,
fetch: driver.fetch,
});
Bun.serve({
unix: socketPath,
fetch: driver.fetch,
});
Bun.serve({
port: 4096,
fetch: app.fetch,
});
Bun.serve({
port: 8080,
fetch: app.fetch,
});
startup();
startup();
logger.info(`Server is running at http://localhost:8080 and unix socket at ${socketPath}`);
})();
logger.info(`Server is running at http://localhost:4096 and unix socket at ${socketPath}`);
export type AppType = typeof app;