refactor: Revise .dockerignore and Dockerfile for enhanced build efficiency and organization #15
@ -1,30 +1,55 @@
|
||||
# Git files
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Virtual environment
|
||||
.venv
|
||||
venv/
|
||||
env/
|
||||
ENV/
|
||||
*.env # Ignore local .env files within the backend directory if any
|
||||
|
||||
# Python cache
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# IDE files
|
||||
# Virtual Environment
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Test artifacts
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Local development
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Docker
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
.dockerignore
|
||||
|
||||
# Tests
|
||||
tests/
|
||||
test/
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
.coverage*
|
||||
|
||||
# Other build/temp files
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
*.db # e.g., sqlite temp dbs
|
@ -1,35 +1,43 @@
|
||||
# be/Dockerfile
|
||||
|
||||
# Choose a suitable Python base image
|
||||
FROM python:alpine
|
||||
# Use multi-stage build
|
||||
FROM python:alpine AS builder
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE 1 # Prevent python from writing pyc files
|
||||
ENV PYTHONUNBUFFERED 1 # Keep stdout/stderr unbuffered
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PIP_NO_CACHE_DIR=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
gcc \
|
||||
musl-dev \
|
||||
postgresql-dev
|
||||
|
||||
# Install system dependencies if needed (e.g., for psycopg2 build)
|
||||
# RUN apt-get update && apt-get install -y --no-install-recommends gcc build-essential libpq-dev && rm -rf /var/lib/apt/lists/*
|
||||
# Create and activate virtual environment
|
||||
RUN python -m venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# Install Python dependencies
|
||||
# Upgrade pip first
|
||||
RUN pip install --no-cache-dir --upgrade pip
|
||||
# Copy only requirements first to leverage Docker cache
|
||||
COPY requirements.txt requirements.txt
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the rest of the application code into the working directory
|
||||
COPY . .
|
||||
# This includes your 'app/' directory, alembic.ini, etc.
|
||||
# Final stage
|
||||
FROM python:alpine
|
||||
|
||||
# Expose the port the app runs on
|
||||
# Copy virtual environment from builder
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Command to run the application using uvicorn
|
||||
# The default command for production (can be overridden in docker-compose for development)
|
||||
# Note: Make sure 'app.main:app' correctly points to your FastAPI app instance
|
||||
# relative to the WORKDIR (/app). If your main.py is directly in /app, this is correct.
|
||||
# Run the application
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
Loading…
Reference in New Issue
Block a user