$DOCKERNET -> $KIWI_HUB_NAME, $DOCKERCIDR -> $KIWI_HUB_CIDR

This commit is contained in:
Jörn-Michael Miehe 2020-08-11 11:20:08 +02:00
parent 6ee528f4cb
commit 3522d6bba5
4 changed files with 22 additions and 22 deletions

View file

@ -23,15 +23,15 @@ CONF_SOURCE:=$(patsubst %,. %;,$(CONF_WILDC))
confvalue=$(shell $(CONF_SOURCE) echo -n $${$(1)})
# docker network name
CONF_DOCKERNET:=$(call confvalue,DOCKERNET)
ifeq ($(CONF_DOCKERNET),)
$(error DOCKERNET not set in $(CONF_WILDC))
CONF_KIWI_HUB_NAME:=$(call confvalue,KIWI_HUB_NAME)
ifeq ($(CONF_KIWI_HUB_NAME),)
$(error KIWI_HUB_NAME not set in $(CONF_WILDC))
endif
# docker network CIDR
CONF_DOCKERCIDR:=$(call confvalue,DOCKERCIDR)
ifeq ($(CONF_DOCKERNET),)
$(error DOCKERCIDR not set in $(CONF_WILDC))
CONF_KIWI_HUB_CIDR:=$(call confvalue,KIWI_HUB_CIDR)
ifeq ($(CONF_KIWI_HUB_CIDR),)
$(error KIWI_HUB_CIDR not set in $(CONF_WILDC))
endif
# persistent data directory
@ -56,7 +56,7 @@ endif
# CONSTANTS
# file to store docker network cidr
FILE_DOCKERNET:=$(CONF_TARGETROOT)/up-$(CONF_DOCKERNET)
KIWI_HUB_FILE:=$(CONF_TARGETROOT)/up-$(CONF_KIWI_HUB_NAME)
# remove any suffix $2 from $1
rmsuffix=$(patsubst %$2,%,$1)
@ -91,31 +91,31 @@ all: purge-conf up
#########
# manage the docker network (container name local DNS)
$(FILE_DOCKERNET):
$(KIWI_HUB_FILE):
-$(DOCKER) network create \
--driver bridge \
--internal \
--subnet "$(CONF_DOCKERCIDR)" \
"$(CONF_DOCKERNET)"
@echo "Creating canary $(FILE_DOCKERNET) ..."
--subnet "$(CONF_KIWI_HUB_CIDR)" \
"$(CONF_KIWI_HUB_NAME)"
@echo "Creating canary $(KIWI_HUB_FILE) ..."
@$(DOCKER) run --rm \
-v "/:/mnt" -u root alpine:latest \
ash -c '\
mkdir -p "$(addprefix /mnt, $(CONF_TARGETROOT))"; \
echo "$(CONF_DOCKERCIDR)" > "$(addprefix /mnt, $(FILE_DOCKERNET))"; \
echo "$(CONF_KIWI_HUB_CIDR)" > "$(addprefix /mnt, $(KIWI_HUB_FILE))"; \
'
.PHONY: net-up
net-up: $(FILE_DOCKERNET)
net-up: $(KIWI_HUB_FILE)
.PHONY: net-down
net-down: down
$(DOCKER) network rm "$(CONF_DOCKERNET)"
@echo "Removing canary $(FILE_DOCKERNET) ..."
$(DOCKER) network rm "$(CONF_KIWI_HUB_NAME)"
@echo "Removing canary $(KIWI_HUB_FILE) ..."
@$(DOCKER) run --rm \
-v "/:/mnt" -u root alpine:latest \
ash -c '\
rm -f "$(addprefix /mnt, $(FILE_DOCKERNET))"; \
rm -f "$(addprefix /mnt, $(KIWI_HUB_FILE))"; \
'
#########
@ -243,7 +243,7 @@ networks:
# interconnects projects
kiwihub:
external:
name: $$DOCKERNET
name: $$KIWI_HUB_NAME
services:
something:

View file

@ -1,7 +1,7 @@
export SUFFIX_PROJECT=.project
export SUFFIX_DOWN=.down
export DOCKERNET=kiwihub
export DOCKERCIDR=10.22.46.0/24
export KIWI_HUB_NAME=kiwihub
export KIWI_HUB_CIDR=10.22.46.0/24
export TARGETROOT=/tmp/kiwi

View file

@ -7,9 +7,9 @@ networks:
# interconnects projects
kiwihub:
external:
name: $DOCKERNET
name: $KIWI_HUB_NAME
services:
hello-world:
image: alpine:latest
command: sh -c 'while :; do echo Hello World; sleep 10; done'
command: sh -c 'while :; do echo Hello World "$$RANDOM"; sleep 10; done'

View file

@ -34,7 +34,7 @@ class LogsCommand(SubCommand):
project_dir = f'{project_name}{project_marker}'
environment = {
'DOCKERNET': config['network:name'],
'KIWI_NET_NAME': config['network:name'],
'COMPOSE_PROJECT_NAME': project_name
}