Healthcheck

This commit is contained in:
Kroese 2023-04-21 08:39:07 +02:00 committed by GitHub
commit f2b1615f07
3 changed files with 30 additions and 1 deletions

View File

@ -36,6 +36,7 @@ COPY agent/*.sh /agent/
COPY --from=builder /src/serial/main /run/serial.bin
RUN ["chmod", "+x", "/run/run.sh"]
RUN ["chmod", "+x", "/run/check.sh"]
RUN ["chmod", "+x", "/run/server.sh"]
RUN ["chmod", "+x", "/run/serial.bin"]
@ -68,6 +69,6 @@ LABEL org.opencontainers.image.version=${VERSION_ARG}
LABEL org.opencontainers.image.url=https://hub.docker.com/r/kroese/virtual-dsm/
LABEL org.opencontainers.image.source=https://github.com/kroese/virtual-dsm/
HEALTHCHECK --interval=30s --timeout=2s CMD curl -ILfSs http://20.20.20.21:5000/ || exit 1
HEALTHCHECK --interval=30s --retries=1 CMD /run/check.sh
ENTRYPOINT ["/run/run.sh"]

22
run/check.sh Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eu
# Docker Healthcheck
PORT=5000
FILE="/var/dsm.ip"
if [ ! -f "${FILE}" ]; then
echo "IP not assigned"
exit 1
fi
IP=$(cat "${FILE}")
if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/"; then
echo "Failed to reach ${IP}"
exit 1
fi
echo "Healthcheck OK for ${IP}"
exit 0

View File

@ -46,6 +46,9 @@ configureDHCP() {
echo "ERROR: Cannot retrieve IP from DHCP using MAC ${VM_NET_MAC}" && exit 16
fi
# Store IP for Docker healthcheck
echo "${DHCP_IP}" > "/var/dsm.ip"
ip a flush "${VM_NET_TAP}"
TAP_PATH="/dev/tap$(</sys/class/net/${VM_NET_TAP}/ifindex)"
@ -83,6 +86,9 @@ configureNAT () {
VM_NET_IP='20.20.20.21'
VM_NET_TAP="_VmNatTap"
# Store IP for Docker healthcheck
echo "${VM_NET_IP}" > "/var/dsm.ip"
#Create bridge with static IP for the VM guest
brctl addbr dockerbridge
ip addr add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge