@@ -4,12 +4,9 @@ verbose="${VERBOSE:-0}"
44
55if [ " $verbose " -gt ' 0' ]; then
66 set -x
7- debug_flags=' --debug=1'
87else
98 set +x
10- debug_flags=' --debug=0'
119fi
12- readonly debug_flags
1310
1411set -e -f -u
1512
@@ -40,15 +37,9 @@ readonly build_date
4037docker_image_name=" ${DOCKER_IMAGE_NAME:- dnsproxy-dev} "
4138readonly docker_image_name
4239
43- # Set DOCKER_OUTPUT to 'type=image,name=adguard/dnsproxy,push=true' if you
44- # want (and are allowed) to push to DockerHub.
45- #
46- # If you want to inspect the resulting image using commands like "docker image
47- # ls", change type to docker and also set docker_platforms to a single platform.
48- #
49- # See https://github.com/docker/buildx/issues/166.
50- docker_output=" ${DOCKER_OUTPUT:- type=image,name=${docker_image_name} ,push=false} "
51- readonly docker_output
40+ # Set DOCKER_PUSH to '1' if you want (and are allowed) to push to DockerHub.
41+ docker_push=" ${DOCKER_PUSH:- 0} "
42+ readonly docker_push
5243
5344docker_version_tag=" --tag=${docker_image_name} :${version} "
5445docker_channel_tag=" --tag=${docker_image_name} :latest"
@@ -84,24 +75,50 @@ cp "${dist_dir}/linux-ppc64le/dnsproxy" \
8475# Prepare the default configuration for the Docker image.
8576cp ./config.yaml.dist " ${dist_docker} /config.yaml"
8677
87- # Don't use quotes with $docker_version_tag and $docker_channel_tag, because we
88- # want word splitting and or an empty space if tags are empty.
89- #
90- # TODO(a.garipov): Once flag --tag of docker buildx build supports commas, use
91- # them instead.
92- #
93- # shellcheck disable=SC2086
94- $sudo_cmd docker \
95- " $debug_flags " \
96- buildx build \
97- --build-arg BUILD_DATE=" $build_date " \
98- --build-arg DIST_DIR=" $dist_dir " \
99- --build-arg VCS_REF=" $commit " \
100- --build-arg VERSION=" $version " \
101- --output " $docker_output " \
102- --platform " $docker_platforms " \
103- $docker_version_tag \
104- $docker_channel_tag \
105- -f ./docker/build.Dockerfile \
106- . \
107- ;
78+ # docker_build_opt_tag is a function that wraps the call of docker build command
79+ # with optionally --tag flags.
80+ docker_build_opt_tag () {
81+ if [ " $sudo_cmd " != ' ' ]; then
82+ set -- " $sudo_cmd "
83+ fi
84+
85+ # Set the initial parameters.
86+ set -- \
87+ " $@ " \
88+ docker \
89+ buildx \
90+ build \
91+ --build-arg BUILD_DATE=" $build_date " \
92+ --build-arg DIST_DIR=" $dist_dir " \
93+ --build-arg VCS_REF=" $commit " \
94+ --build-arg VERSION=" $version " \
95+ --platform " $docker_platforms " \
96+ --progress ' plain' \
97+ ;
98+
99+ # Append the channel tag, if any.
100+ if [ " $docker_channel_tag " != ' ' ]; then
101+ set -- " $@ " " $docker_channel_tag "
102+ fi
103+
104+ # Append the version tag.
105+ set -- " $@ " " $docker_version_tag "
106+
107+ # Push to DockerHub, if requested.
108+ if [ " $docker_push " -eq 1 ]; then
109+ set -- " $@ " ' --push'
110+ fi
111+
112+ # Append the rest.
113+ set -- \
114+ " $@ " \
115+ -f \
116+ ./docker/build.Dockerfile \
117+ . \
118+ ;
119+
120+ # Call the command with the assembled parameters.
121+ " $@ "
122+ }
123+
124+ docker_build_opt_tag
0 commit comments