feat: add Docker setup with multi-stage build

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
achmad
2026-05-29 17:12:29 +07:00
parent f14e6b91f3
commit b55bf45d34
12 changed files with 75 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
node_modules
.next
data
README.md
+40
View File
@@ -0,0 +1,40 @@
FROM node:20-alpine AS base
# Stage 1: Install deps
FROM base AS deps
RUN apk add --no-cache python3 make g++ gcc
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
# Stage 2: Build
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Stage 3: Production runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV DB_PATH=/app/data/zombie_invasion.db
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
ENTRYPOINT ["/bin/sh", "docker-entrypoint.sh"]
View File
+13
View File
@@ -0,0 +1,13 @@
version: '3.8'
services:
app:
build: .
ports:
- "6100:3000"
volumes:
- ./data:/app/data
environment:
- ADMIN_PASSWORD=admin123
- NODE_ENV=production
restart: unless-stopped
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
mkdir -p /app/data
exec node server.js
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const inventory = db.prepare('SELECT * FROM arsenal_inventory ORDER BY steam_id').all();
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const bps = db.prepare('SELECT * FROM battle_passes ORDER BY updated_at DESC').all();
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const contracts = db.prepare('SELECT * FROM death_sentence_contracts').all();
@@ -1,5 +1,7 @@
import { NextResponse } from 'next/server';
export const dynamic = 'force-dynamic';
export async function GET() {
const response = NextResponse.json({ success: true });
response.cookies.delete('admin_session');
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const players = db.prepare('SELECT * FROM players ORDER BY updated_at DESC LIMIT 100').all();
+2
View File
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const players = (db.prepare('SELECT COUNT(*) as c FROM players').get() as any).c;
+2
View File
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server';
import { getDb } from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const db = getDb();
const purchases = db.prepare(`