From 94499d02d581bc8d3da0bf51184e938c5c2b04b7 Mon Sep 17 00:00:00 2001 From: Wizznu Date: Tue, 10 Feb 2026 11:29:49 +0700 Subject: [PATCH] feat: Add Dockerfile for Railway deployment Added production-ready Dockerfile: - Node.js 18 Alpine (lightweight) - Multi-stage dependency installation - Health check monitoring - Non-root user for security - Production optimizations Added .dockerignore: - Exclude node_modules (reinstalled in Docker) - Exclude .env files (Railway injects env vars) - Reduce image size - Faster build times Railway will now detect project type via Dockerfile instead of guessing from package.json. This ensures proper build configuration for BullMQ worker. --- .dockerignore | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..784c6be --- /dev/null +++ b/.dockerignore @@ -0,0 +1,54 @@ +# =================================================================== +# .dockerignore - File yang diabaikan saat build Docker image +# Mengurangi ukuran image dan mempercepat build +# =================================================================== + +# Dependencies (akan di-install ulang di Dockerfile) +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Environment files (Railway akan inject environment variables) +.env +.env.local +.env.*.local +.env.example + +# Git files +.git/ +.gitignore +.github/ + +# Documentation +README.md +*.md +docs/ + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +Thumbs.db + +# Test files +test/ +*.test.js +coverage/ + +# Build artifacts +dist/ +build/ + +# Logs +logs/ +*.log + +# Temporary files +tmp/ +temp/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e061c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# =================================================================== +# Dockerfile untuk ApsGo Railway Worker +# Background service untuk IoT automation dengan BullMQ + Redis +# =================================================================== + +# Base image: Node.js 18 LTS (Alpine untuk size kecil) +FROM node:18-alpine + +# Metadata +LABEL maintainer="ApsGo Team" +LABEL description="Railway Worker untuk ApsGo - 24/7 IoT Automation" +LABEL version="1.0.0" + +# Set working directory +WORKDIR /app + +# Copy package files dulu (untuk leverage Docker cache) +COPY package.json package-lock.json* ./ + +# Install dependencies +# --production: hanya production dependencies (tanpa devDependencies) +# --silent: suppress npm warnings +RUN npm install --production --silent + +# Copy source code +COPY worker.js ./ + +# Environment variables (akan di-override oleh Railway) +ENV NODE_ENV=production +ENV LOG_LEVEL=info + +# Health check (optional - Railway bisa monitor via process) +# Cek apakah process masih berjalan setiap 30 detik +HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ + CMD node -e "process.exit(0)" + +# Expose port (OPTIONAL - worker tidak butuh port) +# Tapi tetap define untuk dokumentasi +# EXPOSE 3000 + +# User non-root untuk security (best practice) +USER node + +# Start command: jalankan worker +CMD ["node", "worker.js"]