---

# Build docker image -------------------------------------------------------------
# -- Target: The first node only.
# -- Objective: Build a docker image for Redis-HA.

- block:
  - name: create build dir if not exists
    file:
      path: "{{ build_root_abspath }}"
      state: directory
      owner: root
      group: root
      mode: '0755'

  - name: git clone
    git:
      repo: "https://pvggitea.duckdns.org/GiteaTeam/demolamp.git"
      dest: "{{ build_root_abspath }}"
      remote: "origin"
      version: "main"
    
  - name: Remove the docker image for demolamp if exists
    community.docker.docker_image:
      name: {{demolamp.imageName}}
      tag: "{{ ansTagVer }}"
      state: absent
 
  - name: Docker login to ECV private repository if not pull from local registry
    community.docker.docker_login:
      registry: "{{ imagePushDomain }}"
      username: "{{ registryUser }}"
      password: "{{ registryPass }}"
      state: present
    when: not localRegistry | bool

  - name: Build demolamp image
    community.docker.docker_image:
      name: {{demolamp.imageName}}
      source: build
      tag: "{{ ansTagVer }}"
      build:
        path: "{{ build_root_abspath }}"
        pull: false
      push: yes
      repository: "{{ demolamp.pushRepoName }}:{{ ansTagVer }}"
      force_tag: yes
      timeout: 300
      state: present

