/
container-push.yml
129 lines (117 loc) · 5.01 KB
/
container-push.yml
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
---
# other than installing docker, need to install docker-python and ansible
# also need to start docker
# This playbook can be used to download the container images which
# passed CI and tag them back to rdoproject registry.
# It will also mirror the images to docker.io.
- name: Download and repush container images
hosts: localhost
become: yes
become_user: root
vars:
named_label: "{{ lookup('env', 'PROMOTE_NAME') }}"
full_hash: "{{ lookup('env', 'FULL_HASH')}}"
script_root: "{{ lookup('env', 'SCRIPT_ROOT') }}"
dockerhub_namespace: "tripleo{{ lookup('env','RELEASE') }}"
dockerhub_username: "{{ lookup('env','DOCKERHUB_USERNAME') }}"
dockerhub_password: "{{ lookup('env','DOCKERHUB_PASSWORD') }}"
rdoproject_namespace: "{{ lookup('env','RELEASE') }}"
rdoproject_username: "{{ lookup('env','RDOPROJECT_USERNAME') }}"
rdoproject_password: "{{ lookup('env','RDOPROJECT_PASSWORD') }}"
tasks:
# NOTE(trown): need to figure out how this list is generated,
# but just took it from the promote artifacts for now:
# https://logs.rdoproject.org/openstack-periodic-4hr/periodic-tripleo-centos-7-pike-containers-build/95e9d60/kolla/parsed_containers.txt
# I manually deleted tacker and ceph containers from the list because we dont need to push those.
# ceph is maintained by ceph team
# tacker container implementation was incomplete in pike
- name: run container tagging and always cleanup at the end
block:
- name: Retrieve list of built images
shell: >
cat "{{ script_root }}/ci-scripts/container-push/parsed_containers.txt"
register: built_images
tags:
- rdoproject_pull
- rdoproject_push
- dockerhub_push
- remove_local_containers
- name: Pull the images from rdoproject registry
docker_image:
name: "trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item }}"
tag: "{{ full_hash }}"
with_items: "{{ built_images.stdout_lines }}"
retries: 3
tags:
- rdoproject_pull
- name: Login to rdoproject registry
docker_login:
registry_url: "trunk.registry.rdoproject.org"
username: "{{ rdoproject_username }}"
password: "{{ rdoproject_password }}"
reauthorize: "yes"
no_log: "yes"
tags:
- rdoproject_push
- name: Tag images to rdoproject registry with named label
shell: >
docker tag
trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item }}:{{ full_hash }}
trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item }}:{{ named_label }}
with_items: "{{ built_images.stdout_lines }}"
tags:
- rdoproject_push
- name: Push images to rdoproject registry with named label
shell: >
docker push trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item }}:{{ named_label }}
with_items: "{{ built_images.stdout_lines }}"
retries: 3
tags:
- rdoproject_push
- name: Login to dockerhub
docker_login:
registry_url: "docker.io"
username: "{{ dockerhub_username }}"
password: "{{ dockerhub_password }}"
reauthorize: "yes"
no_log: "yes"
tags:
- dockerhub_push
# Nested loop order here is on purpose, so we push first all the images with the full hash, then we tag with the named label.
- name: Tag and push images to docker hub
docker_image:
name: "trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item[1] }}"
tag: "{{ item[0] }}"
repository: "docker.io/{{ dockerhub_namespace}}/centos-binary-{{ item[1] }}"
push: yes
with_nested:
- ["{{ full_hash }}", "{{ named_label }}"]
- "{{ built_images.stdout_lines }}"
retries: 3
tags:
- dockerhub_push
always:
- name: Delete the local images from rdoproject registry
docker_image:
name: "trunk.registry.rdoproject.org/{{ rdoproject_namespace }}/centos-binary-{{ item[0] }}"
tag: "{{ item[1] }}"
state: absent
with_nested:
- "{{ built_images.stdout_lines }}"
- ["{{ full_hash }}", "{{ named_label }}"]
retries: 3
ignore_errors: yes
tags:
- remove_local_containers
- name: Delete the local images from docker hub
docker_image:
name: "docker.io/{{ dockerhub_namespace }}/centos-binary-{{ item[0] }}"
tag: "{{ item[1] }}"
state: absent
with_nested:
- "{{ built_images.stdout_lines }}"
- ["{{ full_hash }}", "{{ named_label }}"]
retries: 3
ignore_errors: yes
tags:
- remove_local_containers