Makefile (1813B)
-include config.mk
-include boundary.mk
OPERATION ?=
VALID_OPERATIONS := APPLY DESTROY
NUMBER ?=
PORT ?=
ifeq ($(NUMBER),)
NUMBER = 2
endif
ifeq ($(PORT),)
PORT = 3313
endif
ifneq ($(OPERATION),APPLY)
ifneq ($(OPERATION),DESTROY)
$(error Invalid value for OPERATION: "$(OPERATION)". Must be "APPLY" or "DESTROY")
endif
endif
IS_MAXSCALE_ACTIVE := $(shell systemctl is-active maxscale)
ifneq ($(IS_MAXSCALE_ACTIVE),active)
$(error Maxscale service is not running, can not do service discovery)
endif
ifeq ($(OPERATION),APPLY)
TARGETS := build apply
else ifeq ($(OPERATION),DESTROY)
TARGETS := destroy
endif
operate: service_discovery
$(MAKE) execute_operation
#we need a dynamically generated value from a file, so we must call make from make to refresh state
execute_operation:
$(MAKE) $(TARGETS)
#checks maxctrl, tells what's currently running gives the number of current servers, and builds a locals.tf file
service_discovery:
rm -f boundary.mk
bash service_discovery.sh $(NUMBER) $(PORT) $(ROOT_SRC)
@echo "BOUNDARY=$$(cat boundary.txt)" > boundary.mk
#builds and transports the docker images to the target server, along with a fresh mysqldump
build:
bash init.sh $(TARGET_SRV) $(ROOT_SRC) $(REMOTE_DOCKER_DIR) $(REMOTE_DOCKER_SCRIPTS_DIR) $(DOCKER_BUILD)
#runs the new docker containers, updates maxscale
apply:
terraform init
terraform apply -var="target_ip=$(TARGET_SRV)" -var="docker_image=$(DOCKER_BUILD)"
bash create_maxscale.sh $(BOUNDARY) $(NUMBER) $(PORT) $(ROOT_SRC) $(TARGET_SRV)
#destroys the docker containers, updates maxscale
destroy:
bash destroy_maxscale.sh $(BOUNDARY) $(NUMBER) $(ROOT_SRC)
terraform destroy -var="target_ip=$(TARGET_SRV)" -var="docker_image=$(DOCKER_BUILD)"
.PHONY: service_discovery execute_operation operate build apply destroy