-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.yaml
129 lines (119 loc) · 4.18 KB
/
generate.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
---
- hosts: localhost
gather_facts: false
pre_tasks:
- name: Check if tags is not float
assert:
that:
- "'float' not in reexported_images|json_query('[].*[][]')|map('type_debug')"
- name: Create a directory for export
become: true
file:
path: "{{ directory }}"
state: directory
with_items: '{{ reexported_images }}'
loop_control:
label: "{{ directory }}"
vars:
directory: '{{ docker_images_dir }}/{{ item.name|replace (".", "_") }}'
- name: Create directory for registry structure
become: true
file:
path: "{{ item }}"
state: directory
with_items:
- '{{ registry_blobs_dir }}'
- '{{ registry_manifests_dir }}'
- '{{ registry_tags_dir }}'
tasks:
- name: Archive image of interest into local directory
become: true
command:
cmd: "skopeo copy docker://{{ container }} dir:{{ filename }}"
creates: "{{ filename }}"
loop_control:
label: "{{ item.0.name }}:{{ item.1 }}"
with_subelements:
- '{{ reexported_images }}'
- tags
vars:
filename: '{{ docker_images_dir }}/{{ item.0.name|replace (".", "_") }}/{{ item.1|replace (".", "_") }}'
container: '{{ item.0.name }}:{{ item.1 }}'
- name: Hardlink image blobs
become: true
synchronize:
src: "{{ filename }}/"
dest: "{{ registry_blobs_dir }}/"
link_dest: "{{ filename }}/"
rsync_opts:
- "--exclude=manifest.json"
- "--exclude=version"
loop_control:
label: "{{ item.0.name }}:{{ item.1 }}"
with_subelements:
- '{{ reexported_images }}'
- tags
vars:
filename: '{{ docker_images_dir }}/{{ item.0.name|replace (".", "_") }}/{{ item.1|replace (".", "_") }}'
container: '{{ item.0.name }}:{{ item.1 }}'
- name: Get manifest digest
become: true
command:
cmd: "skopeo manifest-digest {{ filename }}/manifest.json"
register: manifest_digest
changed_when: false
loop_control:
label: "{{ item.0.name }}:{{ item.1 }}"
with_subelements:
- '{{ reexported_images }}'
- tags
vars:
filename: '{{ docker_images_dir }}/{{ item.0.name|replace (".", "_") }}/{{ item.1|replace (".", "_") }}'
container: '{{ item.0.name }}:{{ item.1 }}'
- name: Generate docker images hash map
set_fact:
docker_v2: "{{ docker_v2|default([])|combine({ image: sha256 }) }}"
manifest: "{{ manifest|default([])|combine({ filename: sha256 }) }}"
repos: "{{ repos|default([]) + [ repo ] }}"
loop_control:
label: "{{ image }}"
with_items: "{{ manifest_digest|json_query('results[*]') }}"
vars:
repo: "{{ item|json_query('item[0].name') }}"
image: "{{ item|json_query('item[0].name') }}:{{ item|json_query('item[1]') }}"
filename: "{{ item|json_query('cmd[2]') }}"
sha256: "{{ item|json_query('stdout')|replace('sha256:', '') }}"
- name: Hardlink manifest files
file:
src: "{{ filename }}"
dest: "{{ registry_manifests_dir }}/{{ sha256 }}.json"
state: hard
loop_control:
label: "{{ image }}"
with_items: "{{ manifest_digest|json_query('results[*]') }}"
vars:
image: "{{ item|json_query('item[0].name') }}:{{ item|json_query('item[1]') }}"
filename: "{{ item|json_query('cmd[2]') }}"
sha256: "{{ item|json_query('stdout')|replace('sha256:', '') }}"
- name: Generate tags
with_items: '{{ reexported_images }}'
copy:
content: "{{ image|to_json }}"
dest: "{{ registry_tags_dir }}/{{ item.name|hash('md5') }}.json"
loop_control:
label: '{{ item.name }}'
vars:
image:
name: '{{ item.name }}'
tags: '{{ item.tags }}'
- name: Create db file
copy:
content: "{{ docker_v2|to_json }}"
dest: "{{ registry_dir }}/images.json"
- name: Create catalog file
copy:
content: "{{ catalog|to_json }}"
dest: "{{ registry_dir }}/catalog.json"
vars:
catalog:
repositories: "{{ repos|unique }}"