diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a616e64 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +dist +snapshots +.git +*.log +Dockerfile +docker-compose.yml +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a82172f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# syntax=docker/dockerfile:1 + +# ---- deps: install node_modules once, shared by the dev and build stages ---- +FROM node:22-alpine AS deps +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci + +# ---- dev: Vite dev server with hot reload (used by the `dev` compose profile) ---- +FROM deps AS dev +COPY . . +EXPOSE 5173 +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"] + +# ---- build: typecheck and produce the static site in /app/dist ---- +FROM deps AS build +COPY . . +RUN npm run build + +# ---- runtime: serve the static site with nginx ---- +FROM nginx:1.29-alpine AS runtime +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /app/dist /usr/share/nginx/html +EXPOSE 80 +HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1 diff --git a/README.md b/README.md index 9a6e262..461cb6d 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,32 @@ Calm pixel art meditations for the browser. Pick a journey from the main menu, s ## Run +### With Node (local) + ```bash npm install npm run dev # http://localhost:5173 npm run build # static site in dist/ ``` +### With Docker Compose + +```bash +docker compose up --build -d # production build served by nginx → http://localhost:8080 +docker compose --profile dev up --build dev # Vite dev server with hot reload → http://localhost:5173 +docker compose down # stop +``` + +Change the host ports with `PIXELTATION_PORT` / `PIXELTATION_DEV_PORT` +(e.g. `PIXELTATION_PORT=3000 docker compose up -d`). The dev service bind-mounts the project, +so edits on the host reload in the browser; don't run it and `npm run dev` on the same port at once. + +| File | Purpose | +|---|---| +| `Dockerfile` | Multi-stage: `deps` → `dev` (Vite) / `build` (typecheck + bundle) → `runtime` (nginx) | +| `docker-compose.yml` | `web` service (default) and `dev` service (`dev` profile) | +| `docker/nginx.conf` | Static serving, gzip, long-cache for fingerprinted `/assets` | + ## Meditations | id | Title | Length | @@ -24,6 +44,7 @@ that is scaled up crisply, so all art is generated in code. Drop an audio file in `public/audio/` and set `music: 'audio/.mp3'` on the meditation (e.g. in `src/meditations/northern-cabin/index.ts`). It fades in at the start and out over the last 10 seconds. +With Docker, rebuild the `web` image (`docker compose up --build -d`) so the file is included. ## Dev tools diff --git a/docker-check.png b/docker-check.png new file mode 100644 index 0000000..4c0632d Binary files /dev/null and b/docker-check.png differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..030c8bf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +# Production-style: docker compose up --build → http://localhost:8080 +# Dev (hot reload): docker compose --profile dev up dev → http://localhost:5173 +services: + web: + build: + context: . + target: runtime + image: pixeltation:latest + ports: + - "${PIXELTATION_PORT:-8080}:80" + restart: unless-stopped + + dev: + profiles: ["dev"] + build: + context: . + target: dev + ports: + - "${PIXELTATION_DEV_PORT:-5173}:5173" + volumes: + - .:/app + # Keep the container's own node_modules instead of the host's. + - /app/node_modules diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..280f8d9 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,27 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + gzip on; + gzip_types text/css application/javascript application/json image/svg+xml; + gzip_min_length 1024; + + # Vite fingerprints everything under /assets, so it can be cached forever. + location /assets/ { + add_header Cache-Control "public, max-age=31536000, immutable"; + try_files $uri =404; + } + + # Music files dropped into public/audio/. + location /audio/ { + add_header Cache-Control "public, max-age=86400"; + try_files $uri =404; + } + + location / { + add_header Cache-Control "no-cache"; + try_files $uri $uri/ /index.html; + } +} diff --git a/public/audio/coastline.mp3 b/public/audio/coastline.mp3 new file mode 100644 index 0000000..2cf46e5 Binary files /dev/null and b/public/audio/coastline.mp3 differ diff --git a/public/audio/fx-waves.mp3 b/public/audio/fx-waves.mp3 new file mode 100644 index 0000000..bd6ebbf Binary files /dev/null and b/public/audio/fx-waves.mp3 differ