Merge pull request 'refactor: Revise .dockerignore and Dockerfile for enhanced build efficiency and organization' (#15) from ph4 into prod
Reviewed-on: #15
This commit is contained in:
commit
ca73d6ca79
@ -1,30 +1,55 @@
|
|||||||
# Git files
|
# Git
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
|
|
||||||
# Virtual environment
|
# Python
|
||||||
.venv
|
|
||||||
venv/
|
|
||||||
env/
|
|
||||||
ENV/
|
|
||||||
*.env # Ignore local .env files within the backend directory if any
|
|
||||||
|
|
||||||
# Python cache
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$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/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
# Test artifacts
|
# Logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Local development
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose*
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
tests/
|
||||||
|
test/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
htmlcov/
|
htmlcov/
|
||||||
.coverage*
|
|
||||||
|
|
||||||
# Other build/temp files
|
|
||||||
*.egg-info/
|
|
||||||
dist/
|
|
||||||
build/
|
|
||||||
*.db # e.g., sqlite temp dbs
|
|
@ -1,35 +1,43 @@
|
|||||||
# be/Dockerfile
|
# be/Dockerfile
|
||||||
|
|
||||||
# Choose a suitable Python base image
|
# Use multi-stage build
|
||||||
FROM python:alpine
|
FROM python:alpine AS builder
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1 # Prevent python from writing pyc files
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
ENV PYTHONUNBUFFERED 1 # Keep stdout/stderr unbuffered
|
PYTHONUNBUFFERED=1 \
|
||||||
|
PIP_NO_CACHE_DIR=1 \
|
||||||
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||||
|
|
||||||
# Set the working directory in the container
|
# Install build dependencies
|
||||||
WORKDIR /app
|
RUN apk add --no-cache \
|
||||||
|
gcc \
|
||||||
|
musl-dev \
|
||||||
|
postgresql-dev
|
||||||
|
|
||||||
# Install system dependencies if needed (e.g., for psycopg2 build)
|
# Create and activate virtual environment
|
||||||
# RUN apt-get update && apt-get install -y --no-install-recommends gcc build-essential libpq-dev && rm -rf /var/lib/apt/lists/*
|
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
|
# Install dependencies
|
||||||
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy the rest of the application code into the working directory
|
# Final stage
|
||||||
COPY . .
|
FROM python:alpine
|
||||||
# This includes your 'app/' directory, alembic.ini, etc.
|
|
||||||
|
|
||||||
# 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
|
EXPOSE 8000
|
||||||
|
|
||||||
# Command to run the application using uvicorn
|
# Run the application
|
||||||
# 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.
|
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
Loading…
Reference in New Issue
Block a user