Initial commit

master
Lauri Võsandi 2 years ago
commit 749b5d1b20
  1. 1
      .gitignore
  2. 5
      Dockerfile
  3. 21
      README.md
  4. 18
      docker-compose.yml
  5. 38
      entrypoint.sh

1
.gitignore vendored

@ -0,0 +1 @@
*.swp

@ -0,0 +1,5 @@
FROM alpine
RUN apk add qemu-system-x86_64 qemu-modules bash tcpdump
COPY entrypoint.sh /entrypoint.sh
COPY ifup.sh /ifup.sh
ENTRYPOINT /entrypoint.sh

@ -0,0 +1,21 @@
# Dockerized QEMU
Dockerized QEMU image for reproducibly testing stuff on Windows.
Prepare OS image as described below.
If OS image is mounted to the Docker container as read-only
it is first copied during Docker container launch.
Specify MAC address via environment variable `MAC`.
For more example see `docker-compose.yml`
# Windows template image preparation
Prepare the image using libvirt or similar where you can specify
virtio SCSI controller for storage.
For Windows 10 install also mount
[virtio SCSI and networking drivers ISO](https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md).
In Windows 10 partitioning wizard provide drivers from that ISO.
Install [OpenSSH server](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse).
Make sure OpenSSH starts during boot.
Insert Jenkins or your favourite CI/CD software SSH public key into the image.
Use the resulting virtual machine disk image with this Docker image.

@ -0,0 +1,18 @@
version: '3'
networks:
pub:
external: true
services:
app:
networks:
pub:
build:
context: .
privileged: true
restart: unless-stopped
volumes:
- /home/lauri/test.bin:/data/image.bin:ro
tmpfs:
- /tmp
environment:
- MAC=52:54:00:5e:00:05

@ -0,0 +1,38 @@
#!/bin/bash
set -x
set -e
# Source image path
IMAGE=/data/image.bin
# TODO: With QEMU snapshots instead
if [ ! -w $IMAGE ]; then
echo "Data volume is not writable, assuming discardable VM and copying to tmpfs"
cp $IMAGE /tmp/image.bin
IMAGE=/tmp/image.bin
fi
# Create macvlan interface on Docker's eth0
ip link add link eth0 name macvtap0 type macvtap mode bridge
ip link set dev macvtap0 address ${MAC:?}
ip link set macvtap0 up
# No udev in Docker
IFS=: read major minor < <(cat /sys/devices/virtual/net/macvtap0/tap*/dev)
mknod "/dev/tap$(cat /sys/class/net/macvtap0/ifindex)" c $major $minor
# Launch QEMU instance
/usr/bin/qemu-system-x86_64 \
-machine pc-i440fx-4.2,accel=kvm \
-m 8192 \
-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x6 \
-blockdev "{\"driver\":\"file\",\"filename\":\"$IMAGE\",\"node-name\":\"libvirt-1-storage\",\"auto-read-only\":true,\"discard\":\"unmap\"}" \
-blockdev "{\"node-name\":\"libvirt-1-format\",\"read-only\":false,\"driver\":\"raw\",\"file\":\"libvirt-1-storage\"}" \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-1-format,id=scsi0-0-0-0,bootindex=2 \
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=$(cat /sys/class/net/macvtap0/address) \
-device virtio-balloon-pci \
-usb \
-device usb-ehci,id=ehci \
-device usb-tablet,bus=usb-bus.0 \
-vnc :0 \
-netdev tap,id=hostnet0,vhost=on,fd=9 9<>/dev/tap$(cat /sys/class/net/macvtap0/ifindex)
Loading…
Cancel
Save