Skip to content

Commit a7db3b9

Browse files
committed
scripts: imp docker build
1 parent 5101abd commit a7db3b9

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

scripts/make/build-docker.sh

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ fi
2727
readonly version
2828

2929
# Allow users to use sudo.
30-
sudo_cmd="${SUDO:-}"
30+
sudo_cmd="${SUDO:-exec}"
3131
readonly sudo_cmd
3232

33+
# Make sure that those are built using something like:
34+
# make ARCH='386 amd64 arm arm64 ppc64le' OS=linux VERBOSE=1 build-release
3335
docker_platforms="\
3436
linux/386,\
3537
linux/amd64,\
@@ -104,20 +106,46 @@ cp "${dist_dir}/AdGuardHome_linux_arm_7/AdGuardHome/AdGuardHome" \
104106
cp "${dist_dir}/AdGuardHome_linux_ppc64le/AdGuardHome/AdGuardHome" \
105107
"${dist_docker}/AdGuardHome_linux_ppc64le_"
106108

107-
# Don't use quotes with $docker_version_tag and $docker_channel_tag, because we
108-
# want word splitting and or an empty space if tags are empty.
109-
#
110-
# TODO(a.garipov): Once flag --tag of docker buildx build supports commas, use
111-
# them instead.
112-
#
113-
# shellcheck disable=SC2086
114-
$sudo_cmd docker "$debug_flags" \
115-
buildx build \
116-
--build-arg BUILD_DATE="$build_date" \
117-
--build-arg DIST_DIR="$dist_dir" \
118-
--build-arg VCS_REF="$commit" \
119-
--build-arg VERSION="$version" \
120-
--output "$docker_output" \
121-
--platform "$docker_platforms" \
122-
--progress 'plain' \
123-
$docker_version_tag $docker_channel_tag -f ./docker/Dockerfile .
109+
# docker_opt_tag is a function that wraps the call to docker to optionally add
110+
# --tag flags.
111+
docker_opt_tag() {
112+
# Unset all positional parameters of the function.
113+
set --
114+
115+
# Set the initial parameters.
116+
set -- \
117+
"$debug_flags" \
118+
buildx \
119+
build \
120+
--build-arg BUILD_DATE="$build_date" \
121+
--build-arg DIST_DIR="$dist_dir" \
122+
--build-arg VCS_REF="$commit" \
123+
--build-arg VERSION="$version" \
124+
--output "$docker_output" \
125+
--platform "$docker_platforms" \
126+
--progress 'plain' \
127+
;
128+
129+
# Append the channel tag, if any.
130+
if [ "$docker_channel_tag" != '' ]; then
131+
set -- "$@" "$docker_channel_tag"
132+
fi
133+
134+
# Append the version tag, if any.
135+
if [ "$docker_version_tag" != '' ]; then
136+
set -- "$@" "$docker_version_tag"
137+
fi
138+
139+
# Append the rest.
140+
set -- \
141+
"$@" \
142+
-f \
143+
./docker/Dockerfile \
144+
. \
145+
;
146+
147+
# Call the docker command with the assembled parameters.
148+
"$sudo_cmd" docker "$@"
149+
}
150+
151+
docker_opt_tag

0 commit comments

Comments
 (0)