Skip to content

Commit 352f610

Browse files
iavigorpecovnik
authored andcommitted
(#9400 P2b) host: docker: replace seven echo|grep subshells with here-strings
Seven near-identical `echo "${DOCKER_INFO}" | grep -i -e <key>: | cut -d : -f 2 | xargs echo -n` chains parse fields out of cached `docker info` output. Replace each with `grep -i -e <key>: <<< "${DOCKER_INFO}" | cut -d : -f 2 | xargs echo -n`. The here-string and `echo "${DOCKER_INFO}"` produce the same bytes on stdin (one trailing newline), so grep, cut and xargs see identical input and emit the same field value. The change drops one subshell + one echo process per invocation; `get_docker_info_once` runs these in a tight sequence at the top of every Docker-mode build. Part of #9400 (P2b). Assisted-by: Claude:claude-opus-4.7
1 parent 4c6da5d commit 352f610

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/functions/host/docker.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,26 @@ function docker_cli_prepare() {
192192
# Detect some docker info; use cached.
193193
get_docker_info_once
194194

195-
DOCKER_SERVER_VERSION="$(echo "${DOCKER_INFO}" | grep -i -e "Server Version:" | cut -d ":" -f 2 | xargs echo -n)"
195+
DOCKER_SERVER_VERSION="$(grep -i -e "Server Version:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
196196
display_alert "Docker Server version" "${DOCKER_SERVER_VERSION}" "debug"
197197

198-
DOCKER_SERVER_KERNEL_VERSION="$(echo "${DOCKER_INFO}" | grep -i -e "Kernel Version:" | cut -d ":" -f 2 | xargs echo -n)"
198+
DOCKER_SERVER_KERNEL_VERSION="$(grep -i -e "Kernel Version:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
199199
display_alert "Docker Server Kernel version" "${DOCKER_SERVER_KERNEL_VERSION}" "debug"
200200

201-
DOCKER_SERVER_TOTAL_RAM="$(echo "${DOCKER_INFO}" | grep -i -e "Total memory:" | cut -d ":" -f 2 | xargs echo -n)"
201+
DOCKER_SERVER_TOTAL_RAM="$(grep -i -e "Total memory:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
202202
display_alert "Docker Server Total RAM" "${DOCKER_SERVER_TOTAL_RAM}" "debug"
203203

204-
DOCKER_SERVER_CPUS="$(echo "${DOCKER_INFO}" | grep -i -e "CPUs:" | cut -d ":" -f 2 | xargs echo -n)"
204+
DOCKER_SERVER_CPUS="$(grep -i -e "CPUs:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
205205
display_alert "Docker Server CPUs" "${DOCKER_SERVER_CPUS}" "debug"
206206

207-
DOCKER_SERVER_OS="$(echo "${DOCKER_INFO}" | grep -i -e "Operating System:" | cut -d ":" -f 2 | xargs echo -n)"
207+
DOCKER_SERVER_OS="$(grep -i -e "Operating System:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
208208
display_alert "Docker Server OS" "${DOCKER_SERVER_OS}" "debug"
209209

210210
declare -g DOCKER_ARMBIAN_HOST_OS_UNAME
211211
DOCKER_ARMBIAN_HOST_OS_UNAME="$(uname)"
212212
display_alert "Local uname" "${DOCKER_ARMBIAN_HOST_OS_UNAME}" "debug"
213213

214-
DOCKER_BUILDX_VERSION="$(echo "${DOCKER_INFO}" | grep -i -e "buildx:" | cut -d ":" -f 2 | xargs echo -n)"
214+
DOCKER_BUILDX_VERSION="$(grep -i -e "buildx:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
215215
display_alert "Docker Buildx version" "${DOCKER_BUILDX_VERSION}" "debug"
216216

217217
declare -g DOCKER_HAS_BUILDX=no
@@ -222,7 +222,7 @@ function docker_cli_prepare() {
222222
fi
223223
display_alert "Docker has buildx?" "${DOCKER_HAS_BUILDX}" "debug"
224224

225-
DOCKER_SERVER_NAME_HOST="$(echo "${DOCKER_INFO}" | grep -i -e "name:" | cut -d ":" -f 2 | xargs echo -n)"
225+
DOCKER_SERVER_NAME_HOST="$(grep -i -e "name:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
226226
display_alert "Docker Server Hostname" "${DOCKER_SERVER_NAME_HOST}" "debug"
227227

228228
# Gymnastics: under Darwin, Docker Desktop and Rancher Desktop in dockerd mode behave differently.

0 commit comments

Comments
 (0)