Skip to content

Commit d645507

Browse files
authored
CCM-15190: misc fixes (#117)
* fixed typo in make args in scripts/init.mk * Handle missing ${name} in .tool-versions (fallback to "lastest") With set -euo pipefail, this grep | ... | grep pipeline will terminate the script when there is no matching docker/${name} entry in .tool-versions (a normal case). The command substitution should tolerate no matches and fall back to latest. * fix pipefail and || precedence in content= pipeline content=$(grep ...; grep -v ... ||: | grep -v ...) has two issues under set -euo pipefail: (1) the first grep will exit non-zero when there are no Docker- specific entries, which will abort the script; and (2) due to ||/| precedence, the grep -v "^#" filter is not applied when the second grep -v succeeds. This can break Docker builds in repos without docker/ entries in .tool-versions. * Unquote dangling image IDs to fix docker rmi cleanup docker rmi --force "$(...)" quotes the list of dangling image IDs, which can collapse multiple IDs into a single argument and prevent cleanup from working correctly. Collect the IDs and pass them as separate arguments. * tabs->spaces
1 parent 9c5ec7a commit d645507

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

scripts/docker/docker.lib.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function docker-build() {
5252
for version in $(_get-all-effective-versions) latest; do
5353
docker tag "${DOCKER_IMAGE}:$(_get-effective-version)" "${DOCKER_IMAGE}:${version}"
5454
done
55-
docker rmi --force "$(docker images | grep "<none>" | awk '{print $3}')" 2> /dev/null ||:
55+
local dangling_images="$(docker images -q -f dangling=true)"
56+
[[ -n "$dangling_images" ]] && docker rmi --force $dangling_images 2> /dev/null ||:
5657

5758
return 0
5859
}
@@ -188,7 +189,7 @@ function docker-get-image-version-and-pull() {
188189
local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}"
189190
local version="latest"
190191
if [[ -f "$versions_file" ]]; then
191-
line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-".*"}")
192+
line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-".*"}" || true)
192193
[ -n "$line" ] && version=$(echo "$line" | awk '{print $2}')
193194
fi
194195

@@ -248,7 +249,7 @@ function _replace-image-latest-by-specific-version() {
248249

249250
if [[ -f "$versions_file" ]]; then
250251
# First, list the entries specific for Docker to take precedence, then the rest but exclude comments
251-
content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" ||: | grep -v "^#")
252+
content=$({ grep " docker/" "$versions_file" || true; grep -v " docker/" "$versions_file" || true; } | grep -v "^#" || true)
252253
echo "$content" | while IFS= read -r line; do
253254
[ -z "$line" ] && continue
254255
line=$(echo "$line" | sed "s/^#\s*//; s/\s*#.*$//" | sed "s;docker/;;")

scripts/init.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ list-variables: # List all the variables available to make @Others
8484
.NOTPARALLEL:
8585
.ONESHELL:
8686
.PHONY: * # Please do not change this line! The alternative usage of it introduces unnecessary complexity and is considered an anti-pattern.
87-
MAKEFLAGS := --no-print-director
87+
MAKEFLAGS := --no-print-directory
8888
SHELL := /bin/bash
8989
ifeq (true, $(shell [[ "${VERBOSE}" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$$ ]] && echo true))
9090
.SHELLFLAGS := -cex

0 commit comments

Comments
 (0)