feat: add Docker containerization with multi-stage build

Includes .dockerignore, Dockerfile with cargo-chef caching, and Justfile commands for building/running containerized app. Updates console-logger to support both JSON and pretty-printed logs based on LOG_JSON env var.
This commit is contained in:
2026-01-04 20:06:56 -06:00
parent edf271bcc6
commit 9de3c84f00
15 changed files with 238 additions and 244 deletions
+35 -20
View File
@@ -1,6 +1,3 @@
// Patch console methods to output structured JSON logs
// This runs before the Bun server starts to ensure all console output is formatted
const originalConsole = {
log: console.log,
error: console.error,
@@ -9,23 +6,41 @@ const originalConsole = {
debug: console.debug,
};
const useJson = process.env.LOG_JSON === "true" || process.env.LOG_JSON === "1";
function formatLog(level, args) {
const message = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
).join(' ');
const logEntry = {
timestamp: new Date().toISOString(),
level: level,
message: message,
target: 'bun',
};
originalConsole.log(JSON.stringify(logEntry));
const message = args
.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
.join(" ");
if (useJson) {
const logEntry = {
timestamp: new Date().toISOString(),
level: level,
message: message,
target: "bun",
};
originalConsole.log(JSON.stringify(logEntry));
} else {
const timestamp = new Date().toISOString().split("T")[1].slice(0, 12);
const levelColors = {
debug: "\x1b[36m", // cyan
info: "\x1b[32m", // green
warn: "\x1b[33m", // yellow
error: "\x1b[31m", // red
};
const color = levelColors[level] || "";
const reset = "\x1b[0m";
const gray = "\x1b[90m";
originalConsole.log(
`${gray}${timestamp}${reset} ${color}${level.toUpperCase().padEnd(5)}${reset} ${gray}bun${reset}: ${message}`,
);
}
}
console.log = (...args) => formatLog('info', args);
console.info = (...args) => formatLog('info', args);
console.warn = (...args) => formatLog('warn', args);
console.error = (...args) => formatLog('error', args);
console.debug = (...args) => formatLog('debug', args);
console.log = (...args) => formatLog("info", args);
console.info = (...args) => formatLog("info", args);
console.warn = (...args) => formatLog("warn", args);
console.error = (...args) => formatLog("error", args);
console.debug = (...args) => formatLog("debug", args);