126 lines
3.0 KiB
Makefile
126 lines
3.0 KiB
Makefile
DEPLOY_START_DELAY = 0
|
|
|
|
-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 prerequisites prepare build test deploy pre-deploy post-deploy pre-local post-local upload pull start stop restart reload
|
|
|
|
self-update:
|
|
@- git submodule update --remote
|
|
|
|
deploy: mandatory prepare build test upload pre-deploy pre-local pull start post-local post-deploy reload
|
|
|
|
mandatory:
|
|
@- echo "\n### mandatory check"
|
|
ifndef MANDATORY-$(DEPLOY_TYPE)
|
|
$(error MANDATORY-$(DEPLOY_TYPE) is not defined)
|
|
endif
|
|
@ $(foreach var,$(MANDATORY), \
|
|
if test -z "${$(var)}"; then \
|
|
echo "Missing mandatory variable: $(var)"; \
|
|
exit 1; \
|
|
fi; \
|
|
)
|
|
|
|
prerequisites:
|
|
@- echo "\n### prerequisites ..."
|
|
@- ./prerequisites.sh
|
|
|
|
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 -rav $(cat .rsync) $(cat .rsync_$(host)) --exclude '*~' --exclude '.git*' --exclude '*.swp' . $(SSH_USER)@$(host):$(DEPLOY_PATH)/$(DEPLOY_NAME); \
|
|
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)
|
|
|
|
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
|