From f56601ce5a90467e3832af9f0edbb615beb84c27 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Tue, 5 Jul 2022 08:27:53 +0200 Subject: [PATCH] add docker module --- docker.mk | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docker.mk diff --git a/docker.mk b/docker.mk new file mode 100644 index 0000000..952d586 --- /dev/null +++ b/docker.mk @@ -0,0 +1,72 @@ +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: + @- echo "\n### running pre-deploy script" + @- $(foreach host,$(DEPLOY_HOSTS), \ + ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh pre-deploy"; \ + ) + +post-deploy-docker: + @- echo "\n### running post-deploy script" + @- $(foreach host,$(DEPLOY_HOSTS), \ + ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); sh post-deploy"; \ + ) + +pull-compose: + @- echo "\n### pulling image(s)" + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker context use $(ctx); \ + docker pull $(DOCKER_IMAGE); \ + ) + +pull-swarm: + +start-compose: + @- echo "\n### starting service(s)" + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker context use $(ctx); \ + docker-compose up -d; \ + ) + +start-swarm: + @- echo "\n### starting service(s)" + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker stack deploy -c $(DEPLOY_PATH)/$(DEPLOY_NAME)/stack.yml $(DEPLOY_NAME); \ + ) + +stop-compose: + @- echo "\n### stopping service(s)" + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker context use $(ctx); \ + docker-compose down; \ +) + +stop-swarm: + @- echo "\n### stopping service(s)" + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker stack rm $(DEPLOY_NAME); \ + ) + +logs-compose: + @- echo "\n### logs" + @- docker context use $(host) + @- docker-compose logs -f $(service) + +logs-swarm: + @- echo "\n### logs" + @- docker context use $(DEPLOY_HOSTS) + @- docker service logs -f $(service) + +restart-compose: + @- $(foreach ctx,$(DEPLOY_HOSTS), \ + docker context use $(ctx); \ + docker-compose restart; \ + ) + +reload-compose: