Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 26bb421

Browse files
committed
Add retry policy to migrate-and-run script
1 parent de00182 commit 26bb421

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed

backend/settings/prod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
HUME_BROKER_USERNAME = os.environ["BROKER_USER"]
1010
HUME_BROKER_PASSWORD = os.environ["BROKER_PASS"]
1111

12-
HUME_BROKER_VHOST = int(os.environ["BROKER_VHOST"])
12+
HUME_BROKER_VHOST = os.environ["BROKER_VHOST"]
1313
HUME_BROKER_HOST = os.environ["BROKER_HOST"]
1414
HUME_BROKER_PORT = int(os.environ["BROKER_PORT"])
1515

docker/docker-compose-local.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This compose file is intended for local tests to verify any changes to the
2+
# docker images locally and manually. Useful for deploying a local test cluster
3+
# to try things out in and to check on configuration changes.
4+
version: '3.8'
5+
6+
services:
7+
8+
backend:
9+
image: local/hint-backend:latest
10+
environment:
11+
- BROKER_USER=hint
12+
- BROKER_PASS=hintpw123
13+
- BROKER_VHOST=hub
14+
- BROKER_HOST=rabbitmq
15+
- BROKER_PORT=5672
16+
- SECRET_KEY=3jk12hklöe41j2hrkl21jhrilkh12kl12rh###2klrjh12rkl12hjr1kl2jrh12klj12hrkl12hio12ury1i2fh12kdasdas
17+
- PG_USER=admin
18+
- PG_PASS=admin
19+
- PG_HOST=postgres
20+
- PG_PORT=5432
21+
- REDIS_HOST=redis
22+
- REDIS_PORT=6379
23+
- DJANGO_SETTINGS_MODULE=backend.settings.prod
24+
expose:
25+
- 32000
26+
depends_on:
27+
- rabbitmq
28+
- redis
29+
- postgres
30+
31+
ingress:
32+
image: local/hint-ingress:latest
33+
ports:
34+
- '8080:80'
35+
depends_on:
36+
- backend
37+
38+
postgres:
39+
image: postgres:15.0
40+
environment:
41+
- POSTGRES_USER=admin
42+
- POSTGRES_PASSWORD=admin
43+
- POSTGRES_DB=hint
44+
- PGDATA=/var/lib/postgresql/data/pgdata
45+
volumes:
46+
- postgres_volume:/var/lib/postgresql/data
47+
48+
redis:
49+
image: redis:7.0.5
50+
51+
rabbitmq:
52+
image: local/hint-rabbitmq:latest
53+
volumes:
54+
- rabbitmq_volume:/var/lib/rabbitmq
55+
56+
volumes:
57+
postgres_volume:
58+
rabbitmq_volume:

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ services:
5454
image: redis:7.0.5
5555

5656
rabbitmq:
57-
image: ghcr.io/open-home-iot/rabbitmq:3.11.1-management
57+
image: ghcr.io/open-home-iot/hint-rabbitmq:latest
5858
volumes:
5959
- rabbitmq_volume:/var/lib/rabbitmq
6060

scripts/build-all-for-production

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cd "$HINT_PROJECT_ROOT" || exit 1
1818
# 3. Collect static
1919
# 4. Build ingress/fileserver container image
2020
# 5. Build backend container image
21+
# 6. Build rabbitmq image
2122

2223
#
2324
# LETS GOOOOOO
@@ -34,7 +35,10 @@ rm -rf "$HINT_PROJECT_ROOT/backend/static/collectedstatic"
3435
./manage.py collectstatic
3536

3637
# 4. Build ingress/fileserver container image
37-
docker build . -f docker/ingress.Dockerfile --tag hint-ingress
38+
docker build . -f docker/ingress.Dockerfile --tag local/hint-ingress:latest
3839

3940
# 5. Build backend container image
40-
docker build . -f docker/backend.Dockerfile --tag hint-backend
41+
docker build . -f docker/backend.Dockerfile --tag local/hint-backend:latest
42+
43+
# 6. Build rabbitmq image
44+
docker build . -f docker/rabbitmq.Dockerfile --tag local/hint-rabbitmq:latest

scripts/migrate-and-run

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22
# NOTE! This scripts is ONLY meant to be run in the backend container, and
33
# won't work outside of there.
44

5-
./manage.py migrate
5+
echo "Applying database migrations"
6+
while ! ./manage.py migrate
7+
do
8+
echo "Retrying migration in 2 seconds..."
9+
sleep 2
10+
done
11+
12+
echo "Creating initial user"
613
# createinitialuser creates a single superuser instance, but only if NO OTHER
714
# users exist, so it's safe to call on subsequent deployments.
8-
./manage.py createinitialuser
15+
while ! ./manage.py createinitialuser
16+
do
17+
echo "Retrying user creation in 2 seconds..."
18+
sleep 2
19+
done
20+
21+
echo "Running daphne"
922
daphne backend.asgi:application -b 0.0.0.0 -p 32000

0 commit comments

Comments
 (0)