2022-07-03 21:06:54 +00:00
|
|
|
.PHONY: create_contexts deploy upload pull start stop restart
|
|
|
|
|
|
|
|
include config.mk
|
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
create-contexts:
|
2022-07-03 21:06:54 +00:00
|
|
|
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
|
|
docker context create $(host) --description "$(host)" --docker "host=ssh://$(SSH_USER)@$(host)"; \
|
|
|
|
)
|
|
|
|
|
|
|
|
deploy: upload pre-deploy pull start post-deploy
|
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
pre-deploy: pre-deploy-$(DEPLOY_TYPE)
|
|
|
|
|
2022-07-04 10:43:51 +00:00
|
|
|
post-deploy: post-deploy-$(DEPLOY_TYPE)
|
2022-07-04 07:47:18 +00:00
|
|
|
|
|
|
|
pre-deploy-compose: pre-deploy-docker
|
|
|
|
|
|
|
|
post-deploy-compose: post-deploy-docker
|
|
|
|
|
|
|
|
pre-deploy-swarm: pre-deploy-docker
|
|
|
|
|
|
|
|
post-deploy-swarm: post-deploy-docker
|
|
|
|
|
|
|
|
pre-deploy-docker:
|
2022-07-03 21:22:38 +00:00
|
|
|
@- echo "\n### running pre-deploy script"
|
2022-07-03 21:19:46 +00:00
|
|
|
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
|
|
cd $(DEPLOY_PATH)/$(DEPLOY_NAME); \
|
|
|
|
sh pre-deploy.sh; \
|
|
|
|
)
|
2022-07-03 21:06:54 +00:00
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
post-deploy-docker:
|
2022-07-03 21:22:38 +00:00
|
|
|
@- echo "\n### running post-deploy script"
|
2022-07-03 21:19:46 +00:00
|
|
|
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
|
|
cd $(DEPLOY_PATH)/$(DEPLOY_NAME); \
|
|
|
|
sh post-deploy.sh; \
|
|
|
|
)
|
2022-07-03 21:06:54 +00:00
|
|
|
|
|
|
|
upload:
|
|
|
|
@- echo "\n### uploading files"
|
|
|
|
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
|
|
rsync -rav --exclude '*~' . $(SSH_USER)@$(host):$(DEPLOY_PATH)/$(DEPLOY_NAME); \
|
|
|
|
)
|
|
|
|
|
|
|
|
pull:
|
|
|
|
@- echo "\n### pulling image(s)"
|
|
|
|
@- $(foreach ctx,$(DEPLOY_HOSTS), \
|
|
|
|
docker context use $(ctx); \
|
|
|
|
docker pull $(DOCKER_IMAGE); \
|
|
|
|
)
|
|
|
|
|
|
|
|
start: start-$(DEPLOY_TYPE)
|
|
|
|
|
|
|
|
start-compose:
|
|
|
|
@- echo "\n### starting service(s)"
|
|
|
|
@- $(foreach ctx,$(DEPLOY_HOSTS), \
|
|
|
|
docker context use $(ctx); \
|
|
|
|
docker-compose up -d; \
|
|
|
|
)
|
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
start-swarm:
|
|
|
|
|
|
|
|
stop: stop-$(DEPLOY_TYPE)
|
|
|
|
|
2022-07-03 21:06:54 +00:00
|
|
|
stop-compose:
|
|
|
|
@- echo "\n### stopping service(s)"
|
|
|
|
@- $(foreach ctx,$(DEPLOY_HOSTS), \
|
|
|
|
docker context use $(ctx); \
|
|
|
|
docker-compose down; \
|
2022-07-04 07:47:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
stop-swarm:
|
|
|
|
|
|
|
|
logs: logs-$(DEPLOY_TYPE)
|
2022-07-03 21:06:54 +00:00
|
|
|
|
|
|
|
logs-compose:
|
|
|
|
@- echo "\n### logs"
|
|
|
|
@- docker context use $(host)
|
|
|
|
@- docker-compose logs -f $(service)
|
|
|
|
|
|
|
|
|
|
|
|
logs-swarm:
|
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
restart: restart-$(DEPLOY_TYPE)
|
|
|
|
|
|
|
|
restart-compose:
|
2022-07-03 21:06:54 +00:00
|
|
|
@- $(foreach ctx,$(DEPLOY_HOSTS), \
|
|
|
|
docker context use $(ctx); \
|
|
|
|
docker-compose restart; \
|
|
|
|
)
|
|
|
|
|
2022-07-04 07:47:18 +00:00
|
|
|
reload: reload-$(DEPLOY_TYPE)
|
|
|
|
|
|
|
|
reload-compose:
|
2022-07-03 21:06:54 +00:00
|
|
|
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
|
|
docker context use $(ctx); \
|
|
|
|
docker-compose restart; \
|
|
|
|
)
|