Compare commits
3 commits
main
...
v0.27.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48b3c9a87f | ||
|
|
ca2a2cb74f | ||
|
|
436a63a4b4 |
8 changed files with 61 additions and 24 deletions
|
|
@ -100,7 +100,6 @@ ENV PORT=4096
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/package.json ./
|
COPY --from=builder /app/package.json ./
|
||||||
RUN bun install --production --frozen-lockfile && rm -rf $HOME/.bun/install/cache
|
|
||||||
|
|
||||||
COPY --from=deps /deps/restic /usr/local/bin/restic
|
COPY --from=deps /deps/restic /usr/local/bin/restic
|
||||||
COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,17 @@
|
||||||
import * as schema from "./server/db/schema";
|
|
||||||
import { setSchema, runDbMigrations } from "./server/db/db";
|
|
||||||
import { startup } from "./server/modules/lifecycle/startup";
|
|
||||||
import { logger } from "./server/utils/logger";
|
import { logger } from "./server/utils/logger";
|
||||||
import { shutdown } from "./server/modules/lifecycle/shutdown";
|
import { shutdown } from "./server/modules/lifecycle/shutdown";
|
||||||
import { runCLI } from "./server/cli";
|
import { runCLI } from "./server/cli";
|
||||||
import { runMigrations } from "./server/modules/lifecycle/migrations";
|
|
||||||
import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server";
|
import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server";
|
||||||
import { createServerEntry } from "@tanstack/react-start/server-entry";
|
import { createServerEntry } from "@tanstack/react-start/server-entry";
|
||||||
|
import { initModules } from "./server/modules/lifecycle/bootstrap";
|
||||||
|
|
||||||
setSchema(schema);
|
await initModules();
|
||||||
|
|
||||||
const cliRun = await runCLI(Bun.argv);
|
const cliRun = await runCLI(Bun.argv);
|
||||||
if (cliRun) {
|
if (cliRun) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
runDbMigrations();
|
|
||||||
|
|
||||||
await runMigrations();
|
|
||||||
await startup();
|
|
||||||
|
|
||||||
const customHandler = defineHandlerCallback((ctx) => {
|
const customHandler = defineHandlerCallback((ctx) => {
|
||||||
return defaultStreamHandler(ctx);
|
return defaultStreamHandler(ctx);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
39
app/server/modules/lifecycle/bootstrap.ts
Normal file
39
app/server/modules/lifecycle/bootstrap.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import * as schema from "../../db/schema";
|
||||||
|
import { runDbMigrations, setSchema } from "../../db/db";
|
||||||
|
import { runMigrations } from "./migrations";
|
||||||
|
import { startup } from "./startup";
|
||||||
|
import { initAuth } from "../../lib/auth";
|
||||||
|
import { logger } from "../../utils/logger";
|
||||||
|
import { toMessage } from "../../utils/errors";
|
||||||
|
|
||||||
|
let bootstrapPromise: Promise<void> | undefined;
|
||||||
|
|
||||||
|
export const initModules = async () => {
|
||||||
|
setSchema(schema);
|
||||||
|
|
||||||
|
await initAuth().catch((err) => {
|
||||||
|
logger.error(`Error initializing auth: ${toMessage(err)}`);
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const runBootstrap = async () => {
|
||||||
|
await initModules();
|
||||||
|
|
||||||
|
runDbMigrations();
|
||||||
|
await runMigrations();
|
||||||
|
await startup();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bootstrapApplication = async () => {
|
||||||
|
if (!bootstrapPromise) {
|
||||||
|
bootstrapPromise = runBootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await bootstrapPromise;
|
||||||
|
} catch (err) {
|
||||||
|
bootstrapPromise = undefined;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -12,8 +12,6 @@ import { repositoriesService } from "../repositories/repositories.service";
|
||||||
import { notificationsService } from "../notifications/notifications.service";
|
import { notificationsService } from "../notifications/notifications.service";
|
||||||
import { VolumeAutoRemountJob } from "~/server/jobs/auto-remount";
|
import { VolumeAutoRemountJob } from "~/server/jobs/auto-remount";
|
||||||
import { cache } from "~/server/utils/cache";
|
import { cache } from "~/server/utils/cache";
|
||||||
import { initAuth } from "~/server/lib/auth";
|
|
||||||
import { toMessage } from "~/server/utils/errors";
|
|
||||||
import { withContext } from "~/server/core/request-context";
|
import { withContext } from "~/server/core/request-context";
|
||||||
|
|
||||||
const ensureLatestConfigurationSchema = async () => {
|
const ensureLatestConfigurationSchema = async () => {
|
||||||
|
|
@ -54,11 +52,6 @@ export const startup = async () => {
|
||||||
await Scheduler.start();
|
await Scheduler.start();
|
||||||
await Scheduler.clear();
|
await Scheduler.clear();
|
||||||
|
|
||||||
await initAuth().catch((err) => {
|
|
||||||
logger.error(`Error initializing auth: ${toMessage(err)}`);
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
|
|
||||||
await ensureLatestConfigurationSchema();
|
await ensureLatestConfigurationSchema();
|
||||||
|
|
||||||
const volumes = await db.query.volumesTable.findMany({
|
const volumes = await db.query.volumesTable.findMany({
|
||||||
|
|
|
||||||
11
app/server/plugins/bootstrap.ts
Normal file
11
app/server/plugins/bootstrap.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { definePlugin } from "nitro";
|
||||||
|
import { bootstrapApplication } from "../modules/lifecycle/bootstrap";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
import { toMessage } from "../utils/errors";
|
||||||
|
|
||||||
|
export default definePlugin(() => {
|
||||||
|
void bootstrapApplication().catch((err) => {
|
||||||
|
logger.error(`Bootstrap failed: ${toMessage(err)}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -2,11 +2,9 @@ import { beforeAll, mock } from "bun:test";
|
||||||
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import * as schema from "~/server/db/schema";
|
import { db } from "~/server/db/db";
|
||||||
import { db, setSchema } from "~/server/db/db";
|
import { initModules } from "../server/modules/lifecycle/bootstrap";
|
||||||
import { initAuth } from "~/server/lib/auth";
|
|
||||||
|
|
||||||
setSchema(schema);
|
|
||||||
|
|
||||||
void mock.module("~/server/utils/logger", () => ({
|
void mock.module("~/server/utils/logger", () => ({
|
||||||
logger: {
|
logger: {
|
||||||
|
|
@ -27,7 +25,8 @@ void mock.module("~/server/utils/crypto", () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
await initModules();
|
||||||
|
|
||||||
const migrationsFolder = path.join(cwd(), "app", "drizzle");
|
const migrationsFolder = path.join(cwd(), "app", "drizzle");
|
||||||
migrate(db, { migrationsFolder });
|
migrate(db, { migrationsFolder });
|
||||||
await initAuth();
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ services:
|
||||||
- APP_SECRET=94bad4678ce84a60b9789bd2114a6bf780aeb38df426f7352c941c66e25d5c2b
|
- APP_SECRET=94bad4678ce84a60b9789bd2114a6bf780aeb38df426f7352c941c66e25d5c2b
|
||||||
- BASE_URL=http://localhost:4096
|
- BASE_URL=http://localhost:4096
|
||||||
- PORT=4096
|
- PORT=4096
|
||||||
|
- LOG_LEVEL=debug
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
- /var/lib/zerobyte:/var/lib/zerobyte
|
- /var/lib/zerobyte:/var/lib/zerobyte
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,10 @@ export default defineConfig({
|
||||||
routesDirectory: "routes",
|
routesDirectory: "routes",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
nitro({ preset: "bun" }),
|
nitro({
|
||||||
|
preset: "bun",
|
||||||
|
plugins: ["./app/server/plugins/bootstrap.ts"],
|
||||||
|
}),
|
||||||
viteReact({
|
viteReact({
|
||||||
babel: {
|
babel: {
|
||||||
plugins: ["babel-plugin-react-compiler"],
|
plugins: ["babel-plugin-react-compiler"],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue