diff --git a/docker-compose.yaml b/docker-compose.yaml index ff7283b..1d034e5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -63,7 +63,7 @@ services: build: dockerfile: dev.Dockerfile container_name: celery_worker - command: ["celery", "-A", "middleware.celery", "worker", "-B", "--loglevel=info"] + command: ["sh", "-c", "/app/start-celery.sh"] volumes: - .:/app env_file: diff --git a/prod.Dockerfile b/prod.Dockerfile new file mode 100644 index 0000000..d921f8e --- /dev/null +++ b/prod.Dockerfile @@ -0,0 +1,40 @@ +# Stage 1: Build stage +FROM python:3.12-slim-bookworm AS builder + +ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PATH /venv/bin:$PATH + +# Create virtual environment +RUN python -m venv /venv + +# Install pipenv and dependencies +RUN pip install --no-cache-dir pipenv + +# Copy Pipfile and Pipfile.lock for dependency installation +COPY Pipfile Pipfile.lock ./ + +# Install only production dependencies +RUN pipenv install --system --deploy --ignore-pipfile + +# Stage 2: Production stage +FROM python:3.12-slim-bookworm + +ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PATH /venv/bin:$PATH + +# Copy virtual environment from the builder stage +COPY --from=builder /venv /venv + +# Copy the application code +COPY . /app + +# Set the working directory +WORKDIR /app + +# Expose the application port +EXPOSE 8090 + + +CMD ["python", "manage.py" , "runserver" , "0.0.0.0:8090"] diff --git a/start-celery.sh b/start-celery.sh new file mode 100755 index 0000000..d25e6b5 --- /dev/null +++ b/start-celery.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Navigate to the app directory +cd /app + +# Run migrations +python manage.py migrate + +# Start Celery worker +celery -A middleware.celery worker -B --loglevel=info