From 1ad0a61524a36faf7ac6e94042d3a4853ba4cdbf Mon Sep 17 00:00:00 2001 From: Gernot Schulz Date: Wed, 24 Feb 2021 15:42:33 +0100 Subject: [PATCH] Docker: Simplify image name/registry handling For a subset of the images required by a Compose or Swarm Setup, non-default names can be configured in .env. Originally, the names were treated as the images' complete names, i.e., including an optional registry domain. Using this setup, it was possible to pull the irregularly updated auxiliary images from a default registry while, at the same time, obtaining certain images from different registries. Commit e225a57f97 changed this behavior. Since then, the names in .env can only be used to change part of the image name, excluding the registry. If a default registry is configured it is always prepended to the given image name, breaking the original use case. This patch removes the ability to override image names in .env. Instead, the registry of each image can be customized. The reasoning here is that the only common reason to change an image name is to change its Docker registry. For example, while the default registry may be set to default.example.com, it may be necessary to obtain the backend image private.example.com/openslides-server. With this patch, that would be achieved by the following configuration in .env: DOCKER_OPENSLIDES_BACKEND_REGISTRY="private.example.com" For special cases, for which the images' basename must indeed be changed as well, the template would need to be customized. The templates are not backwards-compatible. --- docker/.env | 8 ++++---- docker/docker-compose.yml.m4 | 31 +++++++++++++++++-------------- docker/docker-stack.yml.m4 | 31 +++++++++++++++++-------------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/docker/.env b/docker/.env index 9f7713257..593750db2 100644 --- a/docker/.env +++ b/docker/.env @@ -17,13 +17,13 @@ DEFAULT_DOCKER_REGISTRY= # Docker Images # ------------- -DOCKER_OPENSLIDES_PROXY_NAME= +DOCKER_OPENSLIDES_PROXY_REGISTRY= DOCKER_OPENSLIDES_PROXY_TAG= -DOCKER_OPENSLIDES_BACKEND_NAME= +DOCKER_OPENSLIDES_BACKEND_REGISTRY= DOCKER_OPENSLIDES_BACKEND_TAG= -DOCKER_OPENSLIDES_FRONTEND_NAME= +DOCKER_OPENSLIDES_FRONTEND_REGISTRY= DOCKER_OPENSLIDES_FRONTEND_TAG= -DOCKER_OPENSLIDES_AUTOUPDATE_NAME= +DOCKER_OPENSLIDES_AUTOUPDATE_REGISTRY= DOCKER_OPENSLIDES_AUTOUPDATE_TAG= # Database diff --git a/docker/docker-compose.yml.m4 b/docker/docker-compose.yml.m4 index 023989d60..a6dddd031 100644 --- a/docker/docker-compose.yml.m4 +++ b/docker/docker-compose.yml.m4 @@ -13,22 +13,25 @@ define(`read_env', `esyscmd(`printf "\`%s'" "$$1"')') dnl return env variable if set; otherwise, return given alternative value define(`ifenvelse', `ifelse(read_env(`$1'),, `$2', read_env(`$1'))') -define(`PROXY_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_PROXY_NAME', openslides-proxy):dnl -ifenvelse(`DOCKER_OPENSLIDES_PROXY_TAG', latest)) +define(`DEFAULT_DOCKER_REGISTRY', ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)) + +dnl Parse image versions that can be configured through .env define(`BACKEND_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_BACKEND_NAME', openslides-server):dnl +ifenvelse(`DOCKER_OPENSLIDES_BACKEND_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-server:dnl ifenvelse(`DOCKER_OPENSLIDES_BACKEND_TAG', latest)) define(`FRONTEND_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_NAME', openslides-client):dnl +ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-client:dnl ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_TAG', latest)) define(`AUTOUPDATE_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_NAME', openslides-autoupdate):dnl +ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-autoupdate:dnl ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_TAG', latest)) +define(`PROXY_IMAGE', +ifenvelse(`DOCKER_OPENSLIDES_PROXY_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-proxy:dnl +ifenvelse(`DOCKER_OPENSLIDES_PROXY_TAG', latest)) define(`PRIMARY_DB', `ifenvelse(`PGNODE_REPMGR_PRIMARY', pgnode1)') @@ -84,7 +87,7 @@ x-osserver-env: &default-osserver-env REDIS_SLAVE_PORT: ifenvelse(`REDIS_SLAVE_PORT', 6379) RESET_PASSWORD_VERBOSE_ERRORS: "ifenvelse(`RESET_PASSWORD_VERBOSE_ERRORS', False)" x-pgnode: &default-pgnode - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-repmgr:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-repmgr:latest networks: - dbnet labels: @@ -190,7 +193,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' pgbouncer: environment: - PG_NODE_LIST=pgnode1`'PGBOUNCER_NODELIST - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-pgbouncer:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-pgbouncer:latest restart: always networks: back: @@ -199,7 +202,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' - postgres dbnet: postfix: - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-postfix:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-postfix:latest restart: always environment: MYHOSTNAME: "ifenvelse(`POSTFIX_MYHOSTNAME', localhost)" @@ -222,7 +225,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' ifelse(read_env(`REDIS_RO_SERVICE_REPLICAS'),,,deploy: replicas: ifenvelse(`REDIS_RO_SERVICE_REPLICAS', 1)) media: - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-media:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-media:latest environment: - CHECK_REQUEST_URL=server:8000/check-media/ - CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10) diff --git a/docker/docker-stack.yml.m4 b/docker/docker-stack.yml.m4 index 2193cb876..1b5f5377c 100644 --- a/docker/docker-stack.yml.m4 +++ b/docker/docker-stack.yml.m4 @@ -13,22 +13,25 @@ define(`read_env', `esyscmd(`printf "\`%s'" "$$1"')') dnl return env variable if set; otherwise, return given alternative value define(`ifenvelse', `ifelse(read_env(`$1'),, `$2', read_env(`$1'))') -define(`PROXY_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_PROXY_NAME', openslides-proxy):dnl -ifenvelse(`DOCKER_OPENSLIDES_PROXY_TAG', latest)) +define(`DEFAULT_DOCKER_REGISTRY', ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)) + +dnl Parse image versions that can be configured through .env define(`BACKEND_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_BACKEND_NAME', openslides-server):dnl +ifenvelse(`DOCKER_OPENSLIDES_BACKEND_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-server:dnl ifenvelse(`DOCKER_OPENSLIDES_BACKEND_TAG', latest)) define(`FRONTEND_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_NAME', openslides-client):dnl +ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-client:dnl ifenvelse(`DOCKER_OPENSLIDES_FRONTEND_TAG', latest)) define(`AUTOUPDATE_IMAGE', -ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/dnl -ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_NAME', openslides-autoupdate):dnl +ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-autoupdate:dnl ifenvelse(`DOCKER_OPENSLIDES_AUTOUPDATE_TAG', latest)) +define(`PROXY_IMAGE', +ifenvelse(`DOCKER_OPENSLIDES_PROXY_REGISTRY', DEFAULT_DOCKER_REGISTRY)/dnl +openslides-proxy:dnl +ifenvelse(`DOCKER_OPENSLIDES_PROXY_TAG', latest)) define(`PRIMARY_DB', `ifenvelse(`PGNODE_REPMGR_PRIMARY', pgnode1)') @@ -83,7 +86,7 @@ x-osserver-env: &default-osserver-env REDIS_SLAVE_PORT: ifenvelse(`REDIS_SLAVE_PORT', 6379) RESET_PASSWORD_VERBOSE_ERRORS: "ifenvelse(`RESET_PASSWORD_VERBOSE_ERRORS', False)" x-pgnode: &default-pgnode - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-repmgr:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-repmgr:latest networks: - dbnet labels: @@ -200,7 +203,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' pgbouncer: environment: - PG_NODE_LIST=pgnode1`'PGBOUNCER_NODELIST - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-pgbouncer:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-pgbouncer:latest networks: back: aliases: @@ -214,7 +217,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' placement: constraints: ifenvelse(`PGBOUNCER_PLACEMENT_CONSTR', [node.role == manager]) postfix: - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-postfix:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-postfix:latest environment: MYHOSTNAME: "ifenvelse(`POSTFIX_MYHOSTNAME', localhost)" RELAYHOST: "ifenvelse(`POSTFIX_RELAYHOST', localhost)" @@ -247,7 +250,7 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `' condition: on-failure delay: 5s media: - image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-media:latest + image: DEFAULT_DOCKER_REGISTRY/openslides-media:latest environment: - CHECK_REQUEST_URL=server:8000/check-media/ - CACHE_SIZE=ifenvelse(`CACHE_SIZE', 10)