From 7874eaf8579a7b9f212ba682e1e6640960aacbdb Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Fri, 10 Oct 2025 11:37:48 +0200 Subject: [PATCH] Allow disabling compression of uploaded images AWS requires image in raw format when directly importing from an S3 bucket. Change-Id: I3e3d6bdd3f802474f074396e089252753527d67b --- roles/upload-image-s3/README.rst | 15 ++++++++-- roles/upload-image-s3/defaults/main.yaml | 1 + roles/upload-image-s3/tasks/main.yaml | 36 +++++++++++++----------- test-playbooks/upload-image-s3.yaml | 26 +++++++++++++++++ 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/roles/upload-image-s3/README.rst b/roles/upload-image-s3/README.rst index eff3619d6..ac8f37b02 100644 --- a/roles/upload-image-s3/README.rst +++ b/roles/upload-image-s3/README.rst @@ -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 suitable for use by the zuul-launcher. -If a `raw` or `vhd` image is provided and the `zstd` command is -available, it will be compressed in the way that zuul-launcher -expects. +If a `raw` or `vhd` image is provided, `upload_image_s3_compress_image` is true +and the `zstd` command is available, it will be compressed in the way that +zuul-launcher expects. **Role Variables** @@ -69,6 +69,15 @@ expects. 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 :default: 600 diff --git a/roles/upload-image-s3/defaults/main.yaml b/roles/upload-image-s3/defaults/main.yaml index 3ade12fa2..1114624a3 100644 --- a/roles/upload-image-s3/defaults/main.yaml +++ b/roles/upload-image-s3/defaults/main.yaml @@ -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_name: '{{ zuul.build }}-{{ build_diskimage_image_name }}.{{ upload_image_s3_extension }}' upload_image_s3_extension: '{{ upload_image_s3_format }}' +upload_image_s3_compress_image: true upload_image_s3_hash_timeout: 600 diff --git a/roles/upload-image-s3/tasks/main.yaml b/roles/upload-image-s3/tasks/main.yaml index e1d407cfc..f8a5a0f4d 100644 --- a/roles/upload-image-s3/tasks/main.yaml +++ b/roles/upload-image-s3/tasks/main.yaml @@ -15,27 +15,31 @@ poll: 0 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 set_fact: zj_upload_image_s3_extension: '' -- name: Set extension +- name: Compress image when: - - "zstd_installed.rc == 0" - - "upload_image_s3_format in ['raw', 'vhd']" - set_fact: - zj_upload_image_s3_extension: '.zst' + - "upload_image_s3_compress_image" + block: + - 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 + 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 no_log: true diff --git a/test-playbooks/upload-image-s3.yaml b/test-playbooks/upload-image-s3.yaml index 3335ae9f4..9db14e45c 100644 --- a/test-playbooks/upload-image-s3.yaml +++ b/test-playbooks/upload-image-s3.yaml @@ -102,3 +102,29 @@ - name: Check for testfile in minio bucket 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 }}"