diff --git a/Dockerfile.dokploy b/Dockerfile.dokploy new file mode 100644 index 0000000..ee70d1b --- /dev/null +++ b/Dockerfile.dokploy @@ -0,0 +1,29 @@ +# Production-ready Dockerfile for Dokploy deployments +# Use a Debian-based Node image to ensure native modules such as bcrypt have prebuilt binaries available. +FROM node:20-slim AS base + +# Create application directory inside the container +WORKDIR /app/backend + +# Set production environment variables inside the image. +ENV NODE_ENV=production \ + PORT=3000 + +# Install only the production dependencies defined in the backend package.json. +COPY backend/package*.json ./ +RUN npm ci --omit=dev \ + && npm cache clean --force + +# Copy backend source code and the static frontend bundle into the container. +COPY backend/src ./src +COPY frontend ../frontend + +# Use the non-root "node" user that is precreated in the base image. +RUN chown -R node:node /app +USER node + +# Expose the HTTP port used by the Express server. +EXPOSE 3000 + +# Start the Express API / Socket.IO server. +CMD ["node", "src/server.js"] diff --git a/README.md b/README.md index c60df0f..9c3d7f9 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,26 @@ DoubleSnake ist eine moderne Interpretation des klassischen Snake-Spiels für zw ## 🐳 Docker-Installation -Das Projekt enthält eine Dockerfile für einfaches Deployment: +Das Projekt enthält zwei Docker-Konfigurationen: -```bash -docker build -t doublesnake . -docker run -p 3000:3000 -e DB_HOST=your-db-host doublesnake -``` +- **`Dockerfile`** – Für lokale Tests oder einfache Deployments. + ```bash + docker build -t doublesnake . + docker run -p 3000:3000 -e DB_HOST=your-db-host -e DB_PASSWORD=your-db-password -e SESSION_KEY=your-session-key doublesnake + ``` +- **`Dockerfile.dokploy`** – Optimierte Variante für das Hosting über [Dokploy](https://dokploy.com/). Hierbei wird nur der notwendige Produktionscode in ein Debian-basiertes Node.js-Image übertragen, damit Module wie `bcrypt` ohne zusätzliche Build-Tools funktionieren. + ```bash + docker build -f Dockerfile.dokploy -t doublesnake-prod . + docker run -p 3000:3000 \ + -e SESSION_KEY=your-session-key \ + -e DB_HOST=your-db-host \ + -e DB_PORT=3306 \ + -e DB_USER=your-db-user \ + -e DB_PASSWORD=your-db-password \ + doublesnake-prod + ``` + +> 💡 Für Dokploy sollte die Datenbank als externer Service eingebunden werden. Die oben aufgeführten Umgebungsvariablen können direkt im Dokploy-Dashboard konfiguriert werden. Der statische Frontend-Code wird automatisch in den Container kopiert, daher ist keine zusätzliche Konfiguration für `FRONTEND_PATH` erforderlich. ## 🎮 Spielablauf