Prepare docker tests for AZP. (#1482)

Backport of important parts of https://github.com/ansible-collections/community.docker/pull/48 to stable-1.
This commit is contained in:
Felix Fontein 2020-12-15 21:04:09 +01:00 committed by GitHub
commit a16164cb72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 144 additions and 9 deletions

View file

@ -11,10 +11,18 @@
name: '{{ docker_registry_container_name_frontend }}'
image: "{{ docker_test_image_registry_nginx }}"
ports: 5000
# `links` does not work when using a network. That's why the docker_container task
# in setup.yml specifies `aliases` so we get the same effect.
links:
- '{{ docker_registry_container_name_registry }}:real-registry'
volumes:
- '{{ docker_registry_container_name_frontend }}:/etc/nginx/'
network_mode: '{{ current_container_network_ip | default(omit, true) }}'
networks: >-
{{
[dict([['name', current_container_network_ip]])]
if current_container_network_ip not in ['', 'bridge'] else omit
}}
register: nginx_container
- name: Copy static files into volume
@ -65,9 +73,17 @@
debug:
var: nginx_container.container.NetworkSettings
- name: Get registry URL
set_fact:
# Note that this host/port combination is used by the Docker daemon, that's why `localhost` is appropriate!
# This host/port combination cannot be used if the tests are running inside a docker container.
docker_registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
# The following host/port combination can be used from inside the docker container.
docker_registry_frontend_address_internal: "{{ nginx_container.container.NetworkSettings.Networks[current_container_network_ip].IPAddress if current_container_network_ip else nginx_container.container.NetworkSettings.IPAddress }}:5000"
- name: Wait for registry frontend
uri:
url: https://{{ nginx_container.container.NetworkSettings.IPAddress }}:5000/v2/
url: https://{{ docker_registry_frontend_address_internal }}/v2/
url_username: testuser
url_password: hunter2
validate_certs: false
@ -76,10 +92,6 @@
retries: 5
delay: 1
- name: Get registry URL
set_fact:
docker_registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
- set_fact:
docker_registry_frontend_address: 'n/a'
when: can_copy_files is failed

View file

@ -44,6 +44,15 @@
name: '{{ docker_registry_container_name_registry }}'
image: "{{ docker_test_image_registry }}"
ports: 5000
network_mode: '{{ current_container_network_ip | default(omit, true) }}'
# We need to define the alias `real-registry` here because the global `links`
# option for the NGINX containers (see setup-frontend.yml) does not work when
# using networks.
networks: >-
{{
[dict([['name', current_container_network_ip], ['aliases', ['real-registry']]])]
if current_container_network_ip not in ['', 'bridge'] else omit
}}
register: registry_container
- name: Get registry URL