Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit ec5685a

Browse files
naemonothbkrkr
andauthored
Note to user when overwriting environment variables using .registry.env (elastic#5665)
* Note to user when overwriting environment variables using .registry.env * Move shellcheck disable back to proper line. * Add check for 'CI' environment variable to confirm we're using Jenkins * get around pipefail * Do not use backticks * Use grep -q, and quote. * Failing if both env vars, and .registry.env are set * Update hack/docker.sh Co-authored-by: Thibault Richard <[email protected]> Co-authored-by: Thibault Richard <[email protected]>
1 parent 3f159f6 commit ec5685a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

hack/docker.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@
1212

1313
set -euo pipefail
1414

15+
# ensure environment variable is set before testing if it's a zero value.
16+
CI=${CI:-}
17+
1518
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1619
REGISTRY_ENV="$SCRIPT_DIR/../.registry.env"
1720

1821
retry() { "$SCRIPT_DIR/retry.sh" 5 "$@"; }
1922

23+
if [[ -f "${REGISTRY_ENV}" && "${DOCKER_LOGIN:-}" != "" ]]; then
24+
echo "error: setting DOCKER_LOGIN/DOCKER_PASSWORD is incompatible the '.registry.env' file"
25+
echo "either unset the environment variables, or remove the '.registry.env' file"
26+
exit
27+
fi
28+
2029
# source variables if present
2130
if [[ -f ${REGISTRY_ENV} ]]; then
2231
# shellcheck disable=SC2046
@@ -27,6 +36,13 @@ docker-login() {
2736
local image=$1
2837
local registry=${image%%"/"*}
2938

39+
# Since this check doesn't work very well in Jenkins, and Jenkins sets
40+
# environment variable 'CI' only perform this check when not in Jenkins.
41+
if [[ -z "${CI}" && -f ~/.docker/config.json ]] && grep -q "${registry}" ~/.docker/config.json; then
42+
echo "not authenticating to ${registry} as configuration block already exists in ~/.docker/config.json"
43+
return
44+
fi
45+
3046
case "$image" in
3147

3248
docker.elastic.co/*)

0 commit comments

Comments
 (0)