Files
flymarq a542c10bf2 Optional build with Podman (#206)
* Fix for podman usage

The output of load command in docker and podman differs:
- docker produces only one line of output the sha256 hash at 4th position
- podman produces mulktiple lines of output with sha256 hash in the last line at third position

This patch filters the line with hash and print the last argument, which is the hash. It works with docker and podman. 

Signed-off-by: flymarq <github@flynnux.de>

* Add hints for building with podman

Provide a simple command toi replace all relevant calls to docker with podman to enable a daemon less run.

Signed-off-by: flymarq <github@flynnux.de>

---------

Signed-off-by: flymarq <github@flynnux.de>
2025-10-08 12:24:46 +02:00

44 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Import a tarball as a docker image, specifying the desired image
# creation date.
# This is useful as there's no other way to manipulate the creation
# date, and the date is part of the calculation of the image id.
# This means that the only way to reproduce an image is to specify
# the same timestamp.
set -e
set -u
set -o pipefail
SOURCE=${1:?Specify the tarball to import}
TIMESTAMP=${2:?Specify the timestamp to use}
PLATFORM=${3:?Specify the target platform}
CONF_TEMPLATE='{"architecture":"%PLATFORM%","comment":"from Bitnami with love","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["/bin/bash"],"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container_config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"created":"%TIMESTAMP%","docker_version":"1.13.0","history":[{"created":"%TIMESTAMP%","comment":"from Bitnami with love"}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:%LAYERSUM%"]}}'
MANIFEST_TEMPLATE='[{"Config":"%CONF_SHA%.json","RepoTags":null,"Layers":["%LAYERSUM%/layer.tar"]}]'
import() {
local TDIR="$(mktemp -d)"
local LAYERSUM="$(sha256sum $SOURCE | awk '{print $1}')"
mkdir $TDIR/$LAYERSUM
cp $SOURCE $TDIR/$LAYERSUM/layer.tar
echo -n '1.0' > $TDIR/$LAYERSUM/VERSION
local CONF="$(echo -n "$CONF_TEMPLATE" | sed -e "s/%PLATFORM%/$PLATFORM/g" -e "s/%TIMESTAMP%/$TIMESTAMP/g" -e "s/%LAYERSUM%/$LAYERSUM/g")"
local CONF_SHA="$(echo -n "$CONF" | sha256sum | awk '{print $1}')"
echo -n "$CONF" > "$TDIR/${CONF_SHA}.json"
local MANIFEST="$(echo -n "$MANIFEST_TEMPLATE" | sed -e "s/%CONF_SHA%/$CONF_SHA/g" -e "s/%LAYERSUM%/$LAYERSUM/g")"
echo -n "$MANIFEST" > $TDIR/manifest.json
tar cf $TDIR/import.tar -C $TDIR manifest.json "${CONF_SHA}.json" "$LAYERSUM"
local ID=$(docker load -i $TDIR/import.tar | grep Loaded\ image | awk '{print $NF}')
if [ "$ID" != "sha256:$CONF_SHA" ]; then
echo "Failed to load $ID correctly, expected id to be $CONF_SHA, source in $TDIR" >&2
exit 1
fi
rm -r "$TDIR"
echo $ID
}
import