From e642ba11b38437d0da204805476dfbb4df1538f2 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Thu, 31 Jan 2019 11:40:34 +0000 Subject: [PATCH] Allow to configure Docker Registry via environment variables Change-Id: Ida7b870e86894bd33e923ae1cc1142d32e052ddc Story: 2004817 Task: 28982 --- ansible/group_vars/all/docker-registry | 9 +++++++++ .../roles/docker-registry/defaults/main.yml | 10 ++++++++++ ansible/roles/docker-registry/tasks/deploy.yml | 1 + etc/kayobe/docker-registry.yml | 9 +++++++++ .../docker-registry-env-e954a0642555864f.yaml | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 releasenotes/notes/docker-registry-env-e954a0642555864f.yaml diff --git a/ansible/group_vars/all/docker-registry b/ansible/group_vars/all/docker-registry index 22e904986..5309e9543 100644 --- a/ansible/group_vars/all/docker-registry +++ b/ansible/group_vars/all/docker-registry @@ -5,6 +5,15 @@ # Whether a docker registry is enabled. docker_registry_enabled: False +# Dict of environment variables to provide to the docker registry container. +# This allows to configure the registry by overriding specific configuration +# options, as described at https://docs.docker.com/registry/configuration/ +# For example, the registry can be configured as a pull through cache to Docker +# Hub by setting REGISTRY_PROXY_REMOTEURL to "https://registry-1.docker.io". +# Note that it is not possible to push to a registry configured as a +# pull through cache. +docker_registry_env: {} + # The port on which the docker registry server should listen. # NOTE: This is set to 4000 rather than the default of 5000 to avoid clashing # with keystone. diff --git a/ansible/roles/docker-registry/defaults/main.yml b/ansible/roles/docker-registry/defaults/main.yml index 0b5097362..0a3f857c8 100644 --- a/ansible/roles/docker-registry/defaults/main.yml +++ b/ansible/roles/docker-registry/defaults/main.yml @@ -8,10 +8,20 @@ docker_registry_action: deploy # Whether a docker registry is enabled. docker_registry_enabled: true +# Dict of environment variables to provide to the docker registry container. +# This allows to configure the registry by overriding specific configuration +# options, as described at https://docs.docker.com/registry/configuration/ +# For example, the registry can be configured as a pull through cache to Docker +# Hub by setting REGISTRY_PROXY_REMOTEURL to "https://registry-1.docker.io". +# Note that it is not possible to push to a registry configured as a +# pull through cache. +docker_registry_env: {} + # Service deployment definition. docker_registry_services: docker_registry: container_name: docker_registry + env: "{{ docker_registry_env }}" enabled: "{{ docker_registry_enabled }}" image: "{{ docker_registry_image_full }}" ports: diff --git a/ansible/roles/docker-registry/tasks/deploy.yml b/ansible/roles/docker-registry/tasks/deploy.yml index 73b37b913..caec5d3c0 100644 --- a/ansible/roles/docker-registry/tasks/deploy.yml +++ b/ansible/roles/docker-registry/tasks/deploy.yml @@ -1,6 +1,7 @@ --- - name: Ensure Docker registry container is running docker_container: + env: "{{ item.value.env }}" image: "{{ item.value.image }}" name: "{{ item.value.container_name }}" ports: "{{ item.value.ports | default(omit) }}" diff --git a/etc/kayobe/docker-registry.yml b/etc/kayobe/docker-registry.yml index 0dd83c718..85308a43a 100644 --- a/etc/kayobe/docker-registry.yml +++ b/etc/kayobe/docker-registry.yml @@ -5,6 +5,15 @@ # Whether a docker registry is enabled. #docker_registry_enabled: +# Dict of environment variables to provide to the docker registry container. +# This allows to configure the registry by overriding specific configuration +# options, as described at https://docs.docker.com/registry/configuration/ +# For example, the registry can be configured as a pull through cache to Docker +# Hub by setting REGISTRY_PROXY_REMOTEURL to "https://registry-1.docker.io". +# Note that it is not possible to push to a registry configured as a +# pull through cache. +#docker_registry_env: + # The port on which the docker registry server should listen. #docker_registry_port: diff --git a/releasenotes/notes/docker-registry-env-e954a0642555864f.yaml b/releasenotes/notes/docker-registry-env-e954a0642555864f.yaml new file mode 100644 index 000000000..60be206d2 --- /dev/null +++ b/releasenotes/notes/docker-registry-env-e954a0642555864f.yaml @@ -0,0 +1,18 @@ +--- +features: + - | + Adds support for configuring the Docker Registry by providing environment + variables to its container via the ``docker_registry_env`` Ansible + variable. For example, the registry can be configured as a pull through + cache to Docker Hub using: + + .. code-block:: text + + docker_registry_env: + REGISTRY_PROXY_REMOTEURL: "https://registry-1.docker.io" + + Note that it is not possible to push to a registry configured as a + pull through cache. See `story 2004817 + `__ for details and the + `Docker documentation `__ + for the full list of configuration options.