2단계 배포 파일: Dockerfile·compose(2974, 메모리 1GB, 쿠키 읽기 전용)·NPMplus 보안 헤더(유튜브 플레이어 허용, noindex)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 19:46:31 +09:00
parent 391bbe69e5
commit 992621e70a
5 changed files with 86 additions and 0 deletions

11
.dockerignore Normal file
View File

@@ -0,0 +1,11 @@
node_modules
**/node_modules
apps/web/dist
test-results
data
.git
deploy/.env
docs
tools
assets
e2e

8
deploy/.env.example Normal file
View File

@@ -0,0 +1,8 @@
# Copy to deploy/.env (chmod 600). Never commit deploy/.env.
PUBLIC_ORIGIN=https://mquiz.tkrmagid.kr
APP_PORT=2974
SESSION_SECRET=change-me-at-least-32-characters-long
DISCORD_CLIENT_ID=1561284577564037140
DISCORD_CLIENT_SECRET=
SUPERADMIN_DISCORD_IDS=
YT_COOKIE_PATH=/run/secrets/ytm_cookie.txt

33
deploy/Dockerfile Normal file
View File

@@ -0,0 +1,33 @@
# Multi-stage build: install → build web → slim runtime (same layout as joke-app, docs/09)
FROM oven/bun:1.3 AS build
WORKDIR /app
COPY package.json bun.lock bunfig.toml tsconfig.base.json ./
COPY packages ./packages
COPY apps ./apps
RUN bun install --frozen-lockfile
RUN cd apps/web && bunx vite build
# Production-only dependencies (no vite/typescript/playwright in the runtime image).
FROM oven/bun:1.3 AS deps
WORKDIR /app
COPY package.json bun.lock bunfig.toml ./
COPY packages/shared/package.json packages/shared/
COPY apps/server/package.json apps/server/
COPY apps/web/package.json apps/web/
RUN bun install --frozen-lockfile --production --filter '@mq/server'
FROM oven/bun:1.3-slim
WORKDIR /app
ENV NODE_ENV=production PORT=3000 DB_PATH=/data/app.db TRUST_PROXY=1
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/packages ./packages
COPY --from=build /app/apps/server ./apps/server
COPY --from=build /app/apps/web/dist ./apps/web/dist
RUN mkdir -p /data && chown bun:bun /data
USER bun
VOLUME ["/data"]
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD bun -e "fetch('http://localhost:3000/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
STOPSIGNAL SIGTERM
CMD ["bun", "apps/server/src/index.ts"]

View File

@@ -0,0 +1,27 @@
# App behind NPMplus (192.168.10.3 → .9:2974), docs/09.
# cd deploy && docker --context default compose -f docker-compose.proxy.yml up -d --build
name: music_quiz
services:
app:
build:
context: ..
dockerfile: deploy/Dockerfile
image: music-quiz:${APP_VERSION:-latest}
restart: unless-stopped
env_file: .env
environment:
TRUST_PROXY: "1"
ports:
- "${APP_PORT:-2974}:3000"
volumes:
- app-data:/data
# YouTube Music cookie for song search (collector / admin autofill, later stages). Read-only.
- ${YT_COOKIE_HOST_PATH:-/home/claude/.config/music_quiz/ytm_cookie.txt}:/run/secrets/ytm_cookie.txt:ro
mem_limit: 1g
stop_grace_period: 15s
logging:
driver: json-file
options: { max-size: "50m", max-file: "5" }
volumes:
app-data:

View File

@@ -0,0 +1,7 @@
# NPMplus proxy host "mquiz.tkrmagid.kr" → Advanced. HSTS is set by NPMplus itself.
# YouTube IFrame player (docs/12 Q1): script from youtube.com/ytimg, frame from youtube.com, thumbnails from i.ytimg.com.
more_set_headers "X-Content-Type-Options: nosniff";
more_set_headers "Referrer-Policy: strict-origin-when-cross-origin";
more_set_headers "Content-Security-Policy: default-src 'self'; script-src 'self' https://www.youtube.com https://s.ytimg.com; frame-src https://www.youtube.com https://www.youtube-nocookie.com; img-src 'self' https://cdn.discordapp.com https://i.ytimg.com data:; connect-src 'self' wss://mquiz.tkrmagid.kr; style-src 'self' 'unsafe-inline'; font-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'";
more_set_headers "X-Robots-Tag: noindex, nofollow";
more_clear_headers Server;