diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dcb0c7f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +**/node_modules +apps/web/dist +test-results +data +.git +deploy/.env +docs +tools +assets +e2e diff --git a/deploy/.env.example b/deploy/.env.example new file mode 100644 index 0000000..f01bb71 --- /dev/null +++ b/deploy/.env.example @@ -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 diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..ae7ce4a --- /dev/null +++ b/deploy/Dockerfile @@ -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"] diff --git a/deploy/docker-compose.proxy.yml b/deploy/docker-compose.proxy.yml new file mode 100644 index 0000000..16eacf0 --- /dev/null +++ b/deploy/docker-compose.proxy.yml @@ -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: diff --git a/deploy/npmplus-advanced.conf b/deploy/npmplus-advanced.conf new file mode 100644 index 0000000..6a915db --- /dev/null +++ b/deploy/npmplus-advanced.conf @@ -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;