From 4335d6fb82186b8f4c6a706561171a230d550f4a Mon Sep 17 00:00:00 2001 From: Patrice Brend'amour Date: Tue, 21 Sep 2021 23:58:34 +0200 Subject: [PATCH] applied requested changes --- Vagrantfile | 26 ++++++++++++++++++++++++++ ufw-docker | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index fa062d9..c07b29b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -125,6 +125,29 @@ DOCKERFILE ufw-docker allow public_webapp SHELL + master.vm.provision "multiple-network", type: 'shell', inline: <<-SHELL + set -euo pipefail + if ! docker network ls | grep -F foo-internal; then + docker network create --internal foo-internal + fi + if ! docker network ls | grep -F bar-external; then + docker network create bar-external + fi + + for app in internal-multinet-app:7000 public-multinet-app:17070; do + if ! docker inspect "${app%:*}" &>/dev/null; then + docker run -d --restart unless-stopped --name "${app%:*}" \ + -p "${app#*:}":80 --env name="${app}" \ + --network foo-internal \ + 192.168.56.130:5000/chaifeng/hostname-webapp + docker network connect bar-external "${app%:*}" + fi + done + + ufw-docker allow public-multinet-app 80 bar-external + ufw-docker allow internal-multinet-app 80 foo-internal + SHELL + master.vm.provision "swarm-webapp", type: 'shell', inline: <<-SHELL set -euo pipefail for name in public:29090 local:9000; do @@ -166,6 +189,9 @@ DOCKERFILE test-webapp "$server:18080" ! test-webapp "$server:8000" + test-webapp "$server:17070" # multiple networks app + ! test-webapp "$server:7000" # internal multiple networks app + test-webapp "$server:29090" ! test-webapp "$server:9000" diff --git a/ufw-docker b/ufw-docker index d49770b..bfa3399 100755 --- a/ufw-docker +++ b/ufw-docker @@ -107,7 +107,7 @@ function ufw-docker--add-rule() { local INSTANCE_IP_ADDRESS="$2" local PORT="$3" local PROTO="$4" - local NETWORK="$5" + local NETWORK="${5:-}" declare comment