Dockerfile.bak-prefix 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Multi-stage Dockerfile for ARM64 optimization
  2. # Stage 1: Build dependencies + PyArmor obfuscation
  3. FROM python:3.11-slim-bullseye as builder
  4. # Install system dependencies for building
  5. RUN apt-get update && apt-get install -y \
  6. build-essential \
  7. curl \
  8. && rm -rf /var/lib/apt/lists/*
  9. # Create virtual environment
  10. RUN python -m venv /opt/venv
  11. ENV PATH="/opt/venv/bin:$PATH"
  12. # Copy requirements and install Python dependencies + PyArmor
  13. COPY requirements.txt .
  14. RUN pip install --no-cache-dir --upgrade pip && \
  15. pip install --no-cache-dir -r requirements.txt && \
  16. pip install --no-cache-dir pyarmor
  17. # Copy application code for obfuscation
  18. COPY . /build
  19. WORKDIR /build
  20. # Fix CRLF + register license + obfuscate
  21. # Skip if WAOUW_SKIP_OBFUSCATION=1 (for development/debugging)
  22. ARG WAOUW_SKIP_OBFUSCATION=0
  23. RUN find /build -name "*.py" -exec sed -i 's/\r$//' {} + && \
  24. find /build -name "*.sh" -exec sed -i 's/\r$//' {} + && \
  25. if [ "$WAOUW_SKIP_OBFUSCATION" != "1" ]; then \
  26. bash /build/obfuscate.sh 2>&1 || echo "Obfuscation failed, continuing with plain .py"; \
  27. fi
  28. # Production stage
  29. FROM python:3.11-slim-bullseye
  30. # Install runtime dependencies (curl, Docker CLI for exec, SMB/NFS for backup)
  31. RUN apt-get update && apt-get install -y \
  32. curl \
  33. cifs-utils \
  34. nfs-common \
  35. ca-certificates \
  36. gnupg \
  37. && install -m 0755 -d /etc/apt/keyrings \
  38. && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
  39. && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" > /etc/apt/sources.list.d/docker.list \
  40. && apt-get update && apt-get install -y docker-ce-cli \
  41. && rm -rf /var/lib/apt/lists/*
  42. # Create non-root user
  43. RUN groupadd -r waouw && useradd -r -g waouw waouw
  44. # Copy virtual environment from builder
  45. COPY --from=builder /opt/venv /opt/venv
  46. ENV PATH="/opt/venv/bin:$PATH"
  47. # Set working directory
  48. WORKDIR /app
  49. # Copy obfuscated application code from builder
  50. COPY --from=builder --chown=waouw:waouw /build .
  51. # Remove build artifacts and Docker marker (PyArmor license check)
  52. RUN rm -f compile_cython.py obfuscate.sh pyarmor-regkey.txt && \
  53. rm -rf build/ __pycache__/ && \
  54. find . -name "*.c" -delete && \
  55. find . -name "_cython_setup_*" -delete && \
  56. rm -f /.dockerenv
  57. # Create directories for logs and data
  58. RUN mkdir -p /app/logs /app/data /data/backups && \
  59. chown -R waouw:waouw /app /data/backups
  60. # Switch to non-root user
  61. USER waouw
  62. # Health check
  63. HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  64. CMD curl -f http://localhost:8000/health || exit 1
  65. # Expose port
  66. EXPOSE 8000
  67. # Start application
  68. CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]