DEPLOY_START_DELAY = 0 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 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), \ scp cleanup.sh $(SSH_USER)@$(host):/$(DEPLOY_PATH)/$(DEPLOY_NAME); \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh cleanup.sh $(host)"; \ ) endif prepare: @- echo "\n### preparing ..." @- chmod 600 secrets.mk @- $(foreach host,$(DEPLOY_HOSTS), \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH); mkdir $(DEPLOY_NAME)"; \ ) 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), \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh pre-deploy.sh $(host); sh pre-deploy_$(host).sh"; \ ) endif post-deploy: ifdef DEPLOY_HOSTS @- echo "\n### running post-deploy script(s)" @- $(foreach host,$(DEPLOY_HOSTS), \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh post-deploy.sh $(host); sh post-deploy_$(host).sh"; \ ) endif pre-local: ifneq (,$(wildcard pre-local.sh)) @- echo "\n### running pre-local script" @- $(foreach host,$(DEPLOY_HOSTS), \ ./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), \ ./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), \ ssh $(SSH_USER)@$(host) "mkdir -p $(DEPLOY_PATH)/$(DEPLOY_NAME)"; \ rsync_xtra=`cat .rsync`; \ rsync_xtra_host=`cat .rsync_$(host)`; \ 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) && chmod o-r .env secrets*"; \ ) 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)"; \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); ./reload.sh"; \ ) else @- echo "\n### no reload script found" endif