Skip to content

Commit 12df9a4

Browse files
committed
Support NO_BINDMOUNT in tasks
Use ./tasks in circleci List task targets with './tasks --help' Signed-off-by: Daniel Nephin <dnephin@docker.com>
1 parent 355a5f3 commit 12df9a4

File tree

4 files changed

+55
-41
lines changed

4 files changed

+55
-41
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/build/
33
cli/winresources/rsrc_386.syso
44
cli/winresources/rsrc_amd64.syso
5+
.cid
6+
coverage.txt

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,20 @@ Docker EE products.
99
Development
1010
===========
1111

12-
`docker/cli` is developed using Docker. The `./tasks` script is used to run
13-
build Docker images and run Docker containers.
12+
The `./tasks` script allows you to build and develop the cli with Docker.
1413

1514
Build a linux binary:
16-
1715
```
1816
$ ./tasks binary
1917
```
2018

21-
Build binaries for all supported platforms:
22-
23-
```
24-
$ ./tasks cross
25-
```
26-
2719
Run all linting:
28-
2920
```
3021
$ ./tasks lint
3122
```
3223

24+
You can see a full list of tasks with `./tasks --help`.
25+
3326
### In-container development environment
3427

3528
Start an interactive development environment:
@@ -38,7 +31,8 @@ Start an interactive development environment:
3831
$ ./tasks shell
3932
```
4033

41-
In the development environment you can run many tasks, including build binaries:
34+
From the interactive development shell you can run tasks defined in the
35+
Makefile. For example, to build a binary you would run:
4236

4337
```
4438
$ make binary

circle.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,30 @@ jobs:
88
steps:
99
- run:
1010
name: "Install Git and SSH"
11-
command: apk add -U git openssh
11+
command: apk add -U git openssh bash
1212
- checkout
1313
- setup_remote_docker
1414
- run:
1515
name: "Lint"
1616
command: |
1717
if [ "$CIRCLE_NODE_INDEX" != "0" ]; then exit; fi
18-
dockerfile=dockerfiles/Dockerfile.lint
19-
echo "COPY . ." >> $dockerfile
20-
docker build -f $dockerfile --tag cli-linter .
21-
docker run cli-linter
18+
./tasks lint
2219
- run:
2320
name: "Cross"
2421
command: |
2522
if [ "$CIRCLE_NODE_INDEX" != "1" ]; then exit; fi
26-
dockerfile=dockerfiles/Dockerfile.cross
27-
echo "COPY . ." >> $dockerfile
28-
docker build -f $dockerfile --tag cli-builder .
29-
docker run --name cross cli-builder make cross
30-
docker cp cross:/go/src/github.com/docker/cli/build /work/build
23+
CID_FILENAME=.cid ./tasks cross
24+
docker cp $(cat .cid):/go/src/github.com/docker/cli/build /work/build
3125
- run:
3226
name: "Unit Test"
3327
command: |
3428
if [ "$CIRCLE_NODE_INDEX" != "2" ]; then exit; fi
35-
dockerfile=dockerfiles/Dockerfile.dev
36-
echo "COPY . ." >> $dockerfile
37-
docker build -f $dockerfile --tag cli-builder .
38-
docker run cli-builder make test
29+
./tasks test
3930
- run:
4031
name: "Validate Vendor and Code Generation"
4132
command: |
4233
if [ "$CIRCLE_NODE_INDEX" != "3" ]; then exit; fi
43-
dockerfile=dockerfiles/Dockerfile.dev
44-
echo "COPY . ." >> $dockerfile
45-
docker build -f $dockerfile --tag cli-builder .
46-
docker run cli-builder make -B vendor compose-jsonschema
34+
./tasks vendor compose-jsonschema
4735
4836
- store_artifacts:
4937
path: /work/build

tasks

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ set -eu -o pipefail
55
dev_image=docker-cli-dev
66
linter_image=docker-cli-lint
77
cross_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

1210
function 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+
3758
function 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
3969
Usage: $0 TASK [TASK...]
4070
4171
Run 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
4574
USAGE
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
5383
done

0 commit comments

Comments
 (0)