From adf279d43acc376c24e40627d3feea356e040ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Thu, 6 Dec 2018 14:27:42 +0100 Subject: [PATCH] new script docker-build to preconfigure parameters for docker build, set environment variable DOCKER_USER; fixed path in docker-update --- README.md | 5 +++++ docker-build | 18 ++++++++++++++++++ docker-update | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 docker-build diff --git a/README.md b/README.md index e289e4a..a7841b8 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,8 @@ docker-update ------------- Script to update all or some images within declared in a yaml file. Use it to update the docker image of all or some services in your already deployed docker swarm stack. + +docker-build +------------ + +Script to be called from a directory with a Dockerfile to build the docker image. Tha name of the tag is derieved from environment variable `DOCKER_USER` and the path name. It automatically applies the options `--rm --force-rm`. As additional options, you can overwirte the image name as first parameter, and/or pass more `docker build` options. diff --git a/docker-build b/docker-build new file mode 100755 index 0000000..6415fe9 --- /dev/null +++ b/docker-build @@ -0,0 +1,18 @@ +#!/bin/bash -x + +if test $# -gt 0 -a "${1#-}" = "${1}"; then + name=$1 + shift +else + name=$(pwd | sed 's,.*/,,') +fi +if test "$name" = "docker"; then + name=$(pwd | sed 's,/[^/]*$,,;s,.*/,,') +fi +if test "${name#*/}" = "${name}"; then + name=${DOCKER_USER:-mwaeckerlin}/${name} +fi + +echo "**** building $name" +set -x +docker build $* --rm --force-rm -t ${name,,} . diff --git a/docker-update b/docker-update index 95273e8..1facf54 100755 --- a/docker-update +++ b/docker-update @@ -39,7 +39,7 @@ for f in $*; do echo "upgrading ${name}" IFS=" " - for param in $(sed -n '/^ *\([^:]\+\): *$/{s//'"${name}"'_\1/;h};/^ *image: */{s///;G;s/\n/ /p}' $file); do + for param in $(sed -n '/^ *\([^:]\+\): *$/{s,,'"${name}"'_\1,;h};/^ *image: */{s///;G;s/\n/ /p}' $file); do IFS=" " if [ -z "$limit" ] || [[ "${param}" =~ " ${name}_${limit}" ]]; then echo "....update $param: docker service update -d --image $param"