-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨(docker) fix first bootstrap can't connect to DB
Fix error `dockerflow.health.E001` with the message of `Could not connect to database`. This only occurs from a fresh installation or on the first boot of the database. Probably this only occurs when the dev machine has a slower IO. Split docker compose file, per supported database and add a dependency of the app to db, if it's healthy, directly on docker compose level. Also fixes running tests on mysql locally. fixes #2455
- Loading branch information
Showing
5 changed files
with
45 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ endif | |
DOCKER_UID = $(shell id -u) | ||
DOCKER_GID = $(shell id -g) | ||
DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID) | ||
COMPOSE = DOCKER_USER=$(DOCKER_USER) DB_HOST=$(DB_HOST) DB_PORT=$(DB_PORT) docker compose | ||
COMPOSE = DOCKER_USER=$(DOCKER_USER) DB_HOST=$(DB_HOST) DB_PORT=$(DB_PORT) docker compose -f docker-compose.yml -f docker-compose-$(DB_HOST).yml | ||
COMPOSE_SSL = NGINX_CONF=ssl DEV_ENV_FILE=dev-ssl $(COMPOSE) | ||
COMPOSE_RUN = $(COMPOSE) run --rm | ||
COMPOSE_RUN_SSL = $(COMPOSE_SSL) run --rm | ||
|
@@ -263,7 +263,7 @@ search-index: ## (re)generate the Elasticsearch index | |
.PHONY: search-index | ||
|
||
superuser: ## Create an admin user with password "admin" | ||
@$(COMPOSE) up -d mysql | ||
@$(COMPOSE) up -d ${DB_HOST} | ||
@echo "Wait for services to be up..." | ||
@$(WAIT_DB) | ||
@$(MANAGE) shell -c "from django.contrib.auth.models import User; not User.objects.filter(username='admin').exists() and User.objects.create_superuser('admin', '[email protected]', 'admin')" | ||
|
@@ -326,7 +326,7 @@ i18n-generate-front: build-ts | |
# -- Database | ||
|
||
dbshell: ## connect to database shell | ||
docker compose exec app python sandbox/manage.py dbshell | ||
@$(COMPOSE) exec app python sandbox/manage.py dbshell | ||
.PHONY: dbshell | ||
|
||
# -- Misc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env_file: | ||
- env.d/development/mysql | ||
command: --default-authentication-plugin=mysql_native_password | ||
healthcheck: | ||
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] | ||
interval: 1s | ||
timeout: 2s | ||
retries: 300 | ||
|
||
app: | ||
depends_on: | ||
mysql: | ||
condition: service_healthy | ||
restart: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: | ||
postgresql: | ||
image: postgres:12 | ||
ports: | ||
- "5472:5432" | ||
env_file: | ||
- env.d/development/postgresql | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready"] | ||
interval: 1s | ||
timeout: 2s | ||
retries: 300 | ||
|
||
app: | ||
depends_on: | ||
postgresql: | ||
condition: service_healthy | ||
restart: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters