install: Do not create intermediate tarfile for container

Skip the creation of the `share/container.tar` file, since it's not used
anywhere. Instead, pipe our `docker/podman save` invocations to `gzip`
directly, which will compress the tarfile on the fly. This saves both
time and disk space.
This commit is contained in:
Alex Pyrgiotis 2022-12-09 19:17:52 +02:00
parent a0503c8c40
commit 624d480cca
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
3 changed files with 16 additions and 24 deletions

View file

@ -3,11 +3,8 @@
echo "Building container image"
podman build container --platform linux/amd64 --tag dangerzone.rocks/dangerzone
echo "Saving container image"
podman save dangerzone.rocks/dangerzone -o share/container.tar
echo "Compressing container image"
gzip -f share/container.tar
echo "Saving and compressing container image"
podman save dangerzone.rocks/dangerzone | gzip > share/container.tar.gz
echo "Looking up the image id"
podman image ls dangerzone.rocks/dangerzone | grep "dangerzone.rocks/dangerzone" | tr -s ' ' | cut -d' ' -f3 > share/image-id.txt

View file

@ -3,11 +3,8 @@
echo "Building container image"
docker build container --platform linux/amd64 --tag dangerzone.rocks/dangerzone
echo "Saving container image"
docker save dangerzone.rocks/dangerzone -o share/container.tar
echo "Compressing container image"
gzip -f share/container.tar
echo "Saving and compressing container image"
docker save dangerzone.rocks/dangerzone | gzip > share/container.tar.gz
echo "Looking up the image id"
docker image ls dangerzone.rocks/dangerzone | grep "dangerzone.rocks/dangerzone" | tr -s ' ' | cut -d' ' -f3 > share/image-id.txt

View file

@ -18,28 +18,26 @@ def main():
)
print("Saving container image")
subprocess.run(
cmd = subprocess.Popen(
[
"docker",
"save",
"dangerzone.rocks/dangerzone",
"-o",
"share/container.tar",
]
],
stdout=subprocess.PIPE,
)
print("Compressing container image")
chunk_size = 1024
with open("share/container.tar", "rb") as f:
with gzip.open("share/container.tar.gz", "wb") as gzip_f:
while True:
chunk = f.read(chunk_size)
if len(chunk) > 0:
gzip_f.write(chunk)
else:
break
chunk_size = 4 << 12
with gzip.open("share/container.tar.gz", "wb") as gzip_f:
while True:
chunk = cmd.stdout.read(chunk_size)
if len(chunk) > 0:
gzip_f.write(chunk)
else:
break
os.remove("share/container.tar")
cmd.wait(5)
print("Looking up the image id")
image_id = subprocess.check_output(