Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
build.yml 2.36 KiB
Newer Older
- 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

Vehbo DZOGOVIC's avatar
Vehbo DZOGOVIC committed
    - name: Get source image
      ansible.builtin.set_fact:
Vehbo DZOGOVIC's avatar
Vehbo DZOGOVIC committed
        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

Vehbo DZOGOVIC's avatar
Vehbo DZOGOVIC committed
    - 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') }}"