Skip to content

Commit

Permalink
Prod docker file for middleware (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkurPrabhu authored Sep 2, 2024
1 parent efbaf37 commit 9540fb9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 10 additions & 0 deletions start-celery.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9540fb9

Please sign in to comment.