Skip to content

Commit

Permalink
Support NO_BINDMOUNT in tasks
Browse files Browse the repository at this point in the history
Use ./tasks in circleci
List task targets with './tasks --help'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed May 23, 2017
1 parent ce3ebb6 commit 760553b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cli/winresources/rsrc_386.syso
cli/winresources/rsrc_amd64.syso
coverage.txt
profile.out
.cid
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,20 @@ Docker EE products.
Development
===========

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

Build a linux binary:

```
$ ./tasks binary
```

Build binaries for all supported platforms:

```
$ ./tasks cross
```

Run all linting:

```
$ ./tasks lint
```

You can see a full list of tasks with `./tasks --help`.

### In-container development environment

Start an interactive development environment:
Expand All @@ -38,7 +31,8 @@ Start an interactive development environment:
$ ./tasks shell
```

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

```
$ make binary
Expand Down
28 changes: 8 additions & 20 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,33 @@ jobs:
steps:
- run:
name: "Install Git and SSH"
command: apk add -U git openssh
command: apk add -U git openssh bash
- checkout
- setup_remote_docker
- run:
name: "Lint"
command: |
if [ "$CIRCLE_NODE_INDEX" != "0" ]; then exit; fi
dockerfile=dockerfiles/Dockerfile.lint
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-linter .
docker run cli-linter
./tasks lint
- run:
name: "Cross"
command: |
if [ "$CIRCLE_NODE_INDEX" != "1" ]; then exit; fi
dockerfile=dockerfiles/Dockerfile.cross
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder .
docker run --name cross cli-builder make cross
docker cp cross:/go/src/github.com/docker/cli/build /work/build
CID_FILENAME=.cid ./tasks cross
docker cp $(cat .cid):/go/src/github.com/docker/cli/build /work/build
- run:
name: "Unit Test with Coverage"
command: |
if [ "$CIRCLE_NODE_INDEX" != "2" ]; then exit; fi
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder .
docker run --name test cli-builder make test-coverage
docker cp test:/go/src/github.com/docker/cli/coverage.txt coverage.txt
apk add -U bash curl
CID_FILENAME=.cid ./tasks test-coverage
docker cp $(cat .cid):/go/src/github.com/docker/cli/coverage.txt coverage.txt
apk add -U curl
curl -s https://codecov.io/bash | bash
- run:
name: "Validate Vendor and Code Generation"
command: |
if [ "$CIRCLE_NODE_INDEX" != "3" ]; then exit; fi
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder .
docker run cli-builder make -B vendor compose-jsonschema
./tasks vendor compose-jsonschema
- store_artifacts:
path: /work/build
54 changes: 42 additions & 12 deletions tasks
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ set -eu -o pipefail
dev_image=docker-cli-dev
linter_image=docker-cli-lint
cross_image=docker-cli-cross
mounts="-v $PWD:/go/src/github.com/docker/cli"

if [ -t 1 ] ; then use_tty="-ti"; else use_tty=""; fi

function run_task {
local task=$1
Expand All @@ -20,34 +18,66 @@ function run_task {

case $task in
lint|lint-shell)
docker build -t "$linter_image" -f ./dockerfiles/Dockerfile.lint .
docker run --rm $use_tty $mounts "$linter_image" $cmd
docker_build_and_run "$linter_image" ./dockerfiles/Dockerfile.lint "$cmd"
;;
cross|dynbinary|cross-shell)
docker build -t "$cross_image" -f ./dockerfiles/Dockerfile.cross .
docker run --rm $use_tty $mounts "$cross_image" $cmd
docker_build_and_run "$cross_image" ./dockerfiles/Dockerfile.cross "$cmd"
;;
*)
docker build -t "$dev_image" -f ./dockerfiles/Dockerfile.dev .
docker run --rm $use_tty $mounts "$dev_image" $cmd
docker_build_and_run "$dev_image" ./dockerfiles/Dockerfile.dev "$cmd"
;;
esac
}

function docker_build_and_run {
local image=$1
local dockerfile=$2
local cmd=$3
local dockerfile_source=
local cidfile=
local remove="--rm"
local envvars="-e VERSION -e GITCOMMIT -e BUILDTIME -e LDFLAGS"
local mounts="-v $PWD:/go/src/github.com/docker/cli"
if [ -t 1 ] ; then local use_tty="-ti"; else local use_tty=""; fi

if [ -n "${DOCKER_HOST:-}" ] || [ -n "${NO_BINDMOUNT:-}" ]; then
dockerfile_source="$(cat $dockerfile <(echo COPY . .))"
mounts=""
dockerfile="-"
fi

if [ -n "${CID_FILENAME:-}" ]; then
cidfile="--cidfile $CID_FILENAME"
remove=
fi

echo "$dockerfile_source" | docker build -t "$image" -f "$dockerfile" .
docker run $remove $envvars $cidfile $use_tty $mounts "$image" $cmd
}

function usage {
local tasks="See Makefile for a list of task names."
if command -v make awk sort grep > /dev/null; then
# this ugly command is supposed to list the targets in a Makefile
tasks="$(set +o pipefail; echo; make -qp | \
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /); for(i in A) print " " A[i]}' | \
sort -u | grep -v Makefile)"
tasks="TASK may be one of: $tasks"
fi

cat <<USAGE
Usage: $0 TASK [TASK...]
Run a project task in the appropriate Docker image.
TASK may be the name of a target in the Makefile or one of:
shell, lint-shell, cross-shell
$tasks
USAGE
exit 1
}

if [ -z "$@" ] || [ "$@" = "--help" ]; then usage; fi
tasks="$@"
if [ -z "$tasks" ] || [ "${tasks[0]}" = "--help" ]; then usage; fi

for task in $@; do
for task in $tasks; do
run_task $task
done

0 comments on commit 760553b

Please sign in to comment.