--- # Copyright Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - name: Ensure directories are present ansible.builtin.file: path: "{{ cifmw_build_containers_basedir }}/{{ item }}" state: directory mode: "0755" loop: - tmp - artifacts - logs - name: Install tcib ansible.builtin.import_tasks: install.yml - name: Generate build_containers.sh script ansible.builtin.template: src: templates/build_containers.sh.j2 dest: "{{ cifmw_build_containers_basedir }}/artifacts/build_containers.sh" mode: "0777" force: true - name: Run build_containers.sh script when: not cifmw_build_containers_run_hotfix | bool become: true environment: PATH: /usr/local/bin:{{ ansible_env.PATH }} args: chdir: "{{ cifmw_build_containers_basedir }}/artifacts" ansible.builtin.shell: | set -o pipefail && bash build_containers.sh 2>&1 {{ cifmw_build_containers_timestamper_cmd }} > {{ cifmw_build_containers_basedir }}/logs/build.log - name: Include tasks from hotfix.yml when: cifmw_build_containers_run_hotfix | bool ansible.builtin.import_tasks: hotfix.yml - name: Make sure authfile exists when: - cifmw_build_containers_authfile_path != None - cifmw_build_containers_push_containers | bool block: - name: Check for authfile ansible.builtin.stat: path: '{{ cifmw_build_containers_authfile_path }}' register: authfile_exist - name: Make sure authfile exists ansible.builtin.assert: that: - authfile_exist.stat.exists | bool - name: Retrieve built images # noqa risky-shell-pipe ansible.builtin.shell: cmd: >- podman images | grep {{ cifmw_build_containers_container_name_prefix }} | awk '{ print $1 }' register: built_images become: true changed_when: false - name: Store built images to containers-built.log # noqa risky-shell-pipe become: true ansible.builtin.shell: cmd: >- podman images | grep {{ cifmw_build_containers_container_name_prefix }} > {{ cifmw_build_containers_basedir }}/logs/containers-built.log - name: "Push image: {{ item }}" become: true ansible.builtin.command: > buildah push {{ item }}:{{ cifmw_build_containers_image_tag }} loop: "{{ built_images.stdout_lines }}" when: - cifmw_build_containers_buildah_push | default (false) | bool - not cifmw_build_containers_push_containers | bool - name: "Retag each image and push to registry: {{ item }}" become: true ansible.builtin.command: > buildah push --format v2s2 --all {{ item }}:{{ cifmw_build_containers_image_tag }} docker://{{ item }}:{{ cifmw_build_containers_retag_string }} loop: "{{ built_images.stdout_lines }}" when: - cifmw_build_containers_retag_images | default(false) | bool - cifmw_build_containers_tag_string != cifmw_build_containers_retag_string - name: Cleanup tcib directories after container build ansible.builtin.import_tasks: cleanup.yml when: cifmw_build_containers_cleanup | bool