
Some checks failed
Deploy to Production, build images and push to Gitea Registry / build_and_push (pull_request) Has been cancelled
- Updated .dockerignore to categorize ignored files, including logs and local development configurations. - Implemented a multi-stage build in Dockerfile to optimize image size and dependency management. - Added build dependencies and created a virtual environment for better isolation of Python packages.
43 lines
857 B
Docker
43 lines
857 B
Docker
# be/Dockerfile
|
|
|
|
# Use multi-stage build
|
|
FROM python:alpine AS builder
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache \
|
|
gcc \
|
|
musl-dev \
|
|
postgresql-dev
|
|
|
|
# Create and activate virtual environment
|
|
RUN python -m venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Install dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Final stage
|
|
FROM python:alpine
|
|
|
|
# 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
|
|
|
|
# Run the application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] |