update docker images
This commit is contained in:
+15
-14
@@ -1,21 +1,22 @@
|
||||
FROM consul:1.6.1 as dist
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
FROM consul:1.11.1 as dist
|
||||
LABEL maintainer aynic.os <support+docker@asycn.io>
|
||||
ARG DOCKER_BUILD_DIR
|
||||
ARG DOCKER_GID=999
|
||||
|
||||
# install docker
|
||||
RUN apk add --no-cache bash docker gawk sudo \
|
||||
&& echo "consul ALL=(root) NOPASSWD: /usr/local/bin/container-list-status" >> /etc/sudoers
|
||||
# add user consul in group docker
|
||||
RUN DOCKER_GROUP=$(awk -F: '$3 == '${DOCKER_GID}' {print $1}' < /etc/group) \
|
||||
&& if [ -n "${DOCKER_GROUP}" ]; then adduser consul ${DOCKER_GROUP}; \
|
||||
else addgroup -g ${DOCKER_GID} docker && adduser consul docker; \
|
||||
fi
|
||||
|
||||
# install goss
|
||||
ADD https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 /usr/bin/goss
|
||||
RUN chmod +rx /usr/bin/goss
|
||||
COPY ${DOCKER_BUILD_DIR}/goss.yml /tests/goss.yml
|
||||
COPY ${DOCKER_BUILD_DIR}/docker-healthcheck /usr/local/bin/
|
||||
RUN chmod +rx /usr/local/bin/docker-healthcheck
|
||||
|
||||
COPY ${DOCKER_BUILD_DIR}/container-check-status ${DOCKER_BUILD_DIR}/container-list-status /usr/local/bin/
|
||||
RUN chmod +rx /usr/local/bin/container-check-status /usr/local/bin/container-list-status
|
||||
|
||||
HEALTHCHECK CMD goss -g /tests/goss.yml validate --format tap
|
||||
HEALTHCHECK CMD ((((echo -e 'GET /v1/health/service/consul HTTP/1.0\n' \
|
||||
|nc -w 1 localhost:8500; echo $? >&3) \
|
||||
|sed -n '/^\[/,$p' \
|
||||
|jq '.[].Checks[0].Output' >&4) 3>&1) \
|
||||
| (read err; exit $err)) 4>&1
|
||||
|
||||
FROM dist as master
|
||||
ARG DOCKER_BUILD_DIR
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
# https://github.com/hashicorp/consul/issues/3182
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
>&2 echo "Invalid parameters: '$@'"
|
||||
echo "USAGE: $0 <container-id|container-name|container-hostname|container-ip>"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
CONTAINER_ID="$1"
|
||||
# CONTAINER_STATUS=$(sudo container-list-status |awk '/\<'${CONTAINER_ID}'\>/ {print $NF}')
|
||||
read -d "\n" CONTAINER_STATUS CONTAINER_OUTPUT <<< $(sudo container-list-status |awk 'BEGIN {FS="\t"; RS="\0"} /\<'${CONTAINER_ID}'\>/ {print $1,$NF}')
|
||||
|
||||
echo ${CONTAINER_STATUS:-undefined}: "${CONTAINER_OUTPUT}"
|
||||
case "${CONTAINER_STATUS}" in
|
||||
healthy)
|
||||
exit 0
|
||||
;;
|
||||
starting)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 2
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
# https://github.com/hashicorp/consul/issues/3182
|
||||
|
||||
# docker inspect -f '{{.Id}} {{.Config.Hostname}} {{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}} {{.State.Health.Status}}' $(docker ps -q) 2>/dev/null
|
||||
docker container inspect --format '{{.State.Health.Status}}{{printf "\t"}}{{.Id}}{{printf "\t"}}{{.Name}}{{printf "\t"}}{{.Config.Hostname}}{{printf "\t"}}{{range .NetworkSettings.Networks}}{{.IPAddress}}{{printf "\t"}}{{end}}{{printf "\t"}}{{$output := ""}}{{range .State.Health.Log}}{{$output = .Output}}{{end}}{{$output}}{{printf "%c" 0}}' $(docker ps -q) 2>/dev/null
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
# link: https://github.com/hashicorp/consul/issues/3182
|
||||
# author: Yann "aya" Autissier
|
||||
# license: GPL
|
||||
set -eu
|
||||
|
||||
DOCKER_SOCK=${DOCKER_SOCK:-/var/run/docker.sock}
|
||||
|
||||
if ! which curl > /dev/null || ! which jq >/dev/null; then
|
||||
>&2 echo "ERROR: curl or jq not found"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
>&2 echo "ERROR: invalid parameter '$*'"
|
||||
echo "USAGE: $0 container-id|container-name|container-ip"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
{
|
||||
{
|
||||
{
|
||||
# list all dockers
|
||||
for docker in $(curl --disable --fail --show-error --silent --unix-socket "${DOCKER_SOCK}" http://localhost/containers/json |jq -r '.[].Id'); do
|
||||
# print "health_status id name ip_address health_output" for each docker
|
||||
curl --disable --fail --show-error --silent --unix-socket "${DOCKER_SOCK}" "http://localhost/containers/${docker}/json" \
|
||||
|jq -r '[.State.Health.Status, .Id, .Name, .NetworkSettings.IPAddress, .State.Health.Log[0].Output] |@tsv'
|
||||
# shorten id: .Id |capture("(?<id>.{12})").id
|
||||
# print "health_status" and "health_output" for line matching $1
|
||||
done |awk -F '\t' '/\<'"$1"'\>/ {print $1 | "cat >&3; exec 3>&-"; print $NF | "cat >&4";}'
|
||||
} 3>&1
|
||||
} | {
|
||||
read -r status ||:
|
||||
case "$status" in
|
||||
healthy) exit=0;;
|
||||
starting) exit=1;;
|
||||
*) exit=2;;
|
||||
esac
|
||||
# exit according to "health_status"
|
||||
exit $exit
|
||||
}
|
||||
# print "health_output"
|
||||
} 4>&1
|
||||
@@ -1,18 +0,0 @@
|
||||
file:
|
||||
/bin/consul:
|
||||
exists: true
|
||||
filetype: file
|
||||
mode: "0755"
|
||||
owner: root
|
||||
sha256: 99bacb9dc1c6b7eaff75326e4ae0396ac2f29eb8ab95bc2124c718d926c3aef4
|
||||
port:
|
||||
tcp6:8500:
|
||||
listening: true
|
||||
ip:
|
||||
process:
|
||||
consul:
|
||||
running: true
|
||||
user:
|
||||
consul:
|
||||
exists: true
|
||||
uid: 100
|
||||
Reference in New Issue
Block a user