Skip to content

Commit 4053f3c

Browse files
committed
Option to specify docker image hash
Adds the option to specify a docker image hash to use for the base vm and for descriptors
1 parent 4703d74 commit 4053f3c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

bin/gbuild

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ distro = build_desc["distro"] || "ubuntu"
237237
suites = build_desc["suites"] or raise "must supply suites"
238238
archs = build_desc["architectures"] or raise "must supply architectures"
239239
build_desc["reference_datetime"] or build_desc["remotes"].size > 0 or raise "must supply `reference_datetime` or `remotes`"
240+
docker_image_digests = build_desc["docker_image_digests"] || []
241+
242+
# if docker_image_digests are supplied, it must be the same length as suites
243+
if docker_image_digests.size > 0 and suites.size != docker_image_digests.size
244+
raise "`suites` and `docker_image_digests` must both be the same size if both are supplied"
245+
elsif ENV["USE_DOCKER"] and docker_image_digests.size > 0 and suites.size == docker_image_digests.size
246+
suites = docker_image_digests
247+
end
240248

241249
ENV['DISTRO'] = distro
242250

bin/make-base-vm

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ MIRROR_BASE=http://${MIRROR_HOST:-127.0.0.1}:3142
88
LXC=0
99
VBOX=0
1010
DOCKER=0
11+
DOCKER_IMAGE_HASH=""
1112

1213
usage() {
1314
echo "Usage: ${0##*/} [OPTION]..."
1415
echo "Make a base client."
1516
echo
1617
cat << EOF
17-
--help display this help and exit
18-
--distro D build distro D (e.g. debian) instead of ubuntu
19-
--suite U build suite U instead of xenial
20-
--arch A build architecture A (e.g. i386) instead of amd64
21-
--lxc use lxc instead of kvm
22-
--vbox use VirtualBox instead of kvm
23-
--docker use docker instead of kvm
18+
--help display this help and exit
19+
--distro D build distro D (e.g. debian) instead of ubuntu
20+
--suite U build suite U instead of xenial
21+
--arch A build architecture A (e.g. i386) instead of amd64
22+
--lxc use lxc instead of kvm
23+
--vbox use VirtualBox instead of kvm
24+
--docker use docker instead of kvm
25+
--docker-image-hash D digest of the docker image to build from
2426
2527
The MIRROR_HOST environment variable can be used to change the
2628
apt-cacher host. It should be something that both the host and the
@@ -42,6 +44,11 @@ usage() {
4244
This is done as separate variable to make it clear that we modify sudo
4345
behaviour here regarding security (though anyway env is cleared with
4446
whitelist so should be perfectly safe).
47+
48+
The --docker-image-hash option can be used to specify the hash of a particular
49+
base image to use. These hashes can be found under the "RepoDigests" field of
50+
"docker image inspect <image>". They will be reported in the form "sha256:<hash>";
51+
only need the <hash> part is needed
4552
EOF
4653
}
4754

@@ -76,6 +83,10 @@ if [ $# != 0 ] ; then
7683
DOCKER=1
7784
shift 1
7885
;;
86+
--docker-image-digest)
87+
DOCKER_IMAGE_HASH="$2"
88+
shift 2
89+
;;
7990
--*)
8091
echo "unrecognized option $1"
8192
exit 1
@@ -166,9 +177,16 @@ if [ $DOCKER = "1" ]; then
166177
mkdir -p docker
167178
cd docker
168179

180+
if [ -n "$DOCKER_IMAGE_HASH" ]; then
181+
base_image="$DISTRO@sha256:$DOCKER_IMAGE_HASH"
182+
OUT=base-$DOCKER_IMAGE_HASH-$ARCH
183+
else
184+
base_image="$DISTRO:$SUITE"
185+
fi
186+
169187
# Generate the dockerfile
170188
cat << EOF > $OUT.Dockerfile
171-
FROM $DISTRO:$SUITE
189+
FROM $base_image
172190
173191
ENV DEBIAN_FRONTEND=noninteractive
174192
RUN apt-get update && apt-get --no-install-recommends -y install $addpkg

0 commit comments

Comments
 (0)