# Auto-generated Dockerfile for Python application # Generated by BYOP Engine - Python Stack Analyzer FROM python:{{.PythonVersion}}-slim # Set working directory WORKDIR /app {{if .SystemDeps}} # Install system dependencies RUN apt-get update && \ apt-get install -y {{.SystemDeps | join " "}} && \ rm -rf /var/lib/apt/lists/* {{end}} # Upgrade pip RUN pip install --upgrade pip {{if .UsePoetry}} # Install Poetry RUN pip install poetry # Copy poetry files COPY pyproject.toml ./ {{if .HasPoetryLock}} COPY poetry.lock ./ {{end}} # Configure poetry and install dependencies RUN poetry config virtualenvs.create false && \ poetry install {{if .ProductionOnly}}--only=main{{end}} {{else if .UsePipenv}} # Install Pipenv RUN pip install pipenv # Copy Pipenv files COPY Pipfile ./ {{if .HasPipenvLock}} COPY Pipfile.lock ./ {{end}} # Install dependencies using Pipenv RUN pipenv install --system {{if .ProductionOnly}}--deploy{{end}} {{else}} # Copy requirements file {{if .HasDevRequirements}} COPY requirements.txt requirements-dev.txt ./ {{if .ProductionOnly}} RUN pip install --no-cache-dir -r requirements.txt {{else}} RUN pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt {{end}} {{else}} COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt {{end}} {{end}} # Copy source code COPY . . {{if .HasSetupPy}} # Install the package in development mode RUN pip install -e . {{end}} # Create non-root user for security RUN useradd --create-home --shell /bin/bash appuser && \ chown -R appuser:appuser /app # Switch to non-root user USER appuser # Expose port EXPOSE {{.Port}} {{if .HealthCheckEndpoint}} # Add health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:{{.Port}}{{.HealthCheckEndpoint}} || exit 1 {{end}} # Start the application CMD {{.StartCommand | toJSON}}