Skip to content
Snippets Groups Projects
Commit 2d366c40 authored by Corné Lukken's avatar Corné Lukken
Browse files

L2SS-988: Do not use individual targets for await target

parent 3a20625a
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ ATTACH_COMPOSE_FILE_ARGS := $(foreach yml,$(filter-out tango.yml,$(COMPOSE_FILES ...@@ -13,6 +13,9 @@ ATTACH_COMPOSE_FILE_ARGS := $(foreach yml,$(filter-out tango.yml,$(COMPOSE_FILES
# But we allow to overwrite it. # But we allow to overwrite it.
NETWORK_MODE ?= tangonet NETWORK_MODE ?= tangonet
# Timeout used to await services to become healthy
TIMEOUT ?= 300
SCRATCH ?= /tmp SCRATCH ?= /tmp
# Host name through which others can reach our control interfaces. # Host name through which others can reach our control interfaces.
...@@ -52,7 +55,6 @@ else ifeq (attach,$(firstword $(MAKECMDGOALS))) ...@@ -52,7 +55,6 @@ else ifeq (attach,$(firstword $(MAKECMDGOALS)))
endif endif
else ifeq (await,$(firstword $(MAKECMDGOALS))) else ifeq (await,$(firstword $(MAKECMDGOALS)))
SERVICE_TARGET = true SERVICE_TARGET = true
WAIT = true
else ifeq (run,$(firstword $(MAKECMDGOALS))) else ifeq (run,$(firstword $(MAKECMDGOALS)))
RUN_TARGET = true RUN_TARGET = true
else ifeq (integration,$(firstword $(MAKECMDGOALS))) else ifeq (integration,$(firstword $(MAKECMDGOALS)))
...@@ -62,11 +64,7 @@ endif ...@@ -62,11 +64,7 @@ endif
ifdef SERVICE_TARGET ifdef SERVICE_TARGET
# .. then use the rest as arguments for the make target # .. then use the rest as arguments for the make target
SERVICE := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) SERVICE := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
ifdef WAIT
AWAITS := $(SERVICE)
endif
# ...and turn them into do-nothing targets # ...and turn them into do-nothing targets
$(eval $(AWAITS):;@:)
$(eval $(SERVICE):;@:) $(eval $(SERVICE):;@:)
else ifdef RUN_TARGET else ifdef RUN_TARGET
# Isolate second argument as service, the rest is arguments for run command # Isolate second argument as service, the rest is arguments for run command
...@@ -226,23 +224,19 @@ restart: ## restart a service (usage: make restart <servicename>) ...@@ -226,23 +224,19 @@ restart: ## restart a service (usage: make restart <servicename>)
attach: ## attach a service to an existing Tango network attach: ## attach a service to an existing Tango network
$(DOCKER_COMPOSE_ARGS) docker-compose $(ATTACH_COMPOSE_FILE_ARGS) up --no-recreate -d $(SERVICE) $(DOCKER_COMPOSE_ARGS) docker-compose $(ATTACH_COMPOSE_FILE_ARGS) up --no-recreate -d $(SERVICE)
await: $(AWAITS) await: ## Await every container with total max timeout of 300, do not reset timeout
time=0
# Await every container with total max timeout of 300, do not reset timeout for i in $(SERVICE); do \
# in between containers. current_service=$$($(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) ps -q $${i}); \
# Awaiting for ready is done through inspecting health status
timeout ?= 300
time := 0
$(AWAITS):
timeout=$(timeout); \
current_service=$$($(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) ps -q $@); \
while [ "`docker inspect -f {{.State.Health.Status}} $${current_service}`" != "healthy" ] ; do \ while [ "`docker inspect -f {{.State.Health.Status}} $${current_service}`" != "healthy" ] ; do \
sleep 1; \ sleep 1; \
time=`expr $$time + 1`; \ time=`expr $$time + 1`; \
if [ $${time} -gt $${timeout} ]; then \ if [ $${time} -gt $${TIMEOUT} ]; then \
echo "Timeout reached waiting for $@ to become healthy"; \ echo "Timeout reached waiting for $${i} to become healthy"; \
exit 1; \ exit 1; \
fi; \ fi; \
done; \
echo "Service $${i} is healthy"; \
done done
status: ## show the container status status: ## show the container status
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment