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.
This commit is contained in:
Wizznu 2026-02-10 11:29:49 +07:00
parent a9d894b2fd
commit 94499d02d5
2 changed files with 99 additions and 0 deletions

54
.dockerignore Normal file
View File

@ -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/

45
Dockerfile Normal file
View File

@ -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"]