mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-12-01 14:16:50 +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:
13
base/qemu/Dockerfile
Normal file
13
base/qemu/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
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"]
|
||||
29
base/qemu/Makefile
Normal file
29
base/qemu/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
.PHONY: tag push
|
||||
|
||||
BASE=alpine:3.5
|
||||
IMAGE=qemu
|
||||
|
||||
default: push
|
||||
|
||||
hash: Dockerfile qemu.sh
|
||||
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
|
||||
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
|
||||
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) || \
|
||||
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
|
||||
docker push mobylinux/$(IMAGE):$(shell cat hash))
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
tag: hash
|
||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
clean:
|
||||
rm -f hash
|
||||
|
||||
.DELETE_ON_ERROR:
|
||||
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 $*
|
||||
Reference in New Issue
Block a user