File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Use official Python image
22FROM python:3.11-slim
33
4+ # Install PostgreSQL client and server
5+ RUN apt-get update && apt-get install -y \
6+ postgresql \
7+ postgresql-contrib \
8+ postgresql-client \
9+ && rm -rf /var/lib/apt/lists/*
10+
411# Set work directory
512WORKDIR /app
613
714# Install dependencies
815COPY requirements.txt ./
916RUN pip install --no-cache-dir -r requirements.txt
1017
11- # Copy the rest of the code
18+ # Copy the rest of the code (including .env file)
1219COPY . .
1320
14- # Expose the backend port
15- EXPOSE 8000
21+ # Set up PostgreSQL with credentials from .env file
22+ USER postgres
23+ RUN /etc/init.d/postgresql start && \
24+ psql --command "CREATE USER postgres WITH SUPERUSER PASSWORD 'postgres';" && \
25+ createdb -O postgres appdb
26+
27+ # Switch back to root user
28+ USER root
29+
30+ # Create a startup script that loads environment variables
31+ RUN echo '#!/bin/bash\n \
32+ # Load environment variables from .env file\n \
33+ if [ -f .env ]; then\n \
34+ export $(cat .env | grep -v "^#" | xargs)\n \
35+ fi\n \
36+ # Update DB_HOST to localhost since PostgreSQL runs in same container\n \
37+ export DB_HOST=localhost\n \
38+ service postgresql start\n \
39+ exec "$@"' > /entrypoint.sh && \
40+ chmod +x /entrypoint.sh
41+
42+ # Expose the backend port and PostgreSQL port
43+ EXPOSE 8000 5432
1644
1745# Start the backend server (adjust if using something other than uvicorn)
46+ ENTRYPOINT ["/entrypoint.sh" ]
1847CMD ["python" , "main.py" ]
You can’t perform that action at this time.
0 commit comments