Debian Codegraph @

ansible_collections/community/docker/tests/integration/targets/setup_docker_registry/tasks/setup-frontend.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 # Set up first nginx frontend for registry
7 - name: Start nginx frontend for registry
8 community.docker.docker_volume:
9 name: '{{ docker_registry_container_name_frontend }}'
10 state: present
11
12 - name: Create container for nginx frontend for registry
13 community.docker.docker_container:
14 state: stopped
15 name: '{{ docker_registry_container_name_frontend }}'
16 image: "{{ docker_test_image_registry_nginx }}"
17 ports: 5000
18 # `links` does not work when using a network. That's why the docker_container task
19 # in setup.yml specifies `aliases` so we get the same effect.
20 links:
21 - '{{ docker_registry_container_name_registry }}:real-registry'
22 volumes:
23 - '{{ docker_registry_container_name_frontend }}:/etc/nginx/'
24 network_mode: '{{ current_container_network_ip | default(omit, true) }}'
25 networks: >-
26 {{
27 [dict([['name', current_container_network_ip]])]
28 if current_container_network_ip not in ['', 'bridge'] else omit
29 }}
30 register: nginx_container
31
32 - name: Copy config files
33 ansible.builtin.copy:
34 src: "{{ item }}"
35 dest: "{{ remote_tmp_dir }}/{{ item }}"
36 mode: "0644"
37 loop:
38 - nginx.conf
39 - nginx.htpasswd
40
41 - name: Copy static files into volume
42 community.docker.docker_container_copy_into:
43 container: '{{ docker_registry_container_name_frontend }}'
44 path: '{{ remote_tmp_dir }}/{{ item }}'
45 container_path: '/etc/nginx/{{ item }}'
46 owner_id: 0
47 group_id: 0
48 loop:
49 - nginx.conf
50 - nginx.htpasswd
51 register: can_copy_files
52 ignore_errors: true
53
54 - when: can_copy_files is not failed
55 block:
56
57 - name: Create private key for frontend certificate
58 community.crypto.openssl_privatekey:
59 path: '{{ remote_tmp_dir }}/cert.key'
60 type: ECC
61 curve: secp256r1
62 force: true
63
64 - name: Create CSR for frontend certificate
65 community.crypto.openssl_csr:
66 path: '{{ remote_tmp_dir }}/cert.csr'
67 privatekey_path: '{{ remote_tmp_dir }}/cert.key'
68 subject_alt_name:
69 - DNS:test-registry.ansible.com
70
71 - name: Create frontend certificate
72 community.crypto.x509_certificate:
73 path: '{{ remote_tmp_dir }}/cert.pem'
74 csr_path: '{{ remote_tmp_dir }}/cert.csr'
75 privatekey_path: '{{ remote_tmp_dir }}/cert.key'
76 provider: selfsigned
77
78 - name: Copy dynamic files into volume
79 community.docker.docker_container_copy_into:
80 container: '{{ docker_registry_container_name_frontend }}'
81 path: '{{ remote_tmp_dir }}/{{ item }}'
82 container_path: '/etc/nginx/{{ item }}'
83 owner_id: 0
84 group_id: 0
85 loop:
86 - cert.pem
87 - cert.key
88
89 - name: Start nginx frontend for registry
90 community.docker.docker_container:
91 name: '{{ docker_registry_container_name_frontend }}'
92 state: started
93 register: nginx_container
94
95 - name: Output nginx container network settings
96 ansible.builtin.debug:
97 var: nginx_container.container.NetworkSettings
98
99 - name: Get registry URL
100 ansible.builtin.set_fact:
101 # Note that this host/port combination is used by the Docker daemon, that's why `localhost` is appropriate!
102 # This host/port combination cannot be used if the tests are running inside a docker container.
103 docker_registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
104 # The following host/port combination can be used from inside the docker container.
105 docker_registry_frontend_address_internal: >-
106 {{
107 nginx_container.container.NetworkSettings.Networks[current_container_network_ip].IPAddress
108 if current_container_network_ip else
109 (
110 nginx_container.container.NetworkSettings.IPAddress
111 | default(nginx_container.container.NetworkSettings.Networks['bridge'].IPAddress)
112 )
113 }}:5000
114 # Since Docker 29, nginx_container.container.NetworkSettings.IPAddress no longer exists.
115 # Use the bridge network's IP address instead...
116
117 - name: Wait for registry frontend
118 ansible.builtin.uri:
119 url: https://{{ docker_registry_frontend_address_internal }}/v2/
120 url_username: testuser
121 url_password: hunter2
122 validate_certs: false
123 register: result
124 until: result is success
125 retries: 5
126 delay: 1
127
128 - ansible.builtin.set_fact:
129 docker_registry_frontend_address: 'n/a'
130 when: can_copy_files is failed