Search code examples
linuxdockerfile

How to decompress a .tar.zst?


currently working on a task where I have to adjust an existing dockerfile to create a new .tar.gz for Python 3.12.2 and frankly, I'm at my wits end. Here is the script being used:

# The same base image as the jenkins agents
FROM openjdk:17-jdk-bullseye

# install tools we need
WORKDIR /package-install
ADD zstd_*_amd64.deb zstd.deb
RUN dpkg -i zstd.deb

# insert the input packages
WORKDIR /input
ADD cpython-*-x86_64-unknown-linux-gnu-pgo-*.tar.zst python.tar.zst

# re-compress the tar archive
WORKDIR /build
RUN unzstd /input/python.tar.zst -o ./python.tar
RUN gzip -k ./python.tar

# prepare the output file
RUN cp ./python.tar.gz /python.tar.gz
RUN chmod a=rw /python.tar.gz

# declare the export
VOLUME /export

WORKDIR /

# this will be executed when the container starts
CMD [ "cp", "-va", "/python.tar.gz", "/export/" ]

The Script fails at the unzstd command and tells me that it can't perform the task because allegedly python.tar.zst is a directory.

Nothing I have found so far has helped me solve this issue. If you have any Idea what is causing this issue and how to fix this, I would be glad for your input.

Best Regards Pascal

Additional Information: cpython-3.12.2+20240224-x86_64-unknown-linux-gnu-pgo-full.tar.zst is the tar.zst in question.

After I learned this I googled a little and found the possibility of adding -r to the command in order to decompress every file inside the .tar.zst, but this yielded the following error:

The command '/bin/sh -c unzstd -r /input/python.tar.zst/ -o ./python.tar' returned a non-zero code: 1

Solution

  • I bit the bullet and played w/ docker, was about time, eh?

    Anyway: turns out that docker is incredibly stupid in its being smart. ADD recognises tar files, and generously unpacks them for you; ADD also only accepts directories as the destination. Taking these two things together you actually end up w/ a directory called python.tar.zst under which there's a dir python with your expanded tarball.

    Long story short - you can achieve your actual goal this way:

    # The same base image as the jenkins agents
    FROM openjdk:17-jdk-bullseye
    
    # install tools we need
    WORKDIR /package-install
    ADD zstd_*_amd64.deb zstd.deb
    RUN dpkg -i zstd.deb
    
    # insert the input packages
    WORKDIR /input
    ADD cpython-*-x86_64-unknown-linux-gnu-pgo-*.tar.zst /input
    
    # re-compress the tar archive
    WORKDIR /build
    # prepare the output file
    RUN tar cvzf python.tar.gz /input/python
    RUN chmod a=rw python.tar.gz
    
    # declare the export
    VOLUME /export
    
    WORKDIR /
    
    # this will be executed when the container starts
    CMD [ "cp", "-va", "/build/python.tar.gz", "/export/" ]