/
main.yaml
284 lines (251 loc) · 9.36 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
---
- name: Set branch for building containers check jobs
set_fact:
ci_branch: "{{ zuul.branch | regex_replace('(stable|cloudsig)/', '') }}"
when: zuul is defined
- name: Set branch for building containers branchless
set_fact:
ci_branch: "{{ branch_override | regex_replace('(stable|cloudsig)/', '') }}"
when: branch_override is defined
- name: Set branch for building containers periodic
set_fact:
ci_branch: "{{ release }}"
when: release is defined
- name: Set facts for kolla-build.conf
set_fact:
push_registry: "{{ push_registry | default('127.0.0.1:8787') }}"
push_containers: "{{ push_containers | default(false) | bool }}"
container_config: ""
- name: Set arch_tag fact
set_fact:
# NOTE(mjturek): Push old style tag for x86_64 first to maintain compatibility.
arch_tag: "{{ '_' + ansible_architecture if ansible_architecture != 'x86_64' else ''}}"
- name: Check the contents of the openstack_repo_name repo
become: true
shell: >
set -o pipefail &&
cat /etc/yum.repos.d/{{ openstack_repo_name }}.repo |grep -o 'baseurl=' |wc -l
register: number_baseurl_lines
when: buildcontainers_version_hash is not defined
- name: Use baseurl if there is only one
when:
- buildcontainers_version_hash is not defined
- number_baseurl_lines.stdout|int == 1
block:
- name: Get contents of openstack repo baseurl for the version hash
become: true
shell: >
set -o pipefail &&
cat /etc/yum.repos.d/{{ openstack_repo_name }}.repo |awk -F= '/baseurl/ {print $2}'
register: baseurl
- name: Set version_hash fact
set_fact:
version_hash: "{{ baseurl.stdout.split('/')[-1] }}"
- name: Use the md5sum if there is more than one baseurl line
when:
- buildcontainers_version_hash is not defined
- number_baseurl_lines.stdout|int > 1
block:
- name: Get contents of openstack repo baseurl for the version hash
become: true
shell: md5sum /etc/yum.repos.d/{{ openstack_repo_name }}.repo | awk '{print $1}'
register: md5sum_repo
- name: Set version_hash fact
set_fact:
version_hash: "{{ md5sum_repo.stdout }}"
- name: Set version_hash fact if buildcontainers_version_hash is defined
set_fact:
version_hash: "{{ buildcontainers_version_hash }}"
when: buildcontainers_version_hash is defined
# collectd tries to disable epel and epel-modular repository, which doesn't
# exist, and so fail, this is just a dummy repository so the container won't
# fail.
- name: Add dummy epel and epel-module repository
become: true
when:
- ansible_pkg_mgr == "dnf"
- ansible_distribution|lower == "redhat"
yum_repository:
name: "{{ item }}"
description: Dummy epel repository
file: delorean_epel_dummy
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
enabled: no
with_items:
- epel
- epel-modular
- name: grab kolla patch rhel8
when:
- ansible_pkg_mgr == "dnf"
- ansible_distribution|lower == "redhat"
- zuul_internal is undefined
shell: |
set -euxo pipefail
git config --global user.email "zuul@openstack.org"
git config --global user.name "Zuul"
git remote add upstream https://review.opendev.org/openstack/kolla
git ls-remote https://review.opendev.org/openstack/kolla | \
grep -E refs/changes/[[:digit:]]+/{{ kolla_rhel8_patch[branch_override|default('master')] }}/ | \
awk '{print $2}' | \
sort -t / -k 5 -g -r | \
head -1 | \
xargs -I{} git fetch https://review.opendev.org/openstack/kolla {} && \
git checkout -b rhel8 FETCH_HEAD
# Look for Kolla changes running in check queue and if present then
# set the git_rebase branch as kolla change as are already clonned and
# can be grabbed from zuul.ref var otherwise use master.
git_rebase_branch={{ branch_override|default('master') }}
{% if zuul.ref is defined and zuul.ref and zuul.pipeline in ['check', 'openstack-check'] %}
found=$(git ls-remote https://review.opendev.org/openstack/kolla | grep {{ zuul.ref }} || true);
echo $found;
if [[ -n "$found" ]] ; then
git_rebase_branch={{ zuul.ref }}
fi
{% endif %}
git pull --rebase upstream $git_rebase_branch
args:
chdir: "{{ openstack_git_root }}/kolla"
warn: false
register: result
changed_when: "'nothing to commit, working directory clean' not in result.stdout_lines"
- include_tasks: venv_setup.yml
when: buildcontainers_venv is defined and buildcontainers_venv
- include_tasks: package_setup.yml
when: buildcontainers_venv is defined and not buildcontainers_venv
# TODO(aschultz): make the kolla-build branch aware
- name: Generate kolla-build.conf
template:
src: templates/kolla-build.conf.j2
dest: "{{ workspace }}/kolla-build.conf"
mode: 0644
force: yes
- name: Set container cli
set_fact:
container_cli: "{% if use_buildah|bool %}buildah{% else %}docker{% endif %}"
- name: Set config-file
set_fact:
container_config: "--config-file $TRIPLEO_COMMON_PATH/container-images/overcloud_containers.yaml"
when: ci_branch in ['pike', 'queens', 'rocky']
- name: Set --config-file for component-ci if component_ci_containers is specified
set_fact:
container_config: "--config-file {{ component_ci_configs[component_ci_containers] }}"
when: component_ci_containers != ""
- name: build base rhel container
block:
- name: create docker-build dir
file:
path: /tmp/base-build
state: directory
- name: create docker-build repos dir
file:
path: /tmp/base-build/repos
state: directory
- name: Move delorean repos to base build
become: true
shell:
cmd: |
{% if zuul_internal is defined %}
cp /etc/yum.repos.d/* /tmp/base-build/repos/
{% else %}
cp /etc/yum.repos.d/delorean* /tmp/base-build/repos/
{% endif %}
chown -R {{ ansible_user }}: /tmp/base-build/repos/*
- name: render dockerfile rhui
when: zuul_internal is undefined
template:
src: templates/Dockerfile_rhui.j2
dest: /tmp/base-build/Dockerfile
- name: render dockerfile zuul_internal
when: zuul_internal is defined
template:
src: templates/Dockerfile_redhat.j2
dest: /tmp/base-build/Dockerfile
- name: create base container with repos from rhel container
shell:
cmd: |
set -x
sudo buildah --debug bud -t {{ kolla_base_image }}:{{ kolla_base_tag }} . \
2>&1 {{ timestamper_cmd }} > {{ workspace }}/build-rhel-base.log
args:
chdir: /tmp/base-build
when:
- ansible_distribution|lower == "redhat"
- kolla_base_image is defined
- kolla_base_tag is defined
- name: Make sure authfile exists
when: buildcontainers_authfile_path is defined
block:
- name: Check for authfile
stat:
path: '{{ buildcontainers_authfile_path }}'
register: authfile_exist
- name: Make sure autfile exists
assert:
that:
- authfile_exist.stat.exists | bool
- name: Generate building script
template:
src: templates/build.sh.j2
dest: "{{ workspace }}/build_containers.sh"
mode: 0777
force: yes
- name: "Run image build as ansible user > {{ workspace }}/build.log"
args:
chdir: '{{ workspace }}'
shell: set -o pipefail && bash build_containers.sh 2>&1 {{ timestamper_cmd }} > {{ workspace }}/build.log
when:
- ansible_distribution|lower != "redhat"
- name: "Run image build as root > {{ workspace }}/build.log"
args:
chdir: '{{ workspace }}'
shell: set -o pipefail && bash build_containers.sh 2>&1 {{ timestamper_cmd }} > {{ workspace }}/build.log
become: true
when:
- ansible_distribution|lower == "redhat"
- name: Retrieve list of built x86_64 images, retag, and push
when:
- ansible_architecture == "x86_64"
- push_containers | bool
- not push_containers_podman | default(false) | bool
block:
- name: Retrieve built images
command: "awk '{ print $1 }' {{ workspace }}/containers-successfully-built.log"
register: built_images
- name: Disable HTTPS and certificates to access registry (buildah)
set_fact:
container_cli_opt: '--tls-verify=false'
when: use_buildah | bool
- name: Tag images
vars:
image: "{{ item }}"
include: tag.yaml
static: no
with_items: "{{ built_images.stdout_lines }}"
become: true
- name: Populate provider registry
when:
- provider_job|default(false)|bool
block:
- name: Retrieve built images
command: "awk '{ print $1 }' {{ workspace }}/containers-successfully-built.log"
register: built_images
- name: Run registry
shell: >-
$(command -v docker || command -v podman) run -d \
-e REGISTRY_HTTP_ADDR=0.0.0.0:{{ provider_registry_port }} \
-p {{ provider_registry_port }}:{{ provider_registry_port }} \
--name registry {{ container_registry_image }}
changed_when: true
- name: Open ports
command: iptables -I INPUT -p tcp --dport 5001 -j ACCEPT
changed_when: true
- name: Disable HTTPS and certificates to access registry (buildah)
set_fact:
container_cli_opt: '--tls-verify=false'
- name: Retag and push images to provider registry
vars:
image: "{{ item }}"
include: provider_push.yaml
static: no
with_items: "{{ built_images.stdout_lines }}"
become: true