Simplified Docker setup with minimal configuration
This commit is contained in:
parent
a35648d860
commit
57ac07730e
53
Dockerfile
53
Dockerfile
@ -1,64 +1,25 @@
|
|||||||
# Multi-stage Dockerfile for Red Head Python Backend
|
# Simple Dockerfile for Red Head Python Backend
|
||||||
|
|
||||||
# Build stage
|
|
||||||
FROM python:3.9-slim as builder
|
|
||||||
|
|
||||||
# Set working directory
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install system dependencies
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
gcc \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Create a non-root user and group for building
|
|
||||||
RUN groupadd --gid 1001 builder && \
|
|
||||||
useradd --uid 1001 --gid builder --shell /bin/bash --create-home builder
|
|
||||||
|
|
||||||
# Switch to builder user for dependency installation
|
|
||||||
USER builder
|
|
||||||
WORKDIR /home/builder
|
|
||||||
|
|
||||||
# Copy requirements and install Python dependencies in a virtual environment
|
|
||||||
COPY src/server/requirements.txt .
|
|
||||||
RUN python -m venv /home/builder/venv && \
|
|
||||||
/home/builder/venv/bin/pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Production stage
|
|
||||||
FROM python:3.9-slim
|
FROM python:3.9-slim
|
||||||
|
|
||||||
# Create a non-root user and group
|
|
||||||
RUN groupadd --gid 1001 appuser && \
|
|
||||||
useradd --uid 1001 --gid appuser --shell /bin/bash --create-home appuser
|
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy Python dependencies from builder stage (virtual environment)
|
# Copy requirements and install Python dependencies
|
||||||
COPY --from=builder /home/builder/venv /app/venv
|
COPY src/server/requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
COPY --chown=appuser:appuser src/server/ .
|
COPY src/server/ .
|
||||||
|
|
||||||
# Copy website files
|
# Copy website files
|
||||||
COPY --chown=appuser:appuser src/website/ website/
|
COPY src/website/ website/
|
||||||
|
|
||||||
# Create directory for cache if it doesn't exist
|
# Create directory for cache if it doesn't exist
|
||||||
RUN mkdir -p website/cache && \
|
RUN mkdir -p website/cache
|
||||||
chown -R appuser:appuser website/cache
|
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 6006
|
EXPOSE 6006
|
||||||
|
|
||||||
# Set environment variables
|
|
||||||
ENV FLASK_APP=app.py
|
|
||||||
ENV FLASK_ENV=production
|
|
||||||
ENV USER=appuser
|
|
||||||
ENV PATH=/app/venv/bin:$PATH
|
|
||||||
|
|
||||||
# Switch to non-root user
|
|
||||||
USER appuser
|
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||||
CMD curl -f http://localhost:6006/api || exit 1
|
CMD curl -f http://localhost:6006/api || exit 1
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
from flask import Flask, jsonify, request, send_from_directory
|
from flask import Flask, jsonify, request, send_from_directory
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app) # Enable CORS for all routes
|
CORS(app) # Enable CORS for all routes
|
||||||
@ -12,33 +11,6 @@ from parse_archive import ArchiveParser
|
|||||||
# Initialize the archive parser
|
# Initialize the archive parser
|
||||||
archive_parser = ArchiveParser()
|
archive_parser = ArchiveParser()
|
||||||
|
|
||||||
# Validate archive directory at startup
|
|
||||||
def validate_archive_directory():
|
|
||||||
"""Validate that the archive directory exists and has content"""
|
|
||||||
archive_dir = os.environ.get('ARCHIVE_DIR', '/app/archive')
|
|
||||||
print(f"Checking archive directory: {archive_dir}")
|
|
||||||
|
|
||||||
if not os.path.exists(archive_dir):
|
|
||||||
print(f"ERROR: Archive directory does not exist: {archive_dir}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Try to list directories in archive
|
|
||||||
dirs = os.listdir(archive_dir)
|
|
||||||
if not dirs:
|
|
||||||
print(f"WARNING: Archive directory is empty: {archive_dir}")
|
|
||||||
else:
|
|
||||||
print(f"INFO: Archive directory contains {len(dirs)} items")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
print(f"ERROR: Cannot access archive directory {archive_dir}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Validate at startup
|
|
||||||
if not validate_archive_directory():
|
|
||||||
print("FATAL: Archive directory validation failed. Application cannot start.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# Serve static files from the website directory
|
# Serve static files from the website directory
|
||||||
# The website directory is at the same level as the src directory
|
# The website directory is at the same level as the src directory
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user