Skip to content

Commit 7115051

Browse files
committed
Deploy rabbit only if necessary
1 parent f649f0c commit 7115051

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

services/rabbit/Makefile

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,20 @@ include ${REPO_BASE_DIR}/scripts/common.Makefile
99
# Running cluster
1010
#
1111

12+
STACK_IS_RUNNING := $(shell docker stack ls --format '{{.Name}}' | grep -q "^$(STACK_NAME)$$" && echo true || echo false)
13+
1214
.PHONY: up
13-
up: ${TEMP_COMPOSE} prune-docker-stack-configs prune-docker-stack-secrets ## Deploy rabbit
14-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
15+
up: ${TEMP_COMPOSE} \
16+
prune-docker-stack-configs \
17+
prune-docker-stack-secrets \
18+
guard-optional-bool-FORCE
19+
up: ## Deploy rabbit
20+
@if [ "$(STACK_IS_RUNNING)" = "false" ] || [ "$(FORCE)" = "true" ] ; then \
21+
docker stack deploy --detach=false --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}; \
22+
else \
23+
echo "Stack $(STACK_NAME) is already running. To avoid unexpected behavior, skipping deploy"; \
24+
echo "Check README to learn more about updates. To enforce deploy, use 'FORCE=true'"; \
25+
fi
1526

1627
up-aws: up
1728

@@ -55,6 +66,8 @@ configs/haproxy.cfg: configs/haproxy.cfg.j2 .env venv
5566
# Deleting volumes (data)
5667
#
5768

69+
### May be needed to start cluster fresh new to enforce new configuration
70+
5871
CLEAN_VOLUMES_TEMP_COMPOSE := .stack.${STACK_NAME}.clean-volumes.yaml
5972
CLEAN_VOLUMES_STACK_NAME := ${STACK_NAME}-clean-volumes
6073

@@ -67,20 +80,24 @@ ${CLEAN_VOLUMES_TEMP_COMPOSE}: docker-compose.clean-volumes.yaml .env
6780
TIMEOUT = 2m
6881
delete-volumes: ${CLEAN_VOLUMES_TEMP_COMPOSE} guard-optional-TIMEOUT guard-optional-bool-FORCE_CONFIRM
6982
delete-volumes: ## Delete rabbit data volumes
70-
@$(call confirm_action,Forever delete all rabbit data?,yes,${FORCE_CONFIRM})
83+
@$(call confirm_action,Forever delete all rabbit data?,deleteforever,${FORCE_CONFIRM})
84+
7185
## avoid accumulating tasks https://github.com/moby/moby/issues/45443
7286
@docker stack rm --detach=false ${CLEAN_VOLUMES_STACK_NAME}
87+
7388
## use --detach=false to wait until all jobs complete successfully
7489
@timeout ${TIMEOUT} \
7590
docker stack deploy --detach=false --with-registry-auth --prune --compose-file ${CLEAN_VOLUMES_TEMP_COMPOSE} ${CLEAN_VOLUMES_STACK_NAME}
91+
92+
## cleaning up
7693
@docker stack rm ${CLEAN_VOLUMES_STACK_NAME}
7794

7895
#
7996
# Destroy cluster with data (to start fresh new)
8097
#
8198

8299
down: guard-optional-bool-FORCE_CONFIRM ## Stop rabbit cluster
83-
@$(call confirm_action,Are you sure you want to stop the Rabbit cluster?,yes,${FORCE_CONFIRM})
100+
@$(call confirm_action,Are you sure you want to stop the Rabbit cluster?,stopcluster,${FORCE_CONFIRM})
84101
@docker stack rm ${STACK_NAME}
85102

86103
destroy-cluster-with-data: down delete-volumes ## Destroy rabbit cluster with data

services/rabbit/docker-compose.clean-volumes.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
services:
44

5-
{% for ix in NODE_IXS %}
5+
{%- for ix in NODE_IXS %}
66
clean_rabbit0{{ ix }}_volume:
77
image: docker:25.0.3-cli
88
volumes:

services/rabbit/docker-compose.yml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ services:
5555
reservations:
5656
cpus: "1.0"
5757
memory: "1G"
58+
update_config:
59+
order: "stop-first"
5860
environment:
5961
# https://www.rabbitmq.com/docs/configure#supported-environment-variables
6062
RABBITMQ_DEFAULT_USER: ${RABBIT_USER}

0 commit comments

Comments
 (0)