Slim Docker runtime image
All checks were successful
Build & Push Docker Image to Gitea Registry / build-and-push (push) Successful in 2m44s

This commit is contained in:
Kroonk
2026-05-20 17:42:52 +02:00
parent c9919479bf
commit e8c1e3539d
3 changed files with 84 additions and 16 deletions

View File

@@ -1,8 +1,21 @@
.git
.github .github
.gitea
.next
.pnpm-store
.vercel
**/.next
**/.turbo
**/dist
**/node_modules
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md
CONTRIBUTING.md CONTRIBUTING.md
Dockerfile
LICENSE LICENSE
README.md README.md
docker-compose.yml docker-compose.yml
Dockerfile logs
LICENSE *.log
*.local
.env
.env.*

View File

@@ -1,7 +1,4 @@
FROM node:lts-bookworm-slim FROM node:lts-bookworm-slim AS build
# Install git and stockfish (native binary)
RUN apt-get update && apt-get install -y --no-install-recommends git stockfish && rm -rf /var/lib/apt/lists/*
ENV PNPM_HOME=/usr/local/bin ENV PNPM_HOME=/usr/local/bin
@@ -9,21 +6,46 @@ WORKDIR /opt/michess/
COPY . . COPY . .
RUN corepack enable && \
corepack prepare pnpm@9.15.9 --activate && \
pnpm config set store-dir /opt/michess/.pnpm-store && \
pnpm install --no-frozen-lockfile
# Build-time env vars for Next.js (baked into the frontend bundle)
ARG NEXT_PUBLIC_API_URL=http://localhost:3001 ARG NEXT_PUBLIC_API_URL=http://localhost:3001
ARG NEXT_PUBLIC_APP_URL=http://localhost:3000 ARG NEXT_PUBLIC_APP_URL=http://localhost:3000
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
# Build server and client RUN corepack enable && \
RUN pnpm build:server && pnpm build:client corepack prepare pnpm@9.15.9 --activate && \
pnpm config set store-dir /opt/michess/.pnpm-store && \
pnpm install --no-frozen-lockfile && \
pnpm build:server && \
pnpm build:client && \
rm -rf node_modules client/node_modules server/node_modules types/node_modules && \
pnpm install --prod --no-frozen-lockfile && \
pnpm store prune && \
rm -rf \
/opt/michess/.pnpm-store \
/root/.cache \
/tmp/* \
client/.next/cache \
client/src \
server/src \
.git \
.github \
.gitea
FROM node:lts-bookworm-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends stockfish && \
rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
ENV PNPM_HOME=/usr/local/bin
WORKDIR /opt/michess/
COPY --from=build /opt/michess/ ./
RUN corepack enable && corepack prepare pnpm@9.15.9 --activate
EXPOSE 3000 3001 EXPOSE 3000 3001
ENTRYPOINT ["pnpm"] CMD ["node", "scripts/start-production.mjs"]
CMD ["start"]

View File

@@ -0,0 +1,33 @@
import { spawn } from "node:child_process";
const processes = [
spawn("node", ["server/dist/server.js"], { stdio: "inherit" }),
spawn("pnpm", ["--filter", "client", "start"], { stdio: "inherit" })
];
let stopping = false;
function stopAll(signal = "SIGTERM") {
stopping = true;
for (const child of processes) {
if (!child.killed) {
child.kill(signal);
}
}
}
for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, () => {
stopAll(signal);
});
}
for (const child of processes) {
child.on("exit", (code, signal) => {
if (stopping) return;
stopping = true;
stopAll();
process.exit(code ?? (signal ? 1 : 0));
});
}