diff --git a/Makefile b/Makefile index 10bc1fc286..3cc14f0391 100644 --- a/Makefile +++ b/Makefile @@ -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', 'admin@example.com', '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 diff --git a/bin/_config.sh b/bin/_config.sh index 9915b314ca..56bb30e3db 100644 --- a/bin/_config.sh +++ b/bin/_config.sh @@ -7,12 +7,8 @@ UNSET_USER=0 COMPOSE_PROJECT="richie" # By default, all commands are run on Postgresql. -# They can be run on Mysql by setting an environment variable: `DB_ENGINE=mysql` -if [[ "${DB_ENGINE}" == "mysql" ]]; then - COMPOSE_FILE="${REPO_DIR}/docker/compose/development/mysql/docker-compose.yml" -else - COMPOSE_FILE="${REPO_DIR}/docker-compose.yml" -fi +# They can be run on Mysql by setting an environment variable: `DB_HOST=mysql` +COMPOSE_FILE="-f ${REPO_DIR}/docker-compose.yml -f ${REPO_DIR}/docker-compose-${DB_HOST:-postgresql}.yml" # _set_user: set (or unset) default user id used to run docker commands # @@ -47,8 +43,9 @@ function _docker_compose() { echo "🐳(compose) project: '${COMPOSE_PROJECT}' file: '${COMPOSE_FILE}'" docker compose \ -p "${COMPOSE_PROJECT}" \ - -f "${COMPOSE_FILE}" \ + ${COMPOSE_FILE} \ --project-directory "${REPO_DIR}" \ + --env-file env.d/development/${DB_HOST:-postgresql} \ "$@" } diff --git a/docker-compose-mysql.yml b/docker-compose-mysql.yml new file mode 100644 index 0000000000..b6c12973fc --- /dev/null +++ b/docker-compose-mysql.yml @@ -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 diff --git a/docker-compose-postgresql.yml b/docker-compose-postgresql.yml new file mode 100644 index 0000000000..2e1f46f8c6 --- /dev/null +++ b/docker-compose-postgresql.yml @@ -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 + diff --git a/docker-compose.yml b/docker-compose.yml index 14ec0fa48e..78d9d972bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,4 @@ services: - postgresql: - image: postgres:12 - ports: - - "5472:5432" - env_file: - - env.d/development/postgresql - - mysql: - image: mysql:8.0 - env_file: - - env.d/development/mysql - command: --default-authentication-plugin=mysql_native_password elasticsearch: image: "${ELASTICSEARCH_IMAGE:-docker.elastic.co/elasticsearch/elasticsearch:7.14.0}" @@ -39,8 +27,8 @@ services: - ./data/media:/data/media - ./data/smedia:/data/smedia depends_on: - - "${DB_HOST:-postgresql}" - - "elasticsearch" + elasticsearch: + condition: service_started stdin_open: true tty: true