diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..fd975aa --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,59 @@ +# Multi-stage build +FROM node:14-alpine as frontend-builder +WORKDIR /app/frontend +COPY frontend/package*.json ./ +RUN npm install +COPY frontend/ ./ +RUN npm run build + +FROM python:3.8-slim + +# Install HAProxy and Certbot +RUN apt-get update && \ + apt-get install -y \ + haproxy \ + certbot \ + python3-certbot \ + && rm -rf /var/lib/apt/lists/* + +# Create necessary directories +RUN mkdir -p /etc/haproxy/certs \ + && mkdir -p /var/lib/haproxy \ + && mkdir -p /run/haproxy + +# Set up Python environment +WORKDIR /app +COPY backend/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy backend code +COPY backend/ ./backend/ + +# Copy frontend build +COPY --from=frontend-builder /app/frontend/build ./frontend/build + +# Copy HAProxy configuration +COPY backend/templates/haproxy.cfg.j2 /etc/haproxy/haproxy.cfg.template + +# Install curl for healthcheck +RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* + +# Create data directory +RUN mkdir -p /app/backend/data + +# Set permissions +RUN chown -R nobody:nogroup /app/backend/data + +# Add healthcheck +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:5000/health || exit 1 + +# Create run script +RUN echo '#!/bin/sh\n\ +python backend/app.py &\n\ +haproxy -f /etc/haproxy/haproxy.cfg -db\n' > /start.sh && \ +chmod +x /start.sh + +EXPOSE 80 443 5000 + +CMD ["/start.sh"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..ff6f629 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.8' + +services: + haproxy-manager: + build: + context: .. + dockerfile: docker/Dockerfile + ports: + - "80:80" + - "443:443" + - "5000:5000" + volumes: + - haproxy-certs:/etc/haproxy/certs + - letsencrypt:/etc/letsencrypt + - sqlite-data:/app/backend/data + environment: + - FLASK_ENV=production + - SECRET_KEY=changeme + - DATABASE_URL=sqlite:///data/haproxy-manager.db + - JWT_SECRET_KEY=change-this-in-production + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 5s + restart: unless-stopped + +volumes: + haproxy-certs: + letsencrypt: + sqlite-data: