get rid of docker contexts

This commit is contained in:
Andreas Neue 2022-11-09 12:39:22 +01:00
parent baf28a6fbd
commit ca9616934c
1 changed files with 15 additions and 39 deletions

View File

@ -1,80 +1,56 @@
# if want our old context back, we need something like that:
#stored_ctx = `docker context ls | grep "\*" | cut -d " " -f1`
stored_ctx = 'default' # HACK
create-docker-contexts:
@- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \
docker context create $(host) --description "$(host)" --docker "host=ssh://$(SSH_USER)@$(host)"; \
)
pull-compose: pull-compose:
@- echo "\n### pulling image(s)" @- echo "\n### pulling image(s)"
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker context use $(ctx); \
if test $(DOCKER_LOGIN) -eq 1 ; \ if test $(DOCKER_LOGIN) -eq 1 ; \
then \ then \
docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY); \ ssh $(SSH_USER)@$(host) "docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY)"; \
fi; \ fi; \
docker pull $(DOCKER_IMAGE); \ ssh $(SSH_USER)@$(host) "docker pull $(DOCKER_IMAGE)"; \
) )
pull-swarm: pull-swarm:
start-compose: start-compose:
@- echo "\n### starting service(s)" @- echo "\n### starting service(s)"
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker context use $(ctx); \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose up -d"; \
docker-compose up -d; \
) )
@- docker context use $(stored_ctx)
start-swarm: start-swarm:
@- echo "\n### starting service(s)" @- echo "\n### starting service(s)"
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker --context $(ctx) stack deploy -c stack.yml $(DEPLOY_NAME); \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker stack deploy -c stack.yml $(DEPLOY_NAME)"; \
) )
@- docker context use $(stored_ctx)
stop-compose: stop-compose:
@- echo "\n### stopping service(s)" @- echo "\n### stopping service(s)"
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker context use $(ctx); \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose down"; \
docker-compose down; \
) )
@- docker context use $(stored_ctx)
stop-swarm: stop-swarm:
@- echo "\n### stopping service(s)" @- echo "\n### stopping service(s)"
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker --context $(ctx) stack rm $(DEPLOY_NAME); \ ssh $(SSH_USER)@$(host) "docker stack rm $(DEPLOY_NAME)"; \
) )
@- docker context use $(stored_ctx)
logs-compose: logs-compose:
@- echo "\n### logs" @- echo "\n### logs"
@- docker context use $(host) @- ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose logs -f $(service)"
@- docker-compose logs -f $(service)
@- docker context use $(stored_ctx)
logs-swarm: logs-swarm:
@- echo "\n### logs" @- echo "\n### logs"
@- docker context use $(DEPLOY_HOSTS) @- ssh $(SSH_USER)@$(host) "docker service logs -f $(service)"
@- docker service logs -f $(service)
@- docker context use $(stored_ctx)
restart-compose: restart-compose:
@- $(foreach ctx,$(DEPLOY_HOSTS), \ @- $(foreach host,$(DEPLOY_HOSTS), \
echo "$(host)"; \ echo "$(host)"; \
docker context use $(ctx); \ ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose restart"; \
docker-compose restart; \
) )
@- docker context use $(stored_ctx)
reload-compose: reload-compose: