fix: Include src in Dockerfile and make DB init non-blocking with retry

This commit is contained in:
Tyler G 2026-08-22 22:41:34 -07:00
parent 45946b797e
commit c24b33143d
3 changed files with 39 additions and 24 deletions

View File

@ -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

View File

@ -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) => {

View File

@ -6,28 +6,42 @@ 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) {
await sql` for (let i = 0; i < retries; i++) {
CREATE TABLE IF NOT EXISTS qa_checklists ( try {
id VARCHAR(50) PRIMARY KEY, await sql`
label TEXT NOT NULL, CREATE TABLE IF NOT EXISTS qa_checklists (
is_completed BOOLEAN DEFAULT false, id VARCHAR(50) PRIMARY KEY,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP label TEXT NOT NULL,
); is_completed BOOLEAN DEFAULT false,
`; updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`;
// 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` INSERT INTO qa_checklists (id, label, is_completed) VALUES
INSERT INTO qa_checklists (id, label, is_completed) VALUES ('qa-cap', 'Supercap mounted & isolated', false),
('qa-cap', 'Supercap mounted & isolated', false), ('qa-sas', 'Broadcom SAS seated in PCIe', false),
('qa-sas', 'Broadcom SAS seated in PCIe', false), ('qa-cool', 'Waterblock pressure tested', false),
('qa-cool', 'Waterblock pressure tested', false), ('qa-zfs', 'ZFS pool scrub baseline passed', false)
('qa-zfs', 'ZFS pool scrub baseline passed', false) `;
`; }
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);
}
}
} }
console.log("✅ Database schema initialized");
} }