Initial commit
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| *.swp | ||||
							
								
								
									
										5
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										21
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -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. | ||||
							
								
								
									
										18
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										38
									
								
								entrypoint.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										38
									
								
								entrypoint.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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) | ||||
		Reference in New Issue
	
	Block a user