Use docker run to run tests and interactive containers

Using docker build is slower and needs lots of Dockerfiles,
while a single image with a careful script can accept any type
of image, either with `-v` to share into `/tmp` for interactive
use (where you need the input and a tty, or by adding a tarball
for cases where there is no login such as running tests, so you
can still use a remote daemon in these cases.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2017-01-24 23:41:06 +00:00
parent b33cee3fc7
commit 007a42ad41
8 changed files with 65 additions and 53 deletions

View File

@ -1,9 +0,0 @@
# Tag: 97cc67f5569c437175f2e54b3c3b9a96a8615a16
FROM mobylinux/alpine-qemu@sha256:80e17a465b332d774fd91b53c0bcb18ed0ea8a77c17bf8d8451c57a8ab8b4e66
COPY alpine/initrd.img .
COPY alpine/kernel/x86_64/vmlinuz64 .
RUN qemu-img create -f raw disk.img 256M
ENTRYPOINT [ "qemu-system-x86_64", "-drive", "file=disk.img,format=raw", "-device", "virtio-rng-pci", "-serial", "stdio", "-kernel", "vmlinuz64", "-initrd", "initrd.img", "-m", "2048", "-append", "earlyprintk=serial console=ttyS0 noapic", "-vnc", "none" ]

View File

@ -1,7 +0,0 @@
# Tag: 97cc67f5569c437175f2e54b3c3b9a96a8615a16
FROM mobylinux/alpine-qemu@sha256:80e17a465b332d774fd91b53c0bcb18ed0ea8a77c17bf8d8451c57a8ab8b4e66
COPY alpine/gce.img.tar.gz .
RUN zcat gce.img.tar.gz | tar xf -
ENTRYPOINT [ "qemu-system-x86_64", "-serial", "stdio", "-drive", "file=disk.raw,format=raw", "-m", "2048", "-vnc", "none" ]

View File

@ -1,6 +0,0 @@
# Tag: 97cc67f5569c437175f2e54b3c3b9a96a8615a16
FROM mobylinux/alpine-qemu@sha256:80e17a465b332d774fd91b53c0bcb18ed0ea8a77c17bf8d8451c57a8ab8b4e66
COPY alpine/mobylinux-bios.iso .
ENTRYPOINT [ "qemu-system-x86_64", "-serial", "stdio", "-cdrom", "./mobylinux-bios.iso", "-m", "2048", "-vnc", "none" ]

View File

@ -1,9 +0,0 @@
# Tag: 97cc67f5569c437175f2e54b3c3b9a96a8615a16
FROM mobylinux/alpine-qemu@sha256:80e17a465b332d774fd91b53c0bcb18ed0ea8a77c17bf8d8451c57a8ab8b4e66
COPY alpine/initrd-test.img initrd.img
COPY alpine/kernel/x86_64/vmlinuz64 .
RUN qemu-img create -f raw disk.img 256M
ENTRYPOINT [ "qemu-system-x86_64", "-drive", "file=disk.img,format=raw", "-device", "virtio-rng-pci", "-serial", "stdio", "-kernel", "vmlinuz64", "-initrd", "initrd.img", "-m", "1024", "-append", "earlyprintk=serial console=ttyS0 noapic", "-vnc", "none" ]

View File

@ -16,17 +16,21 @@ alpine/kernel/x86_64/vmlinuz64:
alpine/mobylinux-bios.iso:
$(MAKE) -C alpine mobylinux-bios.iso
qemu: Dockerfile.qemu alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
tar cf - $^ | docker build -f Dockerfile.qemu -t mobyqemu:build -
docker run -it --rm mobyqemu:build
alpine/gce.img.tar.gz:
$(MAKE) -C alpine gce.img.tar.gz
qemu-iso: Dockerfile.qemuiso alpine/mobylinux-bios.iso
tar cf - $^ | docker build -f Dockerfile.qemuiso -t mobyqemuiso:build -
docker run -it --rm mobyqemuiso:build
# Tag: 0fb8c648e8ed9ef6b1ec449587aeab6c53872744
QEMU_IMAGE=mobylinux/qemu@sha256:606f30d815102e73bc01c07915dc0d5f153b0252c63f5f0ed1e39621ec656eb5
qemu-gce: Dockerfile.qemugce alpine/gce.img.tar.gz
tar cf - $^ | docker build -f Dockerfile.qemugce -t mobyqemugce:build -
docker run -it --rm mobyqemugce:build
# interactive versions need to use volume mounts
qemu: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
docker run -it --rm -v $(CURDIR)/alpine/initrd.img:/tmp/initrd.img -v $(CURDIR)/alpine/kernel/x86_64/vmlinuz64:/tmp/vmlinuz64 $(QEMU_IMAGE)
qemu-iso: alpine/mobylinux-bios.iso
docker run -it --rm -v $(CURDIR)/alpine/mobylinux-bios.iso:/tmp/mobylinux-bios.iso $(QEMU_IMAGE)
qemu-gce: alpine/gce.img.tar.gz
docker run -it --rm -v $(CURDIR)/alpine/gce.img.tar.gz:/tmp/gce.img.tar.gz $(QEMU_IMAGE)
hyperkit.bin:
mkdir $@
@ -48,17 +52,11 @@ endef
hyperkit-test: hyperkit.sh hyperkit.bin/com.docker.hyperkit hyperkit.bin/com.docker.slirp alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
rm -f disk.img
touch test.log && \
INITRD=alpine/initrd-test.img ./hyperkit.sh 2>&1 | tee -a test.log
INITRD=alpine/initrd-test.img ./hyperkit.sh 2>&1 | tee test.log
$(call check_test_log, test.log)
test: Dockerfile.test alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
$(MAKE) -C alpine
BUILD=$$( tar cf - $^ | docker build -f Dockerfile.test -q - ) && \
[ -n "$$BUILD" ] && \
echo "Built $$BUILD" && \
touch test.log && \
docker run --rm $$BUILD 2>&1 | tee -a test.log
test: alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
tar cf - $^ | docker run --rm -i $(QEMU_IMAGE) 2>&1 | tee test.log
$(call check_test_log, test.log)
TAG=$(shell git rev-parse HEAD)
@ -128,4 +126,4 @@ ci-pr:
clean:
$(MAKE) -C alpine clean
rm -rf hyperkit.bin disk.img
rm -rf hyperkit.bin disk.img test.log

View File

@ -3,7 +3,11 @@ FROM alpine:3.5
RUN \
apk update && apk upgrade && \
apk add --no-cache \
libarchive-tools \
qemu-img \
qemu-system-arm \
qemu-system-x86_64 \
&& true
COPY . .
ENTRYPOINT ["/qemu.sh"]

View File

@ -1,14 +1,14 @@
.PHONY: tag push
BASE=alpine:3.5
IMAGE=alpine-qemu
IMAGE=qemu
default: push
hash: Dockerfile
hash: Dockerfile qemu.sh
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm $(IMAGE):build sha1sum /lib/apk/db/installed | sed 's/ .*//' > hash
docker run --rm --entrypoint /bin/sh $(IMAGE):build -c 'cat Dockerfile qemu.sh /lib/apk/db/installed | sha1sum' | sed 's/ .*//' > $@
push: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \

41
base/qemu/qemu.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
set -e
cd /tmp
# extract. BSD tar auto recognises compression, unlike GNU tar
# only if stdin is a tty, if so need files volume mounted...
[ -t 0 ] || bsdtar xzf -
TGZ="$(find . -name '*.tgz' -or -name '*.tar.gz')"
[ -n "$TGZ" ] && bsdtar xzf "$TGZ"
ISO="$(find . -name '*.iso')"
RAW="$(find . -name '*.raw')"
INITRD="$(find . -name '*.img')"
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
if [ -n "$ISO" ]
then
ARGS="-cdrom $ISO -drive file=systemdisk.img,format=raw"
elif [ -n "$RAW" ]
then
# should test with more drives
ARGS="-drive file=$RAW,format=raw"
elif [ -n "KERNEL" ]
then
ARGS="-kernel $KERNEL"
if [ -n "$INITRD" ]
then
ARGS="$ARGS -initrd $INITRD"
fi
ARGS="$ARGS -append console=ttyS0 -drive file=systemdisk.img,format=raw"
else
echo "no recognised boot media" >2
exit 1
fi
echo "$ARGS" | grep -q systemdisk && qemu-img create -f raw systemdisk.img 256M
qemu-system-x86_64 -device virtio-rng-pci -serial stdio -vnc none -m 1024 $ARGS $*