- name: Build testing image hosts: localhost tasks: - name: Log into private registry community.docker.docker_login: registry: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY') }}" username: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_USER') }}" password: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_PASSWORD') }}" reauthorize: true - name: Remove image community.docker.docker_image: state: absent name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}" force_absent: true - name: Building image community.docker.docker_image: build: pull: true path: ../ args: http_proxy: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}" https_proxy: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}" name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}" repository: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}" push: true force_source: true force_tag: true source: build - name: Get source image ansible.builtin.set_fact: source_image: "{{ lookup('ansible.builtin.file', '../Dockerfile') | regex_search('FROM (.*):(.*)') | regex_replace('^FROM\\s(.*)$', '\\1') }}" - name: Remove local image community.docker.docker_image: state: absent name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}" force_absent: true - name: Remove local image community.docker.docker_image: state: absent name: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}" force_absent: true - name: Remove source image community.docker.docker_image: state: absent name: "{{ source_image }}" force_absent: true - name: Log out of registry community.docker.docker_login: state: absent - name: Debug ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.env', 'CI_REGISTRY_IMAGE') }}:{{ lookup('ansible.builtin.env', 'CI_COMMIT_SHORT_SHA') }}"