Skip to content

Commit 3bf53a0

Browse files
committed
build: Rework image tagging
We should really create proper multi-arch images, ... but we can at least improve the current system we have of tagging the image with the host arch. The problem with the way we do it now is that the two tags (the plain one and the one with the arch) cause docker rmi to refuse to delete the image until one if explicitly untagged. Instead we can only create the tag with the arch name in it temporarily, when we're pulling/pushing. To make that work with the allcross image we need to drop --pull, so that the FROM will use the local image without the arch name.
1 parent 7e0d5e1 commit 3bf53a0

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

build/scripts/image.sh

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,61 @@ elif [[ "$task" == "pull-image" ]]; then
3434
exit $?
3535
fi
3636

37+
# Tag the arch specific image with the generic tag
3738
cmd="$DOCKER tag $arch_image $image"
3839
(set -x; $cmd)
40+
if [[ $? -ne 0 ]]; then
41+
echo "Error: tagging $arch_image as $image?" >&2
42+
exit 1
43+
fi
44+
45+
# Remove the arch tag (not the whole image)
46+
cmd="$DOCKER rmi $arch_image"
47+
(set -x; $cmd)
48+
if [[ $? -ne 0 ]]; then
49+
echo "Error: untagging $arch_image?" >&2
50+
exit 1
51+
fi
3952

40-
exit $?
53+
exit 0
4154
elif [[ "$task" == "push-image" ]]; then
4255
if [[ -n "$DOCKER_PASSWORD" && -n "$DOCKER_USER" ]]; then
4356
cmd="$DOCKER login -u $DOCKER_USER -p $DOCKER_PASSWORD"
4457
(set -x; $cmd)
4558
fi
4659

47-
image="$image-$(uname -m)"
48-
cmd="$DOCKER push $image"
60+
# Temporarily tag the image with the arch
61+
arch_image="$image-$(uname -m)"
62+
cmd="$DOCKER tag $image $arch_image"
63+
(set -x; $cmd)
64+
if [[ $? -ne 0 ]]; then
65+
echo "Error: tagging $image as $arch_image?" >&2
66+
exit 1
67+
fi
68+
69+
cmd="$DOCKER push $arch_image"
70+
(set -x; $cmd)
71+
if [[ $? -ne 0 ]]; then
72+
echo "Error: pushing $arch_image?" >&2
73+
exit 1
74+
fi
75+
76+
# Remove the arch tag (not the whole image)
77+
cmd="$DOCKER rmi $arch_image"
4978
(set -x; $cmd)
50-
exit $?
79+
if [[ $? -ne 0 ]]; then
80+
echo "Error: untagging $arch_image?" >&2
81+
exit 1
82+
fi
83+
84+
exit 0
5185
fi
5286

53-
cmd="$DOCKER build --pull -f $distro/Dockerfile "
87+
cmd="$DOCKER build -f $distro/Dockerfile "
88+
89+
if [[ "$distro" != "ubuntu-allcross" ]]; then
90+
cmd+="--pull "
91+
fi
5492

5593
if [[ -n "$http_proxy" ]]; then
5694
cmd+="--build-arg http_proxy=$http_proxy "
@@ -73,7 +111,7 @@ from="${DOCKER_REGISTRY}$distro:$version"
73111
if [[ "$distro" == "docs" ]]; then
74112
from="${DOCKER_REGISTRY}ubuntu:$version"
75113
elif [[ "$distro" == "ubuntu-allcross" ]]; then
76-
from="${DOCKER_REGISTRY}linuxppc/build:ubuntu-$version-$(uname -m)"
114+
from="${DOCKER_REGISTRY}linuxppc/build:ubuntu-$version"
77115
elif [[ "$distro" == "korg" ]]; then
78116
cmd+="--build-arg compiler_version=$version "
79117

@@ -94,7 +132,6 @@ cmd+="--build-arg uid=$UID "
94132
cmd+="--build-arg gid=$GID "
95133
cmd+="--build-arg from=$from "
96134
cmd+="--build-arg apt_mirror=$APT_MIRROR "
97-
cmd+="-t $image-$(uname -m) "
98135
cmd+="-t $image ."
99136

100137
(set -x; $cmd)

0 commit comments

Comments
 (0)