From ac82202afd3750e585da14f9eccf62bbe50f899d Mon Sep 17 00:00:00 2001 From: Kristian Amlie Date: Fri, 6 Dec 2019 10:47:34 +0100 Subject: [PATCH] Add lzma compression option for `MENDER_COMPRESS_DISK_IMAGE`. It uses the parallel pxz compression tool. Changelog: Title Signed-off-by: Kristian Amlie --- Dockerfile | 17 ++++++++++++++++- configs/mender_convert_config | 10 ++++++++-- mender-convert-package | 20 ++++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b19e133..6a2529d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,14 @@ +# Build pxz in separate image to avoid big image size +FROM ubuntu:19.04 AS build +RUN apt-get update && apt-get install -y \ + build-essential \ + git \ + liblzma-dev + +# Parallel xz (LZMA) compression +RUN git clone https://github.com/jnovy/pxz.git /root/pxz +RUN cd /root/pxz && make + FROM ubuntu:19.04 ARG MENDER_ARTIFACT_VERSION=3.1.0 @@ -30,7 +41,11 @@ RUN apt-get update && apt-get install -y \ # to get rid of 'sh: 1: udevadm: not found' errors triggered by parted udev \ # to create bmap index file (MENDER_USE_BMAP) - bmap-tools + bmap-tools \ +# needed to run pxz + libgomp1 + +COPY --from=build /root/pxz/pxz /usr/bin/pxz RUN wget -q -O /usr/bin/mender-artifact https://d1b0l86ne08fsf.cloudfront.net/mender-artifact/$MENDER_ARTIFACT_VERSION/linux/mender-artifact \ && chmod +x /usr/bin/mender-artifact diff --git a/configs/mender_convert_config b/configs/mender_convert_config index b4929da..74f5615 100644 --- a/configs/mender_convert_config +++ b/configs/mender_convert_config @@ -4,12 +4,18 @@ # # NOTE! This file will always be sourced. -# Compress generated disk image using gzip +# Compress generated disk image # # This is useful when you have large disk images, compressing them # makes it easier to transfer them between e.g an build server and a local # machine, and obviously saves space. -MENDER_COMPRESS_DISK_IMAGE=y +# +# Possible values are: +# 'n' - No compression +# 'gzip' - Compress with gzip +# 'lzma' - Compress with xz (LZMA) +# 'y' - Alias for 'gzip' +MENDER_COMPRESS_DISK_IMAGE=gzip # Compression algorithm for Mender Artifact # diff --git a/mender-convert-package b/mender-convert-package index 05ece85..344d54b 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -251,10 +251,22 @@ if [ "${MENDER_USE_BMAP}" == "y" ]; then run_and_log_cmd "${BMAP_TOOL} create ${sdimg_path} > ${sdimg_path}.bmap" fi -if [ "${MENDER_COMPRESS_DISK_IMAGE}" == "y" ]; then - log_info "Compressing ${sdimg_path}.gz" - run_and_log_cmd "pigz --best --force ${sdimg_path}" -fi +case "${MENDER_COMPRESS_DISK_IMAGE}" in + y | gzip) + log_info "Compressing ${sdimg_path}.gz" + run_and_log_cmd "pigz --best --force ${sdimg_path}" + ;; + lzma) + log_info "Compressing ${sdimg_path}.xz" + run_and_log_cmd "pxz --best --force ${sdimg_path}" + ;; + n) + : + ;; + *) + log_fatal "Unknown MENDER_COMPRESS_DISK_IMAGE value: ${MENDER_COMPRESS_DISK_IMAGE}" + ;; +esac log_info "Conversion has completed! \o/"