-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (55 loc) · 1.47 KB
/
Dockerfile
File metadata and controls
65 lines (55 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Use the official Python slim image as a parent image
FROM python:3.9-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory inside the container
WORKDIR /code
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
curl \
dos2unix \
&& rm -rf /var/lib/apt/lists/*
# Copy and install Python dependencies
COPY requirements.txt /code/
RUN pip install --no-cache-dir -r requirements.txt
# Install Gunicorn
RUN pip install gunicorn
# Copy the entire project into the container
COPY . /code/
# Install netcat
RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/*
# Create entrypoint script
RUN echo '#!/bin/sh\n\
\n\
# Function to wait for a service\n\
wait_for() {\n\
host="$1"\n\
port="$2"\n\
\n\
echo "Waiting for $host:$port..."\n\
\n\
while ! nc -z "$host" "$port"; do\n\
sleep 1\n\
done\n\
\n\
echo "$host:$port is available"\n\
}\n\
\n\
# Wait for required services\n\
wait_for db 5432\n\
wait_for redis 6379\n\
\n\
# Run migrations\n\
python manage.py makemigrations\n\
python manage.py migrate\n\
\n\
# Start the application\n\
python manage.py runserver 0.0.0.0:8000' > /code/entrypoint.sh && \
chmod +x /code/entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["/bin/sh", "/code/entrypoint.sh"]
# Expose port 8000
EXPOSE 8000