wait-for-postgres.sh

parent fbb2d9f1
...@@ -2,13 +2,23 @@ FROM python:3.10-slim ...@@ -2,13 +2,23 @@ FROM python:3.10-slim
WORKDIR /app WORKDIR /app
# Install postgresql-client for pg_isready
RUN apt-get update && apt-get install -y \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies # Install Python dependencies
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy the startup script and your application code
COPY . . COPY . .
#just keep the container running without doing anything
#CMD ["sh", "-c", "while :; do sleep 10; done"]
#run the app automatically when the container starts # Make the script executable
CMD ["python", "main.py"] RUN chmod +x wait-for-postgres.sh
# Use the script as the entrypoint
ENTRYPOINT ["/app/wait-for-postgres.sh"]
# This is your application's original startup command
CMD ["python", "main.py"]
\ No newline at end of file
#!/bin/bash
# wait-for-postgres.sh
set -e
host="postgres"
port="5432"
dbname="${POSTGRES_DB}"
user="${POSTGRES_USER}"
password="${POSTGRES_PASSWORD}"
echo "Waiting for PostgreSQL..."
until PGPASSWORD=$password pg_isready -h $host -p $port -U $user; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
echo "PostgreSQL is up - executing command"
exec "$@"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment