Skip to content

Instantly share code, notes, and snippets.

@dcode
Created June 2, 2020 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcode/7e734ab3a519ee7ea913a8d8006c4ef0 to your computer and use it in GitHub Desktop.
Save dcode/7e734ab3a519ee7ea913a8d8006c4ef0 to your computer and use it in GitHub Desktop.
Fedora CoreOS CT snippet and dockerfile to run open-vm-tools in a container for VMware guests
FROM fedora:31
LABEL summary="The open-vm-tools guest agent" \
io.k8s.description="The open-vm-tools agent is providing information about the virtual machine and allows to restart / shutdown the machine via VMware products. This image is intended to be used with virtual machines running Centos Atomic Host." \
io.k8s.display-name="open-vm-tools guest agent" \
architecture="x86_64" \
BZComponent="open-vm-tools" \
maintainer="davis phillips <dphillip@redhat.com>"
ENV SYSTEMD_IGNORE_CHROOT=1
RUN dnf -y --setopt=tsflags=nodocs --setopt=override_install_langs=en_US.utf8 --setopt=install_weak_deps=False install file open-vm-tools net-tools iproute systemd -x gcc && \
dnf clean all
COPY service.template config.json.template /exports/
LABEL RUN="docker run --privileged -v /proc/:/hostproc/ -v /sys/fs/cgroup:/sys/fs/cgroup -v /var/log:/var/log -v /run/systemd:/run/systemd -v /sysroot:/sysroot -v=/var/lib/sss/pipes/:/var/lib/sss/pipes/:rw -v /etc/passwd:/etc/passwd -v /etc/shadow:/etc/shadow -v /tmp:/tmp:rw -v /etc/sysconfig:/etc/sysconfig:rw -v /etc/resolv.conf:/etc/resolv.conf:rw -v /etc/nsswitch.conf:/etc/nsswitch.conf:rw -v /etc/hosts:/etc/hosts:rw -v /etc/hostname:/etc/hostname:rw -v /etc/localtime:/etc/localtime:rw -v /etc/adjtime:/etc/adjtime --env container=docker --net=host --pid=host IMAGE"
CMD /usr/bin/vmtoolsd
%YAML 1.1
---
variant: fcos
version: 1.0.0
systemd:
units:
- name: vmtoolsd.service
enabled: true
contents: |
[Unit]
Description=Service for virtual machines hosted on VMware
Documentation=http://github.com/vmware/open-vm-tools
ConditionVirtualization=vmware
Requires=network-online.target
After=network-online.target
[Service]
Environment=CONTAINER=quay.io/dcode/open-vm-tools
Environment=TAG=master
ExecStartPre=-/usr/bin/podman rm -f %n
ExecStartPre=-/usr/bin/rm -f %t/%p/%n-pid %t/%p/%n-cid
ExecStart=/usr/bin/podman run --name %n\
--conmon-pidfile %t/%p/%n-pid --cidfile %t/%p/%n-cid \
--detach \
-v /run/systemd:/run/systemd \
-v /etc/adjtime:/etc/adjtime \
-v /etc/hosts:/etc/hosts \
-v /tmp:/tmp \
-v /etc/sysconfig:/etc/sysconfig \
-v /etc/resolv.conf:/etc/resolv.conf \
-v /etc/shadow:/etc/shadow \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-v /proc/:/hostproc \
-v /sysroot:/sysroot \
-v /etc/passwd:/etc/passwd \
-v /usr/share/zoneinfo:/usr/share/zoneinfo \
-v /var/lib/sss/pipes:/var/lib/sss/pipes \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
-v /etc/hostname:/etc/hostname:rw \
-v /var/log:/var/log:rw \
-v /:/host \
-v /dev/rtc:/dev/rtc:rw \
-v /proc:/proc \
--pid=host \
--net=host \
--ipc=host \
--uts=host \
--privileged \
--log-driver=journald \
--log-opt=tag="{{ .Name }}" \
"${CONTAINER}":"${TAG}"
ExecStop=/usr/bin/sh -c "/usr/bin/podman rm -f $(cat %t/%p/%n-cid)"
KillMode=none
Type=forking
RuntimeDirectory=%p
PIDFile=%t/%p/%n-pid
TimeoutStopSec=5
TimeoutStartSec=300
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- name: vmtoolsd-hostname.service
enabled: true
contents: |
[Unit]
Description=Set system hostname from vmware info
Requires=vmtoolsd.service
After=vmtoolsd.service
ConditionVirtualization=vmware
[Service]
Type=oneshot
RemainAfterExit=true
Environment=ATTRIBUTES=/run/metadata/afterburn
ExecStart=/bin/bash -c '/usr/bin/hostnamectl set-hostname $(/usr/bin/podman exec vmtoolsd.service /usr/bin/vmware-rpctool "info-get guestinfo.hostname")'
ExecStart=/bin/bash -c 'echo -e "AFTERBURN_CUSTOM_HOSTNAME=$(cat /etc/hostname)" >> $${ATTRIBUTES}'
[Install]
WantedBy=multi-user.target
WantedBy=metadata.target
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment