Ping DB instead of trying migration
This commit is contained in:
parent
f1bbe16606
commit
a35aa953b4
@ -15,7 +15,7 @@ WORKDIR /opt/recipes
|
||||
|
||||
COPY requirements.txt ./
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev libwebp-dev libressl-dev libffi-dev cargo openssl-dev openldap-dev && \
|
||||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev postgresql zlib-dev jpeg-dev libwebp-dev libressl-dev libffi-dev cargo openssl-dev openldap-dev && \
|
||||
python -m venv venv && \
|
||||
/opt/recipes/venv/bin/python -m pip install --upgrade pip && \
|
||||
venv/bin/pip install wheel==0.36.2 && \
|
||||
|
28
boot.sh
28
boot.sh
@ -1,28 +1,28 @@
|
||||
#!/bin/sh
|
||||
source venv/bin/activate
|
||||
|
||||
echo "Migrating database"
|
||||
echo "Waiting for database to be ready..."
|
||||
|
||||
attempt=0
|
||||
max_attempts=20
|
||||
while python manage.py migrate; \
|
||||
status=$?; \
|
||||
attempt=$((attempt+1)); \
|
||||
[ $status -eq 1 ] \
|
||||
&& [ $attempt -le $max_attempts ]; do
|
||||
echo -e "\n!!! Migration failed (error ${status}, attempt ${attempt}/${max_attempts})."
|
||||
echo "!!! Database may not be ready yet or system is misconfigured."
|
||||
echo -e "!!! Retrying in 5 seconds...\n"
|
||||
sleep 5
|
||||
while pg_isready --host=${POSTGRES_HOST} -q; status=$?; attempt=$((attempt+1)); [ $status -ne 0 ] && [ $attempt -le $max_attempts ]; do
|
||||
sleep 5 # no echo needed, response comes from pg_isready already
|
||||
done
|
||||
|
||||
if [ $attempt -gt $max_attempts ]; then
|
||||
echo -e "\n!!! Migration failed. Maximum attempts exceeded."
|
||||
echo "!!! Please check logs above - misconfiguration is very likely."
|
||||
echo "!!! Shutting down container."
|
||||
echo -e "\nDatabase not reachable. Maximum attempts exceeded."
|
||||
echo "Please check logs above - misconfiguration is very likely."
|
||||
echo "Make sure the DB container is up and POSTGRES_HOST is set properly."
|
||||
echo "Shutting down container."
|
||||
exit 1 # exit with error to make the container stop
|
||||
fi
|
||||
|
||||
echo "Database is ready"
|
||||
|
||||
echo "Migrating database"
|
||||
|
||||
python manage.py migrate
|
||||
|
||||
echo "Generating static files"
|
||||
|
||||
python manage.py collectstatic_js_reverse
|
||||
@ -32,4 +32,4 @@ echo "Done"
|
||||
|
||||
chmod -R 755 /opt/recipes/mediafiles
|
||||
|
||||
exec gunicorn -b :8080 --access-logfile - --error-logfile - --log-level INFO recipes.wsgi
|
||||
exec gunicorn -b :8080 --access-logfile - --error-logfile - --log-level INFO recipes.wsgi
|
Loading…
Reference in New Issue
Block a user