to filter all instances of a service
This commit is contained in:
parent
e0b4536873
commit
0ce7e710f5
@ -2,16 +2,30 @@
|
|||||||
|
|
||||||
[[ 0 -eq "$#" ]] && set -- start
|
[[ 0 -eq "$#" ]] && set -- start
|
||||||
|
|
||||||
ufw_docker_agent_image=192.168.56.120:5000/ufw-docker-agent
|
ufw_docker_agent=ufw-docker-agent
|
||||||
|
|
||||||
|
function ufw_update_service_instances() {
|
||||||
|
name="$1"
|
||||||
|
port="$2"
|
||||||
|
|
||||||
|
declare -a opts=("$name")
|
||||||
|
[[ "$port" = all ]] || opts+=("$port")
|
||||||
|
|
||||||
|
docker ps -qf "label=com.docker.swarm.service.name=${name}" |
|
||||||
|
while read name; do
|
||||||
|
echo ufw-docker allow "${opts[@]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
docker service inspect "$ufw_docker_agent" \
|
declare -p | sed -e '/^declare -x ufw_public_/!d' \
|
||||||
--format '{{range $k,$v:=.Spec.Labels}}{{$k}} {{$v}}{{"\n"}}{{end}}' |
|
-e 's/^declare -x ufw_public_//' \
|
||||||
while read label port; do
|
-e 's/="/ /' \
|
||||||
[[ -z "$label" ]] && continue
|
-e 's/"$//' |
|
||||||
name="${label#ufw.public.}"
|
while read name port; do
|
||||||
echo "${name}=$port"
|
echo "${name}=$port"
|
||||||
|
ufw_update_service_instances "${name}" "${port}"
|
||||||
done
|
done
|
||||||
docker events --format '{{.Time}} {{.Status}} {{.Actor.Attributes.name}}' --filter 'scope=local' --filter 'type=container' |
|
docker events --format '{{.Time}} {{.Status}} {{.Actor.Attributes.name}}' --filter 'scope=local' --filter 'type=container' |
|
||||||
while read time status name; do
|
while read time status name; do
|
||||||
|
Loading…
Reference in New Issue
Block a user