Merge pull request 'Add Docker image for self-hosted deployment' (#2) from feat/self-host-deploy into main

This commit is contained in:
2026-11-09 04:02:23 +00:00
4 changed files with 53 additions and 2 deletions
+8
View File
@@ -0,0 +1,8 @@
.git
.next
node_modules
npm-debug.log*
.env*
Dockerfile
.dockerignore
README.md
+31
View File
@@ -0,0 +1,31 @@
# Production image. Designed for a hardened runtime: read-only root filesystem,
# a tmpfs at /tmp, no Linux capabilities, and a reverse proxy in front.
FROM node:22-bookworm-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
FROM node:22-bookworm-slim AS build
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN mkdir -p public && npm run build
FROM node:22-bookworm-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0
COPY --from=build --chown=node:node /app/.next/standalone ./
COPY --from=build --chown=node:node /app/.next/static ./.next/static
COPY --from=build --chown=node:node /app/public ./public
# The root filesystem is read-only at runtime, so Next's cache goes to the /tmp tmpfs.
RUN rm -rf .next/cache && ln -s /tmp/next-cache .next/cache
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
CMD node -e "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node", "server.js"]
+12 -1
View File
@@ -34,6 +34,16 @@ npm run dev # http://localhost:3000
| `npm run build` | Production build. Every page is statically prerendered. |
| `npm run format` | Runs Prettier, which also sorts Tailwind classes |
## Deploying
Live at **https://playground.jun-liu.net**.
Merging to `main` deploys automatically: the server builds the `Dockerfile` and
swaps the running container. If a build fails, the running version stays up.
The image uses Next's `standalone` output and runs as the unprivileged `node`
user on a read-only filesystem.
## Structure
```
@@ -63,4 +73,5 @@ src/
- [ ] Toast stack with swipe-to-dismiss
- [ ] Playwright visual regression and axe checks in CI
- [ ] Case-study write-ups for each component: the problem, the options, and the decision
- [ ] Deploy (Vercel) and link from a portfolio
- [x] Deploy
- [ ] Link from a portfolio
+2 -1
View File
@@ -1,7 +1,8 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
// Self-contained server bundle for the Docker image (see Dockerfile).
output: "standalone",
cacheComponents: true,
partialPrefetching: true,
turbopack: {