blob: a4bc6922b4368d8c8448f054aaf2a90c9fc1b730 [file] [log] [blame]
Mohammed Naserdc087392024-04-01 20:26:02 -04001# Copyright (c) 2024 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15- name: Prepare host for Molecule tests
16 hosts: all
17 tasks:
18 - name: Disable swap
19 ansible.builtin.command: swapoff -a
20 ignore_errors: yes
21
22 # TODO(mnaser): Drop this when we can use https://github.com/vexxhost/atmosphere/pull/977
23 - name: Prefix all images for the job to point to mirror
24 ansible.builtin.shell: |
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040025 sed -i '/registry.atmosphere.dev/!s/ \(.*\): \(.*\)$/ \1: registry.atmosphere.dev\/\2/' roles/defaults/vars/main.yml
Mohammed Naserdc087392024-04-01 20:26:02 -040026 args:
27 chdir: "{{ zuul.project.src_dir }}"
Mohammed Naserf75ab072024-04-02 12:55:10 -040028
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040029 # NOTE(mnaser): This can be removed once the following merges
30 # https://review.opendev.org/c/zuul/zuul-jobs/+/915025
31 - name: Load "buildset_registry" fact
32 block:
33 - name: Check for results.json
34 stat:
35 path: "{{ zuul.executor.result_data_file }}"
36 register: result_json_stat
37 delegate_to: localhost
38 - name: Load information from zuul_return
39 no_log: true
40 set_fact:
41 buildset_registry: "{{ (lookup('file', zuul.executor.result_data_file) | from_json)['secret_data']['buildset_registry'] }}"
42 when:
43 - buildset_registry is not defined
44 - result_json_stat.stat.exists
45 - result_json_stat.stat.size > 0
46 - "'buildset_registry' in (lookup('file', zuul.executor.result_data_file) | from_json).get('secret_data')"
47
48 - name: Configure buildset registry
49 when: buildset_registry is defined
50 block:
51 - name: Install CA certificate for the registry
52 become: true
53 ansible.builtin.copy:
54 content: "{{ buildset_registry.cert }}"
55 dest: /usr/local/share/ca-certificates/registry.crt
56 - name: Update CA certificates
57 become: true
58 ansible.builtin.shell: update-ca-certificates
59 - name: Replace the registry in image manifest
60 ansible.builtin.replace:
61 path: "{{ zuul.project.src_dir }}/roles/defaults/vars/main.yml"
Mohammed Naserd28fbaf2024-04-08 17:15:00 -040062 regexp: "{{ repo }}:{{ tag }}"
63 replace: '{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ repo }}:{{ tag }}'
64 loop: "{{ zuul.artifacts | default([]) }}"
65 loop_control:
66 loop_var: zj_zuul_artifact
67 when: "'metadata' in zj_zuul_artifact and zj_zuul_artifact.metadata.type | default('') == 'container_image'"
68 vars:
69 repo: "{{ zj_zuul_artifact.metadata.repository }}"
70 tag: "{{ zj_zuul_artifact.metadata.tag }}"
Mohammed Naser1bd9d0b2024-04-04 09:05:56 -040071
Mohammed Naserf75ab072024-04-02 12:55:10 -040072 # TODO(mnaser): Drop this when we move to PBR
73 - name: Add current folder to Git's safe directories
74 become: true
75 ansible.builtin.shell: |
76 git config --global --add safe.directory $(pwd)
77 args:
78 chdir: "{{ zuul.project.src_dir }}"