From b24062bfc3d91baf953262019e0b98bd995dcbc8 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Mon, 18 Jul 2022 16:55:24 +0200 Subject: [PATCH] docker.mk: dont change context persistently --- docker.mk | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/docker.mk b/docker.mk index 37fb44e..b718042 100644 --- a/docker.mk +++ b/docker.mk @@ -26,16 +26,20 @@ post-deploy-docker: pull-compose: @- echo "\n### pulling image(s)" @- $(foreach ctx,$(DEPLOY_HOSTS), \ - docker --context $(ctx) pull $(DOCKER_IMAGE); \ + docker context use $(ctx); \ + docker pull $(DOCKER_IMAGE); \ ) pull-swarm: start-compose: @- echo "\n### starting service(s)" + @- stored_ctx=`docker context ls | grep "\*" | cut -d " " -f1` @- $(foreach ctx,$(DEPLOY_HOSTS), \ - docker-compose --host $(ctx) up -d; \ + docker context use $(ctx); \ + docker-compose up -d; \ ) + @- docker context use $(stored_ctx) start-swarm: @- echo "\n### starting service(s)" @@ -45,27 +49,40 @@ start-swarm: stop-compose: @- echo "\n### stopping service(s)" + @- stored_ctx=`docker context ls | grep "\*" | cut -d " " -f1` @- $(foreach ctx,$(DEPLOY_HOSTS), \ - docker-compose --host $(ctx) down; \ -) - + docker context use $(ctx); \ + docker-compose down; \ + ) + @- docker context use $(stored_ctx) + stop-swarm: @- echo "\n### stopping service(s)" @- $(foreach ctx,$(DEPLOY_HOSTS), \ docker --context $(ctx) stack rm $(DEPLOY_NAME); \ ) - + @- docker context use $(stored_ctx) + logs-compose: @- echo "\n### logs" - @- docker-compose --host $(ctx) logs -f $(service) - + @- stored_ctx=`docker context ls | grep "\*" | cut -d " " -f1` + @- docker context use $(host) + @- docker-compose logs -f $(service) + @- docker context use $(stored_ctx) + logs-swarm: @- echo "\n### logs" - @- docker --context $(ctx) service logs -f $(service) - + @- stored_ctx=`docker context ls | grep "\*" | cut -d " " -f1` + @- docker context use $(DEPLOY_HOSTS) + @- docker service logs -f $(service) + @- docker context use $(stored_ctx) + restart-compose: + @- stored_ctx=`docker context ls | grep "\*" | cut -d " " -f1` @- $(foreach ctx,$(DEPLOY_HOSTS), \ - docker-compose --host $(ctx) restart; \ + docker context use $(ctx); \ + docker-compose restart; \ ) - + @- docker context use $(stored_ctx) + reload-compose: