Skip to content

Commit 2e03a1e

Browse files
committed
feat: add multistage Dockerfile; serve dashboard static files in production
1 parent 8157d3a commit 2e03a1e

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM node:24-alpine AS builder
2+
3+
RUN corepack enable && corepack prepare [email protected] --activate
4+
5+
WORKDIR /app
6+
7+
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml .npmrc ./
8+
COPY tsconfig.json tsconfig.base.json ./
9+
COPY lib/ ./lib/
10+
COPY artifacts/ ./artifacts/
11+
COPY scripts/ ./scripts/
12+
13+
RUN pnpm install --frozen-lockfile
14+
15+
RUN PORT=3000 BASE_PATH=/ NODE_ENV=production \
16+
pnpm --filter @workspace/images-dashboard run build
17+
18+
RUN pnpm --filter @workspace/api-server run build
19+
20+
FROM node:24-alpine AS runner
21+
22+
WORKDIR /app
23+
24+
COPY --from=builder /app/artifacts/api-server/dist/ ./dist/
25+
COPY --from=builder /app/artifacts/images-dashboard/dist/public/ ./dist/public/
26+
27+
ENV NODE_ENV=production
28+
ENV PORT=8080
29+
EXPOSE 8080
30+
31+
CMD ["node", "--enable-source-maps", "dist/index.mjs"]

artifacts/api-server/src/app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import express, { type Express } from "express";
22
import cors from "cors";
33
import pinoHttp from "pino-http";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
46
import router from "./routes";
57
import { logger } from "./lib/logger";
68

@@ -31,4 +33,12 @@ app.use(express.urlencoded({ extended: true }));
3133

3234
app.use("/api", router);
3335

36+
if (process.env["NODE_ENV"] === "production") {
37+
const publicDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "public");
38+
app.use(express.static(publicDir));
39+
app.get("*", (_req, res) => {
40+
res.sendFile(path.join(publicDir, "index.html"));
41+
});
42+
}
43+
3444
export default app;

0 commit comments

Comments
 (0)