@@ -5,9 +5,7 @@ set -eu -o pipefail
55dev_image=docker-cli-dev
66linter_image=docker-cli-lint
77cross_image=docker-cli-cross
8- mounts=" -v $PWD :/go/src/github.com/docker/cli"
98
10- if [ -t 1 ] ; then use_tty=" -ti" ; else use_tty=" " ; fi
119
1210function run_task {
1311 local task=$1
@@ -20,34 +18,66 @@ function run_task {
2018
2119 case $task in
2220 lint|lint-shell)
23- docker build -t " $linter_image " -f ./dockerfiles/Dockerfile.lint .
24- docker run --rm $use_tty $mounts " $linter_image " $cmd
21+ docker_build_and_run " $linter_image " ./dockerfiles/Dockerfile.lint " $cmd "
2522 ;;
2623 cross|dynbinary|cross-shell)
27- docker build -t " $cross_image " -f ./dockerfiles/Dockerfile.cross .
28- docker run --rm $use_tty $mounts " $cross_image " $cmd
24+ docker_build_and_run " $cross_image " ./dockerfiles/Dockerfile.cross " $cmd "
2925 ;;
3026 * )
31- docker build -t " $dev_image " -f ./dockerfiles/Dockerfile.dev .
32- docker run --rm $use_tty $mounts " $dev_image " $cmd
27+ docker_build_and_run " $dev_image " ./dockerfiles/Dockerfile.dev " $cmd "
3328 ;;
3429 esac
3530}
3631
32+ function docker_build_and_run {
33+ local image=$1
34+ local dockerfile=$2
35+ local cmd=$3
36+ local dockerfile_source=
37+ local cidfile=
38+ local remove=" --rm"
39+ local envvars=" -e VERSION -e GITCOMMIT -e BUILDTIME -e LDFLAGS"
40+ local mounts=" -v $PWD :/go/src/github.com/docker/cli"
41+ if [ -t 1 ] ; then local use_tty=" -ti" ; else local use_tty=" " ; fi
42+
43+ if [ -n " ${DOCKER_HOST:- } " ] || [ -n " ${NO_BINDMOUNT:- } " ]; then
44+ dockerfile_source=" $( cat $dockerfile <( echo COPY . .) ) "
45+ mounts=" "
46+ dockerfile=" -"
47+ fi
48+
49+ if [ -n " ${CID_FILENAME:- } " ]; then
50+ cidfile=" --cidfile $CID_FILENAME "
51+ remove=
52+ fi
53+
54+ echo " $dockerfile_source " | docker build -t " $image " -f " $dockerfile " .
55+ docker run $remove $envvars $cidfile $use_tty $mounts " $image " $cmd
56+ }
57+
3758function usage {
59+ local tasks=" See Makefile for a list of task names."
60+ if command -v make awk sort grep > /dev/null; then
61+ # this ugly command is supposed to list the targets in a Makefile
62+ tasks=" $( set +o pipefail; echo ; make -qp | \
63+ awk -F' :' ' /^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /); for(i in A) print " " A[i]}' | \
64+ sort -u | grep -v Makefile) "
65+ tasks=" TASK may be one of: $tasks "
66+ fi
67+
3868 cat << USAGE
3969Usage: $0 TASK [TASK...]
4070
4171Run a project task in the appropriate Docker image.
4272
43- TASK may be the name of a target in the Makefile or one of:
44- shell, lint-shell, cross-shell
73+ $tasks
4574USAGE
4675 exit 1
4776}
4877
49- if [ -z " $@ " ] || [ " $@ " = " --help" ]; then usage; fi
78+ tasks=" $@ "
79+ if [ -z " $tasks " ] || [ " ${tasks[0]} " = " --help" ]; then usage; fi
5080
51- for task in $@ ; do
81+ for task in $tasks ; do
5282 run_task $task
5383done
0 commit comments