From 8c756c562e100d7bb6a5e6e399336d96beda9ac2 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 14 Nov 2019 10:17:38 +0100 Subject: [PATCH] new: pkg: avoid spurious warnings from ``docker-compose run`` calls. This helps charm direct actions to keep a tidy standard output, and allows them to be used in scripts. ``docker-compose`` was updated to the latest version available (aka ``1.24.0``) and was patched to include what might have been forgotten when implementing the ``COMPOSE_IGNORE_ORPHANS`` environment variable. On ``compose`` side, we need to make sure to pass environment variables that are to be used by ``docker-compose``. PR: https://github.com/docker/compose/pull/7020 Signed-off-by: Valentin Lab --- Dockerfile | 8 ++++++-- bin/compose | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b5b4f8..28a250e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ ENV KAL_SHLIB_ARRAY_VERSION="0.2.0" \ KAL_SHLIB_PRETTY_VERSION="0.4.3" ARG DOCKER_CLI_VERSION="17.06.2-ce" -ARG DOCKER_COMPOSE_VERSION="1.21.2" +ARG DOCKER_COMPOSE_VERSION="1.24.0" ## install docker ENV DOCKER_DOWNLOAD_URL="https://download.docker.com/linux/static/stable/x86_64/docker-$DOCKER_CLI_VERSION.tgz" @@ -58,7 +58,11 @@ RUN apk add yaml-dev cython cython-dev && \ RUN pip install crudini -RUN pip install docker-compose==$DOCKER_COMPOSE_VERSION +RUN apk add libffi-dev openssl-dev && \ + pip install pip==19.3.1 cffi==1.12.3 \ + git+https://github.com/0k/compose@run_ignore_orphans + # docker-compose==$DOCKER_COMPOSE_VERSION + # pip install git+https://github.com/vaab/colour@master RUN curl -L https://git.0k.io/0k-charm.git/plain/bin/charm > /usr/local/bin/charm && \ chmod +x /usr/local/bin/charm diff --git a/bin/compose b/bin/compose index 94f7f66..10cc93b 100755 --- a/bin/compose +++ b/bin/compose @@ -35,6 +35,30 @@ read-0() { } +read-0a() { + local eof= IFS='' + while [ "$1" ]; do + IFS='' read -r -d $'\n' -- "$1" || eof=1 + shift + done + [ -z "$eof" ] +} + + +p0() { + printf "%s\0" "$@" +} + + +list_compose_vars() { + while read-0a def; do + def="${def##* }" + def="${def%=*}" + p0 "$def" + done < <(declare -p | grep "^declare -x COMPOSE_[A-Z_]\+=\"") +} + + get_running_compose_containers() { ## XXXvlab: docker bug: there will be a final newline anyway docker ps --filter label="compose.service" --format='{{.ID}}' @@ -188,6 +212,18 @@ mk_docker_run_options() { COMPOSE_LAUNCHER_BIN=$(readlink -f "${BASH_SOURCE[0]}") docker_run_opts+=("-v" "$COMPOSE_LAUNCHER_BIN:/usr/local/bin/compose") + while read-0 var; do + case "$var" in + COMPOSE_YML_FILE|COMPOSE_LAUNCHER_BIN|COMPOSE_DOCKER_IMAGE|\ + COMPOSE_LAUNCHER_OPTS|COMPOSE_VAR|COMPOSE_CACHE) + : + ;; + *) + docker_run_opts+=("-e" "$var=${!var}") + ;; + esac + done < <(list_compose_vars) + filename=$(mktemp -p /tmp/ -t launch_opts-XXXXXXXXXXXXXXXX) { printf "%s\0" "${docker_run_opts[@]}"