Allow disabling compression of uploaded images

AWS requires image in raw format when directly importing from an S3
bucket.

Change-Id: I3e3d6bdd3f802474f074396e089252753527d67b
This commit is contained in:
Simon Westphahl
2025-10-10 11:37:48 +02:00
parent 191a1b2822
commit 7874eaf857
4 changed files with 59 additions and 19 deletions

View File

@@ -4,9 +4,9 @@ This uploads a filesystem image (for example, one built by diskimage
builder) to an S3 bucket. The role returns an artifact to Zuul builder) to an S3 bucket. The role returns an artifact to Zuul
suitable for use by the zuul-launcher. suitable for use by the zuul-launcher.
If a `raw` or `vhd` image is provided and the `zstd` command is If a `raw` or `vhd` image is provided, `upload_image_s3_compress_image` is true
available, it will be compressed in the way that zuul-launcher and the `zstd` command is available, it will be compressed in the way that
expects. zuul-launcher expects.
**Role Variables** **Role Variables**
@@ -69,6 +69,15 @@ expects.
The object name to use when uploading. The object name to use when uploading.
.. zuul:rolevar:: upload_image_s3_compress_image
:default: true
Whether to compress the image using zstd before upload.
Some providers (e.g. AWS) require the image to be in raw format when
importing directly from S3. In those cases the flag should be set to
`false`.
.. zuul:rolevar:: upload_image_s3_hash_timeout .. zuul:rolevar:: upload_image_s3_hash_timeout
:default: 600 :default: 600

View File

@@ -3,4 +3,5 @@ upload_image_s3_delete_after: 0
upload_image_s3_filename: '{{ build_diskimage_image_root }}/{{ build_diskimage_image_name }}.{{ upload_image_s3_extension }}' upload_image_s3_filename: '{{ build_diskimage_image_root }}/{{ build_diskimage_image_name }}.{{ upload_image_s3_extension }}'
upload_image_s3_name: '{{ zuul.build }}-{{ build_diskimage_image_name }}.{{ upload_image_s3_extension }}' upload_image_s3_name: '{{ zuul.build }}-{{ build_diskimage_image_name }}.{{ upload_image_s3_extension }}'
upload_image_s3_extension: '{{ upload_image_s3_format }}' upload_image_s3_extension: '{{ upload_image_s3_format }}'
upload_image_s3_compress_image: true
upload_image_s3_hash_timeout: 600 upload_image_s3_hash_timeout: 600

View File

@@ -15,27 +15,31 @@
poll: 0 poll: 0
register: md5_task register: md5_task
- name: Check if zstd is installed
shell: "command -v zstd || exit 1"
register: zstd_installed
failed_when: false
- name: Compress image
when:
- "zstd_installed.rc == 0"
- "upload_image_s3_format in ['raw', 'vhd']"
command: zstd '{{ upload_image_s3_filename }}'
- name: Set extension - name: Set extension
set_fact: set_fact:
zj_upload_image_s3_extension: '' zj_upload_image_s3_extension: ''
- name: Set extension - name: Compress image
when: when:
- "zstd_installed.rc == 0" - "upload_image_s3_compress_image"
- "upload_image_s3_format in ['raw', 'vhd']" block:
set_fact: - name: Check if zstd is installed
zj_upload_image_s3_extension: '.zst' shell: "command -v zstd || exit 1"
register: zstd_installed
failed_when: false
- name: Compress image
when:
- "zstd_installed.rc == 0"
- "upload_image_s3_format in ['raw', 'vhd']"
command: zstd '{{ upload_image_s3_filename }}'
- name: Set extension
when:
- "zstd_installed.rc == 0"
- "upload_image_s3_format in ['raw', 'vhd']"
set_fact:
zj_upload_image_s3_extension: '.zst'
- name: Upload image to S3 - name: Upload image to S3
no_log: true no_log: true

View File

@@ -102,3 +102,29 @@
- name: Check for testfile in minio bucket - name: Check for testfile in minio bucket
command: "{{ ansible_user_dir }}/mc find local/zuul/{{ test_objectname }}.zst" command: "{{ ansible_user_dir }}/mc find local/zuul/{{ test_objectname }}.zst"
- name: Add content to tempfile
copy:
content: "{{ test_content }}"
dest: "{{ test_filename }}"
- name: Remove temp file so we can run the role again
command: rm -f /tmp/testfile.zst
# This should upload the raw image w/o compressing it
- name: Upload file to s3
include_role:
name: upload-image-s3
vars:
upload_image_s3_endpoint: "http://localhost:9000"
upload_image_s3_aws_access_key: "{{ test_aws_access_key }}"
upload_image_s3_aws_secret_key: "{{ test_aws_secret_key }}"
upload_image_s3_bucket: "{{ test_bucket }}"
upload_image_s3_filename: "{{ test_filename }}"
upload_image_s3_name: "{{ test_objectname }}"
upload_image_s3_image_name: "{{ test_image }}"
upload_image_s3_format: "{{ test_ext }}"
upload_image_s3_compress_image: false
- name: Check for testfile in minio bucket
command: "{{ ansible_user_dir }}/mc find local/zuul/{{ test_objectname }}"