- POST /api/upload: FormData, 10MB limit, sharp resize 800px inside + webp@80, saves to /app/uploads, returns /uploads/url - GET /uploads/[...path]: serves files with Content-Type, path traversal protected - compose: ./uploads mounted in tg_shop_admin - Dockerfile: /app/uploads created + chown nextjs - catalog-page: file input + thumbnail preview + remove for photoUrl/hiddenPhotoUrl - Bot resolvePhotoSource already supports /uploads/ paths — no bot changes
66 lines
1.4 KiB
Docker
66 lines
1.4 KiB
Docker
# --- Stage 1: Build ---
|
|
FROM node:22-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install bun for faster installs
|
|
RUN npm install -g bun
|
|
|
|
# Install dependencies
|
|
COPY package.json bun.lock ./
|
|
RUN bun install --frozen-lockfile
|
|
|
|
# Copy source
|
|
COPY prisma ./prisma/
|
|
COPY tsconfig.json next.config.ts postcss.config.mjs tailwind.config.ts components.json ./
|
|
COPY public ./public/
|
|
COPY src ./src/
|
|
|
|
# Generate Prisma client
|
|
RUN npx prisma generate
|
|
|
|
# Build Next.js (output: standalone)
|
|
RUN npx next build
|
|
|
|
# Copy static assets into standalone
|
|
RUN cp -r .next/static .next/standalone/.next/ && \
|
|
cp -r public .next/standalone/
|
|
|
|
# --- Stage 2: Production ---
|
|
FROM node:22-slim AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# OpenSSL для Prisma (SQLite) + curl для healthcheck
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
openssl \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create non-root user
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs
|
|
|
|
# Copy standalone output
|
|
COPY --from=builder /app/.next/standalone ./
|
|
|
|
# Copy static files
|
|
COPY --from=builder /app/.next/standalone/.next ./.next
|
|
|
|
# Copy Prisma schema for potential migrations
|
|
COPY --from=builder /app/prisma ./prisma/
|
|
|
|
# Create db and uploads directories
|
|
RUN mkdir -p /app/db /app/uploads && chown nextjs:nodejs /app/db /app/uploads
|
|
|
|
# Switch to non-root
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", "server.js"]
|