File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pager_duty_key: testkey
77registry_env : prod
88registry_port : 80
99registry_host : " quay.io"
10+ quay_api_token : QB9UzzNhwClqMgRyMgNGrSGLdUYZPJLJALdcpKRa
1011
1112# for docker stop old container
1213stop_time : 5
Original file line number Diff line number Diff line change 1+ ---
2+ dependencies :
3+ - { role: docker_squash }
Original file line number Diff line number Diff line change 2323 url : https://quay.io/api/v1/repository/runnable/{{ repository_name | default(name) }}/tag/?limit=1&specificTag={{ container_tag }}
2424 method : GET
2525 headers :
26- Authorization : ' Bearer QB9UzzNhwClqMgRyMgNGrSGLdUYZPJLJALdcpKRa '
26+ Authorization : ' Bearer {{ quay_api_token }} '
2727 register : currently_built_tags
2828
2929- name : set number of images built
134134 loop_control :
135135 loop_var : file_name_item
136136
137+ - name : get image id for newly created image
138+ tags : deploy
139+ become : true
140+ when : build_image and push_image
141+ shell : docker images -a | grep "{{ container_image }}" | grep "{{ container_tag }}" | awk '{print $3}'
142+ register : unsquahed_image_id
143+
144+ - name : squash newly created image (Expect this to take some time [5 min. approx])
145+ tags : deploy
146+ when : build_image and push_image
147+ become : true
148+ shell : docker-squash "{{ unsquahed_image_id.stdout_lines[0] }}" -t "{{ container_image }}:{{ container_tag }}"
149+
150+ - name : get number of layers
151+ tags : deploy
152+ when : build_image and push_image
153+ become : true
154+ shell : docker history "{{ container_image }}:{{ container_tag }}" | wc -l
155+ register : number_of_layers
156+
157+ - name : Ensure only squashed images are pushed
158+ tags : deploy
159+ # One line for layer and one line for headers
160+ when : build_image and push_image and (number_of_layers is defined and number_of_layers.stdout != "2")
161+ fail : msg="Only squashed layers can be pushed to registry"
162+
137163- name : login to registry
138164 tags : deploy
139165 become : yes
Original file line number Diff line number Diff line change 11---
2- - name : squash newly created image
3- become : true
4- ignore_errors : true # Might already be squashed
5- shell : docker-squash "{{ unsquahed_image_id.stdout_lines[0] }}" -t "{{ container_image }}:{{ container_tag }}"
6-
72- name : get image id for newly created image
83 become : true
94 shell : docker images -a | grep "{{ container_image }}" | grep "{{ container_tag }}" | awk '{print $3}'
You can’t perform that action at this time.
0 commit comments