|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +- name: Ensure directories are present |
| 18 | + ansible.builtin.file: |
| 19 | + path: "{{ cifmw_build_containers_basedir }}/{{ item }}" |
| 20 | + state: directory |
| 21 | + mode: "0755" |
| 22 | + loop: |
| 23 | + - tmp |
| 24 | + - artifacts |
| 25 | + - logs |
| 26 | + |
| 27 | +- name: Make sure authfile exists |
| 28 | + when: |
| 29 | + - cifmw_build_containers_authfile_path != None |
| 30 | + - cifmw_build_containers_push_containers | bool |
| 31 | + block: |
| 32 | + - name: Check for authfile |
| 33 | + ansible.builtin.stat: |
| 34 | + path: '{{ cifmw_build_containers_authfile_path }}' |
| 35 | + register: authfile_exist |
| 36 | + |
| 37 | + - name: Make sure authfile exists |
| 38 | + ansible.builtin.assert: |
| 39 | + that: |
| 40 | + - authfile_exist.stat.exists | bool |
| 41 | + |
| 42 | +- name: Retrieve the log file from container build job |
| 43 | + ansible.builtin.get_url: |
| 44 | + url: "{{ containers_built_artifacts_url }}/ci-framework-data/logs/containers-built.log" |
| 45 | + dest: "{{ cifmw_build_containers_basedir }}/logs/containers-built.log" |
| 46 | + mode: "0644" |
| 47 | + force: true |
| 48 | + register: result |
| 49 | + until: |
| 50 | + - result.status_code is defined |
| 51 | + - result.status_code == 200 |
| 52 | + retries: 6 |
| 53 | + delay: 50 |
| 54 | + |
| 55 | +- name: Get built_images from the log file |
| 56 | + ansible.builtin.shell: |
| 57 | + cmd: >- |
| 58 | + set -o pipefail; |
| 59 | + cat {{ cifmw_build_containers_basedir }}/logs/containers-built.log | |
| 60 | + grep {{ cifmw_build_containers_container_name_prefix }} | |
| 61 | + awk '{ print $1 }' |
| 62 | + register: built_images_from_file |
| 63 | + |
| 64 | +- name: Get the hash tag from the log file |
| 65 | + ansible.builtin.shell: |
| 66 | + cmd: >- |
| 67 | + set -o pipefail; |
| 68 | + cat {{ cifmw_build_containers_basedir }}/logs/containers-built.log | |
| 69 | + grep {{ cifmw_build_containers_container_name_prefix }} | |
| 70 | + awk '{ print $2 }' | head -n 1 |
| 71 | + register: images_tag_from_file |
| 72 | + |
| 73 | +- name: Set variables for looping |
| 74 | + ansible.builtin.set_fact: |
| 75 | + built_images: "{{ built_images_from_file.stdout_lines }}" |
| 76 | + images_tag: "{{ images_tag_from_file.stdout_lines[0] }}" |
| 77 | + |
| 78 | +- name: Pull images returned in built_images |
| 79 | + containers.podman.podman_image: |
| 80 | + name: "{{ item }}" |
| 81 | + tag: "{{ images_tag }}" |
| 82 | + loop: "{{ built_images }}" |
| 83 | + |
| 84 | +- name: Retag the images with new tag |
| 85 | + containers.podman.podman_tag: |
| 86 | + image: "{{ item }}:{{ images_tag }}" |
| 87 | + target_names: |
| 88 | + - "{{ item }}:{{ cifmw_build_containers_tag_string }}" |
| 89 | + loop: "{{ built_images }}" |
| 90 | + |
| 91 | +- name: Push images to registry with new tag |
| 92 | + containers.podman.podman_image: |
| 93 | + name: "{{ item }}" |
| 94 | + push_args: |
| 95 | + dest: "{{ cifmw_build_containers_push_registry }}/{{ cifmw_build_containers_registry_namespace }}" |
| 96 | + tag: "{{ cifmw_build_containers_tag_string }}" |
| 97 | + pull: false |
| 98 | + push: true |
| 99 | + loop: "{{ built_images }}" |
0 commit comments