From 497b07e57b74d98958d956b52a2547071d04ae96 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 10 May 2017 23:32:25 +0100 Subject: [PATCH] Add a simple qemu guest agent package We don't actually build it here, we just use the alpine package, which is already included in the linuxkit/alpine base. Can be instantiated with a service stanza such as: - name: qemu-ga image: "linuxkit/qemu-ga:e5fbcf55926f6e1a96b3e49a392e547e8be1022c" binds: - /dev/vport0p1:/dev/vport0p1 The only functionality I've tested is to report IP addresses to the host (e.g. via `virsh domifaddr`). The image is configured to use `/dev/vport0p1` by default. If your VM image is using a different port number then you can either incorporate the rename into the bind ("/dev/vport1p1:/dev/vport0p1") or override the command with: command: ["/usr/bin/qemu-ga", "-p", "/dev/vport1p1"] The mdev tool appears to not create the symlinks which udev would provide `/dev/virtio-ports/org.qemu.guest_agent.0` hence the need to hardcode the potentially unstable `/dev/vportNp1`, `N` seems to depend on the number and order of virtio devices in use. I don't know if it is possible to get mdev to create these links. For reference the udev rule is: SUBSYSTEM=="virtio-ports", KERNEL=="vport*", ATTR{name}=="?*", SYMLINK+="virtio-ports/$attr{name}" See https://wiki.libvirt.org/page/Qemu_guest_agent for more info on the guest agent. A suitable stanza is added to `projects/swarmd/swarmd.yml` since that is where I am using it. Signed-off-by: Ian Campbell --- pkg/qemu-ga/Dockerfile | 12 ++++++++++++ pkg/qemu-ga/Makefile | 14 ++++++++++++++ projects/swarmd/swarmd.yml | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 pkg/qemu-ga/Dockerfile create mode 100644 pkg/qemu-ga/Makefile diff --git a/pkg/qemu-ga/Dockerfile b/pkg/qemu-ga/Dockerfile new file mode 100644 index 000000000..9691b25f4 --- /dev/null +++ b/pkg/qemu-ga/Dockerfile @@ -0,0 +1,12 @@ +FROM linuxkit/alpine:630ee558e4869672fae230c78364e367b8ea67a9 AS build +RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/ +RUN mkdir -p /out/var/run +RUN apk add --no-cache --initdb -p /out \ + qemu-guest-agent \ + musl +FROM scratch +WORKDIR / +ENTRYPOINT [] +COPY --from=build /out / +CMD ["/usr/bin/qemu-ga", "-p", "/dev/vport0p1"] +LABEL org.mobyproject.config='{"net": "host"}' diff --git a/pkg/qemu-ga/Makefile b/pkg/qemu-ga/Makefile new file mode 100644 index 000000000..d87500b3d --- /dev/null +++ b/pkg/qemu-ga/Makefile @@ -0,0 +1,14 @@ +.PHONY: tag push + +ORG?=linuxkit +IMAGE=qemu-ga + +HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') + +default: push + +tag: Dockerfile + docker build --network=none -t $(ORG)/$(IMAGE):$(HASH) . + +push: tag + docker pull $(ORG)/$(IMAGE):$(HASH) || docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/projects/swarmd/swarmd.yml b/projects/swarmd/swarmd.yml index 9e54c6229..f900af726 100644 --- a/projects/swarmd/swarmd.yml +++ b/projects/swarmd/swarmd.yml @@ -20,6 +20,10 @@ onboot: - name: metadata image: "linuxkit/metadata:b053fd6a945829bb626bb3546cad69aae0ff7803" services: + - name: qemu-ga + image: "linuxkit/qemu-ga:e5fbcf55926f6e1a96b3e49a392e547e8be1022c" + binds: + - /dev/vport0p1:/dev/vport0p1 - name: rngd image: "linuxkit/rngd:b67c3151a52b05db50e6207b40876900f2208d14" - name: ntpd