From af2cad09b44df0bf5f2ef93190ec79dc2219269f Mon Sep 17 00:00:00 2001 From: Stefan Riepenhausen Date: Wed, 5 Jun 2024 09:29:49 +0200 Subject: [PATCH] Deal with unset docker login --- apt.mk | 2 +- compose-file.mk | 11 ++++++-- compose.mk | 11 ++++++-- test.sh | 50 ++++++++++++++++++++++++++++++++++ testing/apt_config.mk | 6 ++++ testing/compose_config.mk | 5 ++++ testing/compose_file_config.mk | 7 +++++ testing/docker-compose.yml | 4 +++ 8 files changed, 91 insertions(+), 5 deletions(-) create mode 100755 test.sh create mode 100644 testing/apt_config.mk create mode 100644 testing/compose_config.mk create mode 100644 testing/compose_file_config.mk create mode 100644 testing/docker-compose.yml diff --git a/apt.mk b/apt.mk index 7afe780..b3099ea 100644 --- a/apt.mk +++ b/apt.mk @@ -1,4 +1,4 @@ -MANDATORY-apt = APT_PACKAGES +MANDATORY-apt = DEPLOY_HOSTS SSH_USER APT_PACKAGES DEPLOY_NAME pull-apt: # nop diff --git a/compose-file.mk b/compose-file.mk index 0d1c7c9..03a194c 100644 --- a/compose-file.mk +++ b/compose-file.mk @@ -1,4 +1,8 @@ -MANDATORY-compose-file = DEPLOY_HOSTS DEPLOY_TYPE TAG DEPLOY_COMPOSE_FILE DEPLOY_COMPOSE_PROJECT +MANDATORY-compose-file = DEPLOY_HOSTS DEPLOY_TYPE SSH_USER DEPLOY_COMPOSE_FILE DEPLOY_COMPOSE_PROJECT + +ifndef DOCKER_LOGIN +DOCKER_LOGIN = 0 +endif pull-compose-file: @- echo "\n### pulling image(s)" @@ -9,7 +13,10 @@ pull-compose-file: echo "\n#### perfom docker login with user $(DOCKER_USER) on $(DOCKER_REGISTRY)"; \ ssh $(SSH_USER)@$(host) "docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY)"; \ fi; \ - ssh $(SSH_USER)@$(host) "docker pull $(DOCKER_IMAGE)"; \ + if test -n "$(DOCKER_IMAGE)" ; \ + then \ + ssh $(SSH_USER)@$(host) "docker pull $(DOCKER_IMAGE)"; \ + fi; \ ) start-compose-file: diff --git a/compose.mk b/compose.mk index c9779bf..6de67f8 100644 --- a/compose.mk +++ b/compose.mk @@ -1,4 +1,8 @@ -MANDATORY-compose = DEPLOY_HOSTS DEPLOY_TYPE TAG +MANDATORY-compose = DEPLOY_HOSTS DEPLOY_TYPE SSH_USER DEPLOY_NAME + +ifndef DOCKER_LOGIN +DOCKER_LOGIN = 0 +endif pull-compose: @- echo "\n### pulling image(s)" @@ -9,7 +13,10 @@ pull-compose: echo "\n#### perfom docker login with user $(DOCKER_USER) on $(DOCKER_REGISTRY)"; \ ssh $(SSH_USER)@$(host) "docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY)"; \ fi; \ - ssh $(SSH_USER)@$(host) "docker pull $(DOCKER_IMAGE)"; \ + if test -n "$(DOCKER_IMAGE)" ; \ + then \ + ssh $(SSH_USER)@$(host) "docker pull $(DOCKER_IMAGE)"; \ + fi; \ ) start-compose: diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..88d79e1 --- /dev/null +++ b/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +DIR=$(mktemp -d) +TESTS=$DIR/make-deploy/testing + +function prepdir() { + mkdir $DIR/make-deploy + cp -r * $DIR/make-deploy + cd $DIR + ln -s make-deploy/Makefile + touch secrets.mk + echo "::::::::: testing directory root: $DIR" +} + +function cleandir(){ + rm -fr $DIR + echo "::::::::: cleanup done" +} + +function test_with_minimal_vars_apt(){ + echo "::::::::: $FUNCNAME ::::::::::::" + cp $TESTS/apt_config.mk config.mk + make deploy +} + +function test_with_minimal_vars_compose(){ + echo "::::::::: $FUNCNAME ::::::::::::" + cp $TESTS/compose_config.mk config.mk + cp $TESTS/docker-compose.yml . + make deploy + rm -f docker-compose.yml +} + +function test_with_minimal_vars_compose_file(){ + echo "::::::::: $FUNCNAME ::::::::::::" + cp $TESTS/compose_file_config.mk config.mk + cp $TESTS/docker-compose.yml . + make deploy + rm -f docker-compose.yml +} + +prepdir + +test_with_minimal_vars_apt +test_with_minimal_vars_compose +test_with_minimal_vars_compose_file + +cleandir diff --git a/testing/apt_config.mk b/testing/apt_config.mk new file mode 100644 index 0000000..444165f --- /dev/null +++ b/testing/apt_config.mk @@ -0,0 +1,6 @@ +DEPLOY_NAME = make-deploy-test-apt +DEPLOY_PATH = /tmp +DEPLOY_HOSTS = localhost +DEPLOY_TYPE = apt +SSH_USER = $(USER) +APT_PACKAGES = curl diff --git a/testing/compose_config.mk b/testing/compose_config.mk new file mode 100644 index 0000000..7d81afb --- /dev/null +++ b/testing/compose_config.mk @@ -0,0 +1,5 @@ +DEPLOY_NAME = make-deploy-test-compose +DEPLOY_PATH = /tmp +DEPLOY_HOSTS = localhost +DEPLOY_TYPE = compose +SSH_USER = $(USER) diff --git a/testing/compose_file_config.mk b/testing/compose_file_config.mk new file mode 100644 index 0000000..bdd0ab8 --- /dev/null +++ b/testing/compose_file_config.mk @@ -0,0 +1,7 @@ +DEPLOY_NAME = make-deploy-test-compose-file +DEPLOY_PATH = /tmp +DEPLOY_HOSTS = localhost +DEPLOY_TYPE = compose-file +SSH_USER = $(USER) +DEPLOY_COMPOSE_PROJECT = make-deploy-test-compose-file +DEPLOY_COMPOSE_FILE = docker-compose.yml diff --git a/testing/docker-compose.yml b/testing/docker-compose.yml new file mode 100644 index 0000000..d362336 --- /dev/null +++ b/testing/docker-compose.yml @@ -0,0 +1,4 @@ +services: + curl: + image: "alpine/curl" + command: -s -o /dev/null https://www.test.de