Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
  • stage-features
2 results

Dockerfile

Blame
  • Dockerfile 1.83 KiB
    # Stage 1: Build the Rust extension using maturin
    FROM rust:latest as builder
    
    # Install Python and system dependencies required for maturin
    RUN apt-get update && apt-get install -y \
        python3 \
        python3-pip \
        build-essential \
        libssl-dev
    
    # Install maturin
    RUN pip3 install --break-system-packages maturin
    
    WORKDIR /build
    
    # Copy the Rust project folder into the builder stage.
    # This assumes the folder "rust_crud_api" is in the build context.
    COPY rust_crud_api/ ./rust_crud_api/
    
    # Change directory into the Rust project and build the wheel.
    WORKDIR /build/rust_crud_api
    RUN maturin build --release
    
    # Stage 2: Build the final Django container
    FROM python:3.11-slim
    
    # Install system dependencies needed for Django and Postgres
    RUN apt-get update && apt-get install -y libpq-dev gcc && rm -rf /var/lib/apt/lists/*
    
    WORKDIR /app
    
    # Copy the built Rust extension wheel from the builder stage.
    # This assumes maturin built the wheel into rust_crud_api/target/wheels/
    COPY --from=builder /build/rust_crud_api/target/wheels/*.whl .
    
    # Install the Rust extension into the Python environment.
    RUN pip install --no-cache-dir *.whl
    
    # Copy your Django project into the container.
    # In this example, we assume the Django project (including manage.py) is inside the "django_project" folder.
    COPY django_project/ ./django_project/
    
    # Set the working directory to your Django project folder.
    WORKDIR /app/django_project
    
    # Install Django and other Python dependencies (adjust as needed).
    RUN pip install --no-cache-dir django psycopg2-binary
    
    # Set environment variables (adjust the DATABASE_URL as needed).
    ENV DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
    
    # Expose the port that Django will run on.
    EXPOSE 8000
    
    # Run the Django development server (for production use a proper WSGI/ASGI server).
    CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]