From a106e635fe5b1c371a7d2d35936ad7fc35b9b398 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 14 Nov 2024 19:01:46 +0000 Subject: [PATCH 01/11] docker login --- .evergreen/connectivity-tests/run.sh | 2 ++ .evergreen/functions.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.evergreen/connectivity-tests/run.sh b/.evergreen/connectivity-tests/run.sh index b6c8ab81066..b8a1d15f9da 100644 --- a/.evergreen/connectivity-tests/run.sh +++ b/.evergreen/connectivity-tests/run.sh @@ -6,6 +6,8 @@ set -e MONOREPO_ROOT_DIR="$(cd $(dirname "$0")/../..; pwd)" cd $MONOREPO_ROOT_DIR +echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + echo "building connectivity tests image from ${PWD}" docker build -t devtools-connectivity-tests --build-arg "NODE_JS_VERSION=$NODE_JS_VERSION" -f "./.evergreen/connectivity-tests/Dockerfile" . echo "connectivity tests image built" diff --git a/.evergreen/functions.yml b/.evergreen/functions.yml index bb69785b943..c09b63ffaf6 100644 --- a/.evergreen/functions.yml +++ b/.evergreen/functions.yml @@ -78,6 +78,8 @@ variables: GARASIGN_PASSWORD: ${garasign_password} ARTIFACTORY_USERNAME: ${artifactory_username} ARTIFACTORY_PASSWORD: ${artifactory_password} + DOCKERHUB_USERNAME: ${dockerhub_username} + DOCKERHUB_PASSWORD: ${dockerhub_password} # This is here with the variables because anchors aren't supported across includes post: From 57e12901fd4228da8be019cb81df2828af18d42d Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 14 Nov 2024 19:05:33 +0000 Subject: [PATCH 02/11] rather log in when starting the envs --- .evergreen/connectivity-tests/run.sh | 2 -- .evergreen/start-docker-envs.sh | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.evergreen/connectivity-tests/run.sh b/.evergreen/connectivity-tests/run.sh index b8a1d15f9da..b6c8ab81066 100644 --- a/.evergreen/connectivity-tests/run.sh +++ b/.evergreen/connectivity-tests/run.sh @@ -6,8 +6,6 @@ set -e MONOREPO_ROOT_DIR="$(cd $(dirname "$0")/../..; pwd)" cd $MONOREPO_ROOT_DIR -echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin - echo "building connectivity tests image from ${PWD}" docker build -t devtools-connectivity-tests --build-arg "NODE_JS_VERSION=$NODE_JS_VERSION" -f "./.evergreen/connectivity-tests/Dockerfile" . echo "connectivity tests image built" diff --git a/.evergreen/start-docker-envs.sh b/.evergreen/start-docker-envs.sh index 120d80f08a6..33edb1a1dee 100644 --- a/.evergreen/start-docker-envs.sh +++ b/.evergreen/start-docker-envs.sh @@ -33,6 +33,9 @@ if [ "$HAS_DOCKER" = true ]; then docker version $DOCKER_COMPOSE version + echo "Logging in to docker" + echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + echo "Starting test environments" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" From 26f05e3f5473a7a1afb660d2f7312f6cf595bd15 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 14 Nov 2024 20:29:07 +0000 Subject: [PATCH 03/11] also login before starting atlas cloud cluster --- .evergreen/start-atlas-cloud-cluster.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.evergreen/start-atlas-cloud-cluster.sh b/.evergreen/start-atlas-cloud-cluster.sh index 5c38b3d1f14..5c1cfe6c2a2 100644 --- a/.evergreen/start-atlas-cloud-cluster.sh +++ b/.evergreen/start-atlas-cloud-cluster.sh @@ -89,6 +89,9 @@ cleanup() { trap cleanup EXIT +echo "Logging in to docker" +echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + echo "Allowing access from current ip..." atlascli accessList create \ --currentIp \ From 7913bbce4345f11ce4e20da919ca958dae597995 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 07:55:55 +0000 Subject: [PATCH 04/11] also login for start-atlas-local --- .evergreen/start-atlas-local.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.evergreen/start-atlas-local.sh b/.evergreen/start-atlas-local.sh index 75dce43a048..6f7a3448b36 100755 --- a/.evergreen/start-atlas-local.sh +++ b/.evergreen/start-atlas-local.sh @@ -19,6 +19,9 @@ cleanup() { trap cleanup EXIT +echo "Logging in to docker" +echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + # Image name with version IMAGE_NAME="mongodb/mongodb-atlas-local:$ATLAS_LOCAL_VERSION" echo docker run --rm --name $CONTAINER_NAME -d -e DO_NOT_TRACK=1 -P "$IMAGE_NAME" From 9053899e5d6f717de5a40cd7f970b06850a647c1 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 08:41:25 +0000 Subject: [PATCH 05/11] conditionally log into docker --- .evergreen/start-atlas-cloud-cluster.sh | 6 ++++-- .evergreen/start-atlas-local.sh | 6 ++++-- .evergreen/start-docker-envs.sh | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.evergreen/start-atlas-cloud-cluster.sh b/.evergreen/start-atlas-cloud-cluster.sh index 5c1cfe6c2a2..30b61c053db 100644 --- a/.evergreen/start-atlas-cloud-cluster.sh +++ b/.evergreen/start-atlas-cloud-cluster.sh @@ -89,8 +89,10 @@ cleanup() { trap cleanup EXIT -echo "Logging in to docker" -echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin +if [ -z "$DOCKERHUB_PASSWORD" ]; then + echo "Logging in to docker" + echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin +fi echo "Allowing access from current ip..." atlascli accessList create \ diff --git a/.evergreen/start-atlas-local.sh b/.evergreen/start-atlas-local.sh index 6f7a3448b36..e5377f0ff6f 100755 --- a/.evergreen/start-atlas-local.sh +++ b/.evergreen/start-atlas-local.sh @@ -19,8 +19,10 @@ cleanup() { trap cleanup EXIT -echo "Logging in to docker" -echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin +if [ -z "$DOCKERHUB_PASSWORD" ]; then + echo "Logging in to docker" + echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin +fi # Image name with version IMAGE_NAME="mongodb/mongodb-atlas-local:$ATLAS_LOCAL_VERSION" diff --git a/.evergreen/start-docker-envs.sh b/.evergreen/start-docker-envs.sh index 33edb1a1dee..ce2a8739457 100644 --- a/.evergreen/start-docker-envs.sh +++ b/.evergreen/start-docker-envs.sh @@ -33,8 +33,10 @@ if [ "$HAS_DOCKER" = true ]; then docker version $DOCKER_COMPOSE version - echo "Logging in to docker" - echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + if [ -z "$DOCKERHUB_PASSWORD" ]; then + echo "Logging in to docker" + echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin + fi echo "Starting test environments" From 9dd7547ded54d6d92d8054add40c8c42566f4f78 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 08:57:31 +0000 Subject: [PATCH 06/11] invert the docker env var checks --- .evergreen/start-atlas-cloud-cluster.sh | 2 +- .evergreen/start-atlas-local.sh | 2 +- .evergreen/start-docker-envs.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.evergreen/start-atlas-cloud-cluster.sh b/.evergreen/start-atlas-cloud-cluster.sh index 30b61c053db..1876c548cfe 100644 --- a/.evergreen/start-atlas-cloud-cluster.sh +++ b/.evergreen/start-atlas-cloud-cluster.sh @@ -89,7 +89,7 @@ cleanup() { trap cleanup EXIT -if [ -z "$DOCKERHUB_PASSWORD" ]; then +if [ -n "$DOCKERHUB_PASSWORD" ]; then echo "Logging in to docker" echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin fi diff --git a/.evergreen/start-atlas-local.sh b/.evergreen/start-atlas-local.sh index e5377f0ff6f..b317aa6cc90 100755 --- a/.evergreen/start-atlas-local.sh +++ b/.evergreen/start-atlas-local.sh @@ -19,7 +19,7 @@ cleanup() { trap cleanup EXIT -if [ -z "$DOCKERHUB_PASSWORD" ]; then +if [ -n "$DOCKERHUB_PASSWORD" ]; then echo "Logging in to docker" echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin fi diff --git a/.evergreen/start-docker-envs.sh b/.evergreen/start-docker-envs.sh index ce2a8739457..b7b56525aff 100644 --- a/.evergreen/start-docker-envs.sh +++ b/.evergreen/start-docker-envs.sh @@ -33,7 +33,7 @@ if [ "$HAS_DOCKER" = true ]; then docker version $DOCKER_COMPOSE version - if [ -z "$DOCKERHUB_PASSWORD" ]; then + if [ -n "$DOCKERHUB_PASSWORD" ]; then echo "Logging in to docker" echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin fi From eb9507deba9b8bfc756685eaddaa8b0fa7ca5beb Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 09:42:19 +0000 Subject: [PATCH 07/11] also log out of docker --- .evergreen/start-atlas-cloud-cluster.sh | 5 +++++ .evergreen/start-atlas-local.sh | 5 +++++ .evergreen/start-docker-envs.sh | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.evergreen/start-atlas-cloud-cluster.sh b/.evergreen/start-atlas-cloud-cluster.sh index 1876c548cfe..c4a24509171 100644 --- a/.evergreen/start-atlas-cloud-cluster.sh +++ b/.evergreen/start-atlas-cloud-cluster.sh @@ -85,6 +85,11 @@ cleanup() { fi echo "Deleting Atlas db user \`$ATLAS_TEST_DB_USERNAME\`..." atlascli dbusers delete $ATLAS_TEST_DB_USERNAME --force + + if [ -n "$DOCKERHUB_PASSWORD" ]; then + echo "Logging out of docker" + docker logout + fi } trap cleanup EXIT diff --git a/.evergreen/start-atlas-local.sh b/.evergreen/start-atlas-local.sh index b317aa6cc90..5540488c091 100755 --- a/.evergreen/start-atlas-local.sh +++ b/.evergreen/start-atlas-local.sh @@ -15,6 +15,11 @@ cleanup() { echo "Stopping and removing container..." docker stop $CONTAINER_NAME || true docker rm -f $CONTAINER_NAME || true + + if [ -n "$DOCKERHUB_PASSWORD" ]; then + echo "Logging out of docker" + docker logout + fi } trap cleanup EXIT diff --git a/.evergreen/start-docker-envs.sh b/.evergreen/start-docker-envs.sh index b7b56525aff..6b9dfc382df 100644 --- a/.evergreen/start-docker-envs.sh +++ b/.evergreen/start-docker-envs.sh @@ -78,6 +78,11 @@ if [ "$HAS_DOCKER" = true ]; then $DOCKER_COMPOSE -f test-envs/docker/ssh/docker-compose.yaml down -v --remove-orphans $DOCKER_COMPOSE -f test-envs/docker/tls/docker-compose.yaml down -v --remove-orphans $DOCKER_COMPOSE -f test-envs/docker/kerberos/docker-compose.yaml down -v --remove-orphans + + if [ -n "$DOCKERHUB_PASSWORD" ]; then + echo "Logging out of docker" + docker logout + fi } trap "__stop_all_docker_containers" EXIT From e978d177ef123c1d4e392c0af43f140293be25e9 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 10:45:18 +0000 Subject: [PATCH 08/11] credsStore from-env --- .../bin/docker-credential-from-env | 32 +++++++++++++++++++ .evergreen/docker-config/config.json | 6 ++++ .evergreen/print-compass-env.js | 4 +++ 3 files changed, 42 insertions(+) create mode 100755 .evergreen/docker-config/bin/docker-credential-from-env create mode 100644 .evergreen/docker-config/config.json diff --git a/.evergreen/docker-config/bin/docker-credential-from-env b/.evergreen/docker-config/bin/docker-credential-from-env new file mode 100755 index 00000000000..df3a5ee68bd --- /dev/null +++ b/.evergreen/docker-config/bin/docker-credential-from-env @@ -0,0 +1,32 @@ +#!/bin/bash + +set -euo pipefail + +DOCKER_HUB_URL="https://index.docker.io/v1/" + +STDIN=$(cat) + +ACTION="$1" + +case "$ACTION" in + get) + SERVER_URL="$STDIN" + + if [[ "$SERVER_URL" == "$DOCKER_HUB_URL" ]]; then + if [[ -z "${DOCKERHUB_USERNAME:-}" || -z "${DOCKERHUB_PASSWORD:-}" ]]; then + echo "Error: DOCKERHUB_USERNAME or DOCKERHUB_PASSWORD environment variables are not set." >&2 + exit 1 + fi + + echo "{\"Username\": \"$DOCKERHUB_USERNAME\", \"Secret\": \"$DOCKERHUB_PASSWORD\"}" + else + echo "Error: No credentials available for $SERVER_URL" >&2 + exit 1 + fi + ;; + + *) + echo "Unsupported action: $ACTION" >&2 + exit 1 + ;; +esac diff --git a/.evergreen/docker-config/config.json b/.evergreen/docker-config/config.json new file mode 100644 index 00000000000..353cd057bcd --- /dev/null +++ b/.evergreen/docker-config/config.json @@ -0,0 +1,6 @@ +{ + "auths": { + "https://index.docker.io/v1/": {} + }, + "credsStore": "from-env" +} diff --git a/.evergreen/print-compass-env.js b/.evergreen/print-compass-env.js index 1497e9e642c..0059b9201c1 100755 --- a/.evergreen/print-compass-env.js +++ b/.evergreen/print-compass-env.js @@ -74,6 +74,8 @@ function printCompassEnv() { pathsToPrepend.unshift('/opt/mongodbtoolchain/v4/bin'); } + pathsToPrepend(`${originalPWD}/.evergreen/docker-config/bin`); + PATH = maybePrependPaths(PATH, pathsToPrepend); printVar('PATH', PATH); @@ -113,6 +115,8 @@ function printCompassEnv() { // https://jira.mongodb.org/browse/NODE-6320 printVar('GYP_DEFINES', `kerberos_use_rtld=${process.platform === 'linux'}`); + + printVar('DOCKER_CONFIG', `${originalPWD}/.evergreen/docker-config`); } printCompassEnv(); From 757e25ac1a9d220432c5a188b70721680b234176 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 10:48:40 +0000 Subject: [PATCH 09/11] no need to login --- .evergreen/start-atlas-cloud-cluster.sh | 10 ---------- .evergreen/start-atlas-local.sh | 10 ---------- .evergreen/start-docker-envs.sh | 10 ---------- 3 files changed, 30 deletions(-) diff --git a/.evergreen/start-atlas-cloud-cluster.sh b/.evergreen/start-atlas-cloud-cluster.sh index c4a24509171..5c38b3d1f14 100644 --- a/.evergreen/start-atlas-cloud-cluster.sh +++ b/.evergreen/start-atlas-cloud-cluster.sh @@ -85,20 +85,10 @@ cleanup() { fi echo "Deleting Atlas db user \`$ATLAS_TEST_DB_USERNAME\`..." atlascli dbusers delete $ATLAS_TEST_DB_USERNAME --force - - if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging out of docker" - docker logout - fi } trap cleanup EXIT -if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging in to docker" - echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin -fi - echo "Allowing access from current ip..." atlascli accessList create \ --currentIp \ diff --git a/.evergreen/start-atlas-local.sh b/.evergreen/start-atlas-local.sh index 5540488c091..75dce43a048 100755 --- a/.evergreen/start-atlas-local.sh +++ b/.evergreen/start-atlas-local.sh @@ -15,20 +15,10 @@ cleanup() { echo "Stopping and removing container..." docker stop $CONTAINER_NAME || true docker rm -f $CONTAINER_NAME || true - - if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging out of docker" - docker logout - fi } trap cleanup EXIT -if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging in to docker" - echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin -fi - # Image name with version IMAGE_NAME="mongodb/mongodb-atlas-local:$ATLAS_LOCAL_VERSION" echo docker run --rm --name $CONTAINER_NAME -d -e DO_NOT_TRACK=1 -P "$IMAGE_NAME" diff --git a/.evergreen/start-docker-envs.sh b/.evergreen/start-docker-envs.sh index 6b9dfc382df..120d80f08a6 100644 --- a/.evergreen/start-docker-envs.sh +++ b/.evergreen/start-docker-envs.sh @@ -33,11 +33,6 @@ if [ "$HAS_DOCKER" = true ]; then docker version $DOCKER_COMPOSE version - if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging in to docker" - echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin - fi - echo "Starting test environments" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" @@ -78,11 +73,6 @@ if [ "$HAS_DOCKER" = true ]; then $DOCKER_COMPOSE -f test-envs/docker/ssh/docker-compose.yaml down -v --remove-orphans $DOCKER_COMPOSE -f test-envs/docker/tls/docker-compose.yaml down -v --remove-orphans $DOCKER_COMPOSE -f test-envs/docker/kerberos/docker-compose.yaml down -v --remove-orphans - - if [ -n "$DOCKERHUB_PASSWORD" ]; then - echo "Logging out of docker" - docker logout - fi } trap "__stop_all_docker_containers" EXIT From 74c3b2358a70fecfd5d6d80b6cccc497c1c7188e Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 10:54:15 +0000 Subject: [PATCH 10/11] unshift.. --- .evergreen/print-compass-env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/print-compass-env.js b/.evergreen/print-compass-env.js index 0059b9201c1..7c0b8ebd664 100755 --- a/.evergreen/print-compass-env.js +++ b/.evergreen/print-compass-env.js @@ -74,7 +74,7 @@ function printCompassEnv() { pathsToPrepend.unshift('/opt/mongodbtoolchain/v4/bin'); } - pathsToPrepend(`${originalPWD}/.evergreen/docker-config/bin`); + pathsToPrepend.unshift(`${originalPWD}/.evergreen/docker-config/bin`); PATH = maybePrependPaths(PATH, pathsToPrepend); printVar('PATH', PATH); From 12d8509cfd83e77dbee0726a2f5851ff99adc0d9 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 15 Nov 2024 11:08:08 +0000 Subject: [PATCH 11/11] print docker config --- .evergreen/preinstall.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.evergreen/preinstall.sh b/.evergreen/preinstall.sh index bac0ce1249e..3a8a0382227 100755 --- a/.evergreen/preinstall.sh +++ b/.evergreen/preinstall.sh @@ -18,6 +18,8 @@ echo "IS_WINDOWS: $IS_WINDOWS" echo "IS_RHEL: $IS_RHEL" echo "IS_UBUNTU: $IS_UBUNTU" +echo "DOCKER_CONFIG: $DOCKER_CONFIG" + SCRIPTDIR="$(cd $(dirname "$0"); pwd)" if [ -n "$IS_WINDOWS" ]; then