Merge pull request #1498 from MaxJa4/improvement/retry_migrations
Moved DB-waiting from docker-level to container-level
This commit is contained in:
commit
f1bbe16606
27
boot.sh
27
boot.sh
@ -1,10 +1,33 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
|
|
||||||
echo "Updating database"
|
echo "Migrating database"
|
||||||
python manage.py migrate
|
|
||||||
|
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
|
||||||
|
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."
|
||||||
|
exit 1 # exit with error to make the container stop
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Generating static files"
|
||||||
|
|
||||||
python manage.py collectstatic_js_reverse
|
python manage.py collectstatic_js_reverse
|
||||||
python manage.py collectstatic --noinput
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|
||||||
chmod -R 755 /opt/recipes/mediafiles
|
chmod -R 755 /opt/recipes/mediafiles
|
||||||
|
@ -9,15 +9,9 @@ services:
|
|||||||
- ./.env
|
- ./.env
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "psql -U $$POSTGRES_USER -d $$POSTGRES_DB --list || exit 1"]
|
|
||||||
interval: 4s
|
|
||||||
timeout: 1s
|
|
||||||
retries: 12
|
|
||||||
|
|
||||||
web_recipes:
|
web_recipes:
|
||||||
image: vabene1111/recipes
|
image: vabene1111/recipes
|
||||||
restart: always
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./.env
|
- ./.env
|
||||||
volumes:
|
volumes:
|
||||||
@ -25,8 +19,7 @@ services:
|
|||||||
- nginx_config:/opt/recipes/nginx/conf.d
|
- nginx_config:/opt/recipes/nginx/conf.d
|
||||||
- ./mediafiles:/opt/recipes/mediafiles
|
- ./mediafiles:/opt/recipes/mediafiles
|
||||||
depends_on:
|
depends_on:
|
||||||
db_recipes:
|
- db_recipes
|
||||||
condition: service_healthy
|
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
|
|
||||||
|
@ -7,15 +7,9 @@ services:
|
|||||||
- ./postgresql:/var/lib/postgresql/data
|
- ./postgresql:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
- ./.env
|
- ./.env
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "psql -U $$POSTGRES_USER -d $$POSTGRES_DB --list || exit 1"]
|
|
||||||
interval: 4s
|
|
||||||
timeout: 1s
|
|
||||||
retries: 12
|
|
||||||
|
|
||||||
web_recipes:
|
web_recipes:
|
||||||
image: vabene1111/recipes
|
image: vabene1111/recipes
|
||||||
restart: always
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./.env
|
- ./.env
|
||||||
volumes:
|
volumes:
|
||||||
@ -23,8 +17,7 @@ services:
|
|||||||
- nginx_config:/opt/recipes/nginx/conf.d
|
- nginx_config:/opt/recipes/nginx/conf.d
|
||||||
- ./mediafiles:/opt/recipes/mediafiles
|
- ./mediafiles:/opt/recipes/mediafiles
|
||||||
depends_on:
|
depends_on:
|
||||||
db_recipes:
|
- db_recipes
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
nginx_recipes:
|
nginx_recipes:
|
||||||
image: nginx:mainline-alpine
|
image: nginx:mainline-alpine
|
||||||
|
@ -9,15 +9,9 @@ services:
|
|||||||
- ./.env
|
- ./.env
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "psql -U $$POSTGRES_USER -d $$POSTGRES_DB --list || exit 1"]
|
|
||||||
interval: 4s
|
|
||||||
timeout: 1s
|
|
||||||
retries: 12
|
|
||||||
|
|
||||||
web_recipes:
|
web_recipes:
|
||||||
image: vabene1111/recipes
|
image: vabene1111/recipes
|
||||||
restart: always
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./.env
|
- ./.env
|
||||||
volumes:
|
volumes:
|
||||||
@ -25,8 +19,7 @@ services:
|
|||||||
- nginx_config:/opt/recipes/nginx/conf.d
|
- nginx_config:/opt/recipes/nginx/conf.d
|
||||||
- ./mediafiles:/opt/recipes/mediafiles
|
- ./mediafiles:/opt/recipes/mediafiles
|
||||||
depends_on:
|
depends_on:
|
||||||
db_recipes:
|
- db_recipes
|
||||||
condition: service_healthy
|
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user