dockerized

This commit is contained in:
salvacybersec
2025-11-11 04:30:25 +03:00
parent 8ddd6a983f
commit c62478937e
15 changed files with 1041 additions and 21 deletions

43
backend/.dockerignore Normal file
View File

@@ -0,0 +1,43 @@
# Node modules
node_modules/
npm-debug.log
# Environment files
.env
.env.local
# Git
.git/
.gitignore
# Database (will be in volume)
database/
*.db
*.db-journal
# Logs (will be in volume)
logs/
*.log
# Documentation
*.md
# IDE
.vscode/
.idea/
# OS
.DS_Store
# Testing
coverage/
.nyc_output/
# Migrations (already applied)
migrations/
seeders/
# Temporary
tmp/
temp/

54
backend/Dockerfile Normal file
View File

@@ -0,0 +1,54 @@
# Backend Dockerfile
# Multi-stage build for optimized production image
# Stage 1: Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Stage 2: Production stage
FROM node:20-alpine
# Install required packages
RUN apk add --no-cache \
sqlite \
tini
# Create app user
RUN addgroup -g 1001 -S oltalama && \
adduser -S oltalama -u 1001 -G oltalama
WORKDIR /app
# Copy dependencies from builder
COPY --from=builder /app/node_modules ./node_modules
# Copy application code
COPY --chown=oltalama:oltalama . .
# Create necessary directories
RUN mkdir -p database logs && \
chown -R oltalama:oltalama /app
# Switch to non-root user
USER oltalama
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Use tini as entrypoint for proper signal handling
ENTRYPOINT ["/sbin/tini", "--"]
# Start application
CMD ["node", "src/app.js"]

33
backend/Dockerfile.dev Normal file
View File

@@ -0,0 +1,33 @@
# Backend Development Dockerfile
# Hot reload enabled with nodemon
FROM node:20-alpine
# Install required packages
RUN apk add --no-cache \
sqlite \
tini
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including dev)
RUN npm install
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p database logs
# Expose port
EXPOSE 3000
# Use tini as entrypoint
ENTRYPOINT ["/sbin/tini", "--"]
# Start with nodemon for hot reload
CMD ["npm", "run", "dev"]