fix: Include src in Dockerfile and make DB init non-blocking with retry
This commit is contained in:
parent
45946b797e
commit
c24b33143d
@ -1,4 +1,4 @@
|
|||||||
FROM denoland/deno:alpine-2.0.2
|
FROM docker.io/denoland/deno:alpine-2.0.2
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@ -8,6 +8,7 @@ RUN deno install || true
|
|||||||
|
|
||||||
# Copy source code and assets
|
# Copy source code and assets
|
||||||
COPY main.ts .
|
COPY main.ts .
|
||||||
|
COPY src ./src
|
||||||
COPY viewer ./viewer
|
COPY viewer ./viewer
|
||||||
COPY data ./data
|
COPY data ./data
|
||||||
COPY mechanical ./mechanical
|
COPY mechanical ./mechanical
|
||||||
|
|||||||
4
main.ts
4
main.ts
@ -5,8 +5,8 @@ import { qaRoutes } from "./src/routes/qa.ts";
|
|||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
// Initialize DB schema on startup
|
// Initialize DB schema in background so server opens port immediately
|
||||||
await initDb();
|
initDb().catch((err) => console.error("Database background init failed:", err));
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
app.get("/api/status", async (c) => {
|
app.get("/api/status", async (c) => {
|
||||||
|
|||||||
@ -6,9 +6,14 @@ export const sql = postgres({
|
|||||||
database: Deno.env.get("POSTGRES_DB") || "nas_builder",
|
database: Deno.env.get("POSTGRES_DB") || "nas_builder",
|
||||||
username: Deno.env.get("POSTGRES_USER") || "nasadmin",
|
username: Deno.env.get("POSTGRES_USER") || "nasadmin",
|
||||||
password: Deno.env.get("POSTGRES_PASSWORD") || "your_secure_database_password_here",
|
password: Deno.env.get("POSTGRES_PASSWORD") || "your_secure_database_password_here",
|
||||||
|
max: 10,
|
||||||
|
idle_timeout: 30,
|
||||||
|
connect_timeout: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function initDb() {
|
export async function initDb(retries = 5, delayMs = 2000) {
|
||||||
|
for (let i = 0; i < retries; i++) {
|
||||||
|
try {
|
||||||
await sql`
|
await sql`
|
||||||
CREATE TABLE IF NOT EXISTS qa_checklists (
|
CREATE TABLE IF NOT EXISTS qa_checklists (
|
||||||
id VARCHAR(50) PRIMARY KEY,
|
id VARCHAR(50) PRIMARY KEY,
|
||||||
@ -18,7 +23,6 @@ export async function initDb() {
|
|||||||
);
|
);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Seed some initial data if empty
|
|
||||||
const count = await sql`SELECT count(*) FROM qa_checklists`;
|
const count = await sql`SELECT count(*) FROM qa_checklists`;
|
||||||
if (count[0].count === "0") {
|
if (count[0].count === "0") {
|
||||||
await sql`
|
await sql`
|
||||||
@ -29,5 +33,15 @@ export async function initDb() {
|
|||||||
('qa-zfs', 'ZFS pool scrub baseline passed', false)
|
('qa-zfs', 'ZFS pool scrub baseline passed', false)
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
console.log("✅ Database schema initialized");
|
console.log("✅ Database schema initialized successfully");
|
||||||
|
return;
|
||||||
|
} catch (err: any) {
|
||||||
|
console.warn(`⚠️ Database init attempt ${i + 1}/${retries} failed: ${err.message}`);
|
||||||
|
if (i < retries - 1) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||||
|
} else {
|
||||||
|
console.error("❌ Could not initialize database schema after retries:", err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user