mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
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:
parent
b33cee3fc7
commit
007a42ad41
@ -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" ]
|
|
@ -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" ]
|
|
@ -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" ]
|
|
@ -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" ]
|
|
36
Makefile
36
Makefile
@ -16,17 +16,21 @@ alpine/kernel/x86_64/vmlinuz64:
|
|||||||
alpine/mobylinux-bios.iso:
|
alpine/mobylinux-bios.iso:
|
||||||
$(MAKE) -C alpine mobylinux-bios.iso
|
$(MAKE) -C alpine mobylinux-bios.iso
|
||||||
|
|
||||||
qemu: Dockerfile.qemu alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
|
alpine/gce.img.tar.gz:
|
||||||
tar cf - $^ | docker build -f Dockerfile.qemu -t mobyqemu:build -
|
$(MAKE) -C alpine gce.img.tar.gz
|
||||||
docker run -it --rm mobyqemu:build
|
|
||||||
|
|
||||||
qemu-iso: Dockerfile.qemuiso alpine/mobylinux-bios.iso
|
# Tag: 0fb8c648e8ed9ef6b1ec449587aeab6c53872744
|
||||||
tar cf - $^ | docker build -f Dockerfile.qemuiso -t mobyqemuiso:build -
|
QEMU_IMAGE=mobylinux/qemu@sha256:606f30d815102e73bc01c07915dc0d5f153b0252c63f5f0ed1e39621ec656eb5
|
||||||
docker run -it --rm mobyqemuiso:build
|
|
||||||
|
|
||||||
qemu-gce: Dockerfile.qemugce alpine/gce.img.tar.gz
|
# interactive versions need to use volume mounts
|
||||||
tar cf - $^ | docker build -f Dockerfile.qemugce -t mobyqemugce:build -
|
qemu: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
|
||||||
docker run -it --rm mobyqemugce:build
|
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:
|
hyperkit.bin:
|
||||||
mkdir $@
|
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
|
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
|
rm -f disk.img
|
||||||
touch test.log && \
|
INITRD=alpine/initrd-test.img ./hyperkit.sh 2>&1 | tee test.log
|
||||||
INITRD=alpine/initrd-test.img ./hyperkit.sh 2>&1 | tee -a test.log
|
|
||||||
$(call check_test_log, test.log)
|
$(call check_test_log, test.log)
|
||||||
|
|
||||||
test: Dockerfile.test alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
|
test: alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
|
||||||
$(MAKE) -C alpine
|
tar cf - $^ | docker run --rm -i $(QEMU_IMAGE) 2>&1 | tee test.log
|
||||||
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
|
|
||||||
$(call check_test_log, test.log)
|
$(call check_test_log, test.log)
|
||||||
|
|
||||||
TAG=$(shell git rev-parse HEAD)
|
TAG=$(shell git rev-parse HEAD)
|
||||||
@ -128,4 +126,4 @@ ci-pr:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C alpine clean
|
$(MAKE) -C alpine clean
|
||||||
rm -rf hyperkit.bin disk.img
|
rm -rf hyperkit.bin disk.img test.log
|
||||||
|
@ -3,7 +3,11 @@ FROM alpine:3.5
|
|||||||
RUN \
|
RUN \
|
||||||
apk update && apk upgrade && \
|
apk update && apk upgrade && \
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
|
libarchive-tools \
|
||||||
qemu-img \
|
qemu-img \
|
||||||
qemu-system-arm \
|
qemu-system-arm \
|
||||||
qemu-system-x86_64 \
|
qemu-system-x86_64 \
|
||||||
&& true
|
&& true
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT ["/qemu.sh"]
|
@ -1,14 +1,14 @@
|
|||||||
.PHONY: tag push
|
.PHONY: tag push
|
||||||
|
|
||||||
BASE=alpine:3.5
|
BASE=alpine:3.5
|
||||||
IMAGE=alpine-qemu
|
IMAGE=qemu
|
||||||
|
|
||||||
default: push
|
default: push
|
||||||
|
|
||||||
hash: Dockerfile
|
hash: Dockerfile qemu.sh
|
||||||
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
|
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
|
||||||
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
|
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
|
push: hash
|
||||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
41
base/qemu/qemu.sh
Executable file
41
base/qemu/qemu.sh
Executable 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 $*
|
Loading…
Reference in New Issue
Block a user