python.tmpl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Auto-generated Dockerfile for Python application
  2. # Generated by BYOP Engine - Python Stack Analyzer
  3. FROM python:{{.PythonVersion}}-slim
  4. # Set working directory
  5. WORKDIR /app
  6. {{if .SystemDeps}}
  7. # Install system dependencies
  8. RUN apt-get update && \
  9. apt-get install -y {{.SystemDeps | join " "}} && \
  10. rm -rf /var/lib/apt/lists/*
  11. {{end}}
  12. # Upgrade pip
  13. RUN pip install --upgrade pip
  14. {{if .UsePoetry}}
  15. # Install Poetry
  16. RUN pip install poetry
  17. # Copy poetry files
  18. COPY pyproject.toml ./
  19. {{if .HasPoetryLock}}
  20. COPY poetry.lock ./
  21. {{end}}
  22. # Configure poetry and install dependencies
  23. RUN poetry config virtualenvs.create false && \
  24. poetry install {{if .ProductionOnly}}--only=main{{end}}
  25. {{else if .UsePipenv}}
  26. # Install Pipenv
  27. RUN pip install pipenv
  28. # Copy Pipenv files
  29. COPY Pipfile ./
  30. {{if .HasPipenvLock}}
  31. COPY Pipfile.lock ./
  32. {{end}}
  33. # Install dependencies using Pipenv
  34. RUN pipenv install --system {{if .ProductionOnly}}--deploy{{end}}
  35. {{else}}
  36. # Copy requirements file
  37. {{if .HasDevRequirements}}
  38. COPY requirements.txt requirements-dev.txt ./
  39. {{if .ProductionOnly}}
  40. RUN pip install --no-cache-dir -r requirements.txt
  41. {{else}}
  42. RUN pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt
  43. {{end}}
  44. {{else}}
  45. COPY requirements.txt ./
  46. RUN pip install --no-cache-dir -r requirements.txt
  47. {{end}}
  48. {{end}}
  49. # Copy source code
  50. COPY . .
  51. {{if .HasSetupPy}}
  52. # Install the package in development mode
  53. RUN pip install -e .
  54. {{end}}
  55. # Create non-root user for security
  56. RUN useradd --create-home --shell /bin/bash appuser && \
  57. chown -R appuser:appuser /app
  58. # Switch to non-root user
  59. USER appuser
  60. # Expose port
  61. EXPOSE {{.Port}}
  62. {{if .HealthCheckEndpoint}}
  63. # Add health check
  64. HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  65. CMD curl -f http://localhost:{{.Port}}{{.HealthCheckEndpoint}} || exit 1
  66. {{end}}
  67. # Start the application
  68. CMD {{.StartCommand | toJSON}}