@@ -22,16 +22,14 @@ setup_validate_container_runtime() {
2222 echo " Error: Podman is not available but was specified"
2323 exit 1
2424 fi
25- USE_SUDO=true
26- CONFIG_PATH=" /root/.config/containers/auth.json"
27- echo " Using Podman for container authentication (sudo mode)"
25+ CONFIG_PATH=" ${HOME} /.config/containers/auth.json"
26+ echo " Using Podman for container authentication (rootless mode)"
2827 ;;
2928 " docker" )
3029 if ! command -v docker & > /dev/null; then
3130 echo " Error: Docker is not available but was specified"
3231 exit 1
3332 fi
34- USE_SUDO=false
3533 CONFIG_PATH=" ${HOME} /.docker/config.json"
3634 echo " Using Docker for container authentication"
3735 ;;
@@ -41,41 +39,7 @@ setup_validate_container_runtime() {
4139 ;;
4240 esac
4341
44- if [[ " ${USE_SUDO} " == " true" ]]; then
45- sudo mkdir -p " $( dirname " ${CONFIG_PATH} " ) "
46- else
47- mkdir -p " $( dirname " ${CONFIG_PATH} " ) "
48- fi
49- }
50-
51- # Wrapper function to execute commands with or without sudo
52- exec_cmd () {
53- if [[ " ${USE_SUDO} " == " true" ]]; then
54- sudo env PATH=" ${PATH} " " $@ "
55- else
56- " $@ "
57- fi
58- }
59-
60- # Wrapper function to read files with or without sudo
61- read_file () {
62- local file=" $1 "
63- if [[ " ${USE_SUDO} " == " true" ]]; then
64- sudo cat " ${file} "
65- else
66- cat " ${file} "
67- fi
68- }
69-
70- # Wrapper function to write files with or without sudo
71- write_file () {
72- local content=" $1 "
73- local file=" $2 "
74- if [[ " ${USE_SUDO} " == " true" ]]; then
75- echo " ${content} " | sudo tee " ${file} " > /dev/null
76- else
77- echo " ${content} " > " ${file} "
78- fi
42+ mkdir -p " $( dirname " ${CONFIG_PATH} " ) "
7943}
8044
8145remove_element () {
@@ -84,11 +48,11 @@ remove_element() {
8448 tmpfile=$( mktemp)
8549
8650 if [[ ! -f " ${CONFIG_PATH} " ]]; then
87- write_file ' {}' " ${CONFIG_PATH} "
51+ echo ' {}' > " ${CONFIG_PATH} "
8852 fi
8953
90- exec_cmd jq ' del(.' " ${config_option} " ' )' " ${CONFIG_PATH} " > " ${tmpfile} "
91- exec_cmd cp " ${tmpfile} " " ${CONFIG_PATH} "
54+ jq ' del(.' " ${config_option} " ' )' " ${CONFIG_PATH} " > " ${tmpfile} "
55+ cp " ${tmpfile} " " ${CONFIG_PATH} "
9256 rm " ${tmpfile} "
9357}
9458
@@ -97,7 +61,7 @@ registry_login() {
9761 local registry=" $2 "
9862
9963 if [[ " ${CONTAINER_RUNTIME} " == " podman" ]]; then
100- exec_cmd podman login --authfile " ${CONFIG_PATH} " --username " ${username} " --password-stdin " ${registry} "
64+ podman login --authfile " ${CONFIG_PATH} " --username " ${username} " --password-stdin " ${registry} "
10165 else
10266 docker login --username " ${username} " --password-stdin " ${registry} "
10367 fi
@@ -106,13 +70,13 @@ registry_login() {
10670setup_validate_container_runtime
10771
10872if [[ ! -f " ${CONFIG_PATH} " ]]; then
109- write_file ' {}' " ${CONFIG_PATH} "
73+ echo ' {}' > " ${CONFIG_PATH} "
11074fi
11175
11276if [[ -f " ${CONFIG_PATH} " ]]; then
11377 if [[ " ${RUNNING_IN_EVG:- " false" } " != " true" ]]; then
11478 echo " Checking if container registry credentials are valid..."
115- ecr_auth=$( exec_cmd jq -r ' .auths."268558157000.dkr.ecr.us-east-1.amazonaws.com".auth // empty' " ${CONFIG_PATH} " )
79+ ecr_auth=$( jq -r ' .auths."268558157000.dkr.ecr.us-east-1.amazonaws.com".auth // empty' " ${CONFIG_PATH} " )
11680
11781 if [[ -n " ${ecr_auth} " ]]; then
11882 http_status=$( curl --head -s -o /dev/null -w " %{http_code}" --max-time 3 " https://268558157000.dkr.ecr.us-east-1.amazonaws.com/v2/dev/mongodb-kubernetes/manifests/latest" \
@@ -132,10 +96,10 @@ if [[ -f "${CONFIG_PATH}" ]]; then
13296
13397 # There could be some leftovers on Evergreen (Docker-specific, skip for Podman)
13498 if [[ " ${CONTAINER_RUNTIME} " == " docker" ]]; then
135- if exec_cmd grep -q " credsStore" " ${CONFIG_PATH} " ; then
99+ if grep -q " credsStore" " ${CONFIG_PATH} " ; then
136100 remove_element " credsStore"
137101 fi
138- if exec_cmd grep -q " credHelpers" " ${CONFIG_PATH} " ; then
102+ if grep -q " credHelpers" " ${CONFIG_PATH} " ; then
139103 remove_element " credHelpers"
140104 fi
141105 fi
@@ -149,7 +113,7 @@ aws ecr get-login-password --region "us-east-1" | registry_login "AWS" "26855815
149113# by default docker tries to store credentials in an external storage (e.g. OS keychain) - not in the config.json
150114# We need to store it as base64 string in config.json instead so we need to remove the "credsStore" element
151115# This is Docker-specific behavior, Podman stores credentials directly in auth.json
152- if [[ " ${CONTAINER_RUNTIME} " == " docker" ]] && exec_cmd grep -q " credsStore" " ${CONFIG_PATH} " ; then
116+ if [[ " ${CONTAINER_RUNTIME} " == " docker" ]] && grep -q " credsStore" " ${CONFIG_PATH} " ; then
153117 remove_element " credsStore"
154118
155119 # login again to store the credentials into the config.json
@@ -164,8 +128,8 @@ if [[ -n "${PRERELEASE_PULLSECRET_DOCKERCONFIGJSON:-}" ]]; then
164128 quay_io_auth_file=$( mktemp)
165129 config_tmp=$( mktemp)
166130 echo " ${PRERELEASE_PULLSECRET_DOCKERCONFIGJSON} " | base64 -d > " ${quay_io_auth_file} "
167- exec_cmd jq -s ' .[0] * .[1]' " ${quay_io_auth_file} " " ${CONFIG_PATH} " > " ${config_tmp} "
168- exec_cmd mv " ${config_tmp} " " ${CONFIG_PATH} "
131+ jq -s ' .[0] * .[1]' " ${quay_io_auth_file} " " ${CONFIG_PATH} " > " ${config_tmp} "
132+ mv " ${config_tmp} " " ${CONFIG_PATH} "
169133 rm " ${quay_io_auth_file} "
170134fi
171135
0 commit comments