161 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			161 lines
		
	
	
	
		
			4.6 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
DEPLOY_START_DELAY = 0
 | 
						|
DEPLOY_PROJECT_DIR =
 | 
						|
 | 
						|
MANDATORY = DEPLOY_NAME DEPLOY_HOSTS DEPLOY_PATH SSH_USER
 | 
						|
 | 
						|
-include secrets.mk
 | 
						|
include config.mk
 | 
						|
-include $(DEPLOY_CONFIG_OVERRIDE)
 | 
						|
 | 
						|
# copy ist jetzt simple
 | 
						|
ifeq ($(DEPLOY_TYPE), copy)
 | 
						|
	DEPLOY_TYPE = simple
 | 
						|
endif
 | 
						|
 | 
						|
project_dir = $(DEPLOY_PATH)/$(DEPLOY_NAME)$(DEPLOY_PROJECT_DIR)
 | 
						|
 | 
						|
include make-deploy/$(DEPLOY_TYPE).mk
 | 
						|
 | 
						|
.PHONY: self-update mandatory cleanup prerequisites prepare build test deploy pre-deploy post-deploy pre-local post-local upload pull start stop restart reload notify
 | 
						|
 | 
						|
self-update:
 | 
						|
	@- git submodule update --remote
 | 
						|
 | 
						|
deploy: mandatory cleanup prepare build test upload pre-deploy pre-local pull start notify post-local post-deploy reload
 | 
						|
 | 
						|
mandatory:
 | 
						|
	@- echo "\n### mandatory check"
 | 
						|
	@ $(foreach var,$(MANDATORY), \
 | 
						|
		if test -z "${$(var)}"; then \
 | 
						|
			echo "Missing mandatory variable: $(var)"; \
 | 
						|
			exit 1; \
 | 
						|
		fi; \
 | 
						|
	)
 | 
						|
 | 
						|
prerequisites:
 | 
						|
	@- echo "\n### prerequisites ..."
 | 
						|
	@- ./prerequisites.sh
 | 
						|
 | 
						|
ifdef DEPLOY_CLEANUP
 | 
						|
cleanup:
 | 
						|
	@- echo "\n### cleanup ..."
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		scp cleanup.sh $(SSH_USER)@$(host):/$(DEPLOY_PATH)/$(DEPLOY_NAME); \
 | 
						|
		if [ -e cleanup.sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh cleanup.sh $(host)"; fi; \
 | 
						|
	)
 | 
						|
endif
 | 
						|
 | 
						|
prepare:
 | 
						|
	@- echo "\n### preparing ..."
 | 
						|
	@- chmod 600 secrets.mk
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH); if [ ! -d $(DEPLOY_NAME) ] ; then mkdir $(DEPLOY_NAME); fi"; \
 | 
						|
	)
 | 
						|
	
 | 
						|
build:
 | 
						|
ifneq (,$(wildcard build.sh))
 | 
						|
	@- echo "\n### running build script"
 | 
						|
	@ ./build.sh
 | 
						|
else
 | 
						|
	@- echo "\n### no build script found"
 | 
						|
endif
 | 
						|
 | 
						|
test:
 | 
						|
ifneq (,$(wildcard test.sh))
 | 
						|
	@- echo "\n### running test script"
 | 
						|
	@ ./test.sh
 | 
						|
else
 | 
						|
	@- echo "\n### no test script found"
 | 
						|
endif
 | 
						|
 | 
						|
pre-deploy:
 | 
						|
ifdef DEPLOY_HOSTS
 | 
						|
	@- echo "\n### running pre-deploy script(s)"
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		if [ -e pre-deploy.sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh pre-deploy.sh $(host)"; fi; \
 | 
						|
		if [ -e pre-deploy_$(host).sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh pre-deploy_$(host).sh"; fi; \
 | 
						|
	)
 | 
						|
endif
 | 
						|
 | 
						|
post-deploy:
 | 
						|
ifdef DEPLOY_HOSTS
 | 
						|
	@- echo "\n### running post-deploy script(s)"
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		if [ -e post-deploy.sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh post-deploy.sh $(host)"; fi; \
 | 
						|
		if [ -e post-deploy_$(host).sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh post-deploy_$(host).sh"; fi; \
 | 
						|
	)
 | 
						|
endif
 | 
						|
 | 
						|
pre-local:
 | 
						|
ifneq (,$(wildcard pre-local.sh))
 | 
						|
	@- echo "\n### running pre-local script"
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		./pre-local.sh $(host); \
 | 
						|
	)
 | 
						|
else
 | 
						|
	@- echo "\n### no pre-local script found"
 | 
						|
endif
 | 
						|
 | 
						|
post-local:
 | 
						|
ifneq (,$(wildcard post-local.sh))
 | 
						|
	@- echo "\n### running post-local script"
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		./post-local.sh $(host); \
 | 
						|
	)
 | 
						|
else
 | 
						|
	@- echo "\n### no post-local script found"
 | 
						|
endif
 | 
						|
 | 
						|
upload:
 | 
						|
ifdef DEPLOY_HOSTS
 | 
						|
	@- echo "\n### uploading files"
 | 
						|
	@$(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "#host: $(host)"; \
 | 
						|
		ssh $(SSH_USER)@$(host) "if [ ! -d $(DEPLOY_PATH)/$(DEPLOY_NAME) ]; then mkdir -p $(DEPLOY_PATH)/$(DEPLOY_NAME); fi"; \
 | 
						|
		if [ -r .rsync ] ; then rsync_xtra=`cat .rsync`; fi; \
 | 
						|
		if [ -r .rsync_$(host) ] ; then rsync_xtra_host=`cat .rsync_$(host)`; fi; \
 | 
						|
		param="-ravv"; \
 | 
						|
		param="$$param $$rsync_xtra"; \
 | 
						|
		param="$$param $$rsync_xtra_host"; \
 | 
						|
		param="$$param --exclude '*~' --exclude '.git*' --exclude '*.swp' . $(SSH_USER)@$(host):$(DEPLOY_PATH)/$(DEPLOY_NAME)"; \
 | 
						|
		eval rsync $$param; \
 | 
						|
		ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); if [ -e .env ]; then chmod o-r .env ; fi; if [ -e secrets.mk ]; then chmod o-r secrets.mk; fi; if [ -e secrets.yaml ]; then chmod o-r secrets.yaml; fi"; \
 | 
						|
	)
 | 
						|
endif
 | 
						|
 | 
						|
pull: pull-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
start: start-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
stop: stop-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
notify:
 | 
						|
ifdef DEPLOY_NOTIFY_HOSTS
 | 
						|
ifdef DEPLOY_NOTIFY_MAIL
 | 
						|
ifdef DEPLOY_NOTIFY_MSG
 | 
						|
	@- echo "\n### notify"
 | 
						|
	@- echo "$$DEPLOY_NOTIFY_MSG :: Please deploy manually on following hosts: $$DEPLOY_NOTIFY_HOSTS" | mail -s "make-deploy notification" $(DEPLOY_MAIL)
 | 
						|
endif
 | 
						|
endif
 | 
						|
endif
 | 
						|
 | 
						|
logs: logs-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
restart: restart-$(DEPLOY_TYPE)
 | 
						|
	
 | 
						|
reload:
 | 
						|
ifneq (,$(wildcard reload.sh))
 | 
						|
	@- echo "\n### reloading ..."
 | 
						|
	@ $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		echo "### reloading service on $(host)"; \
 | 
						|
		if [ -e reload.sh ]; then ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); ./reload.sh"; fi; \
 | 
						|
	)
 | 
						|
else
 | 
						|
	@- echo "\n### no reload script found"
 | 
						|
endif
 |