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 Jul 13, 2017
1 parent 37250be commit 2d03cfc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cli/winresources/rsrc_amd64.syso
/docs/yaml/gen/
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
46 changes: 12 additions & 34 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:

lint:
working_directory: /work
docker: [{image: 'docker:17.05-git'}]
docker: [{image: 'dnephin/docker-circleci-task-runner:17.05'}]
steps:
- checkout
- setup_remote_docker:
Expand All @@ -15,14 +15,11 @@ jobs:
- run:
name: "Lint"
command: |
dockerfile=dockerfiles/Dockerfile.lint
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-linter:$CIRCLE_BUILD_NUM .
docker run --rm cli-linter:$CIRCLE_BUILD_NUM
TASK_UNIQUE_ID=$CIRCLE_BUILD_NUM ./tasks lint
cross:
working_directory: /work
docker: [{image: 'docker:17.05-git'}]
docker: [{image: 'dnephin/docker-circleci-task-runner:17.05'}]
parallelism: 3
steps:
- checkout
Expand All @@ -32,23 +29,15 @@ jobs:
- run:
name: "Cross"
command: |
dockerfile=dockerfiles/Dockerfile.cross
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM .
name=cross-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX
docker run \
-e CROSS_GROUP=$CIRCLE_NODE_INDEX \
--name $name cli-builder:$CIRCLE_BUILD_NUM \
make cross
docker cp \
$name:/go/src/github.com/docker/cli/build \
/work/build
TASK_UNIQUE_ID=$CIRCLE_BUILD_NUM CID_FILENAME=.cid ./tasks cross
docker cp $(cat .cid):/go/src/github.com/docker/cli/build /work/build
- store_artifacts:
path: /work/build

test:
working_directory: /work
docker: [{image: 'docker:17.05-git'}]
docker: [{image: 'dnephin/docker-circleci-task-runner:17.05'}]
steps:
- checkout
- setup_remote_docker:
Expand All @@ -57,25 +46,17 @@ jobs:
- run:
name: "Unit Test with Coverage"
command: |
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
docker build -f $dockerfile --tag cli-builder:$CIRCLE_BUILD_NUM .
docker run --name \
test-$CIRCLE_BUILD_NUM cli-builder:$CIRCLE_BUILD_NUM \
make test-coverage
TASK_UNIQUE_ID=$CIRCLE_BUILD_NUM CID_FILENAME=.cid ./tasks test-coverage
- run:
name: "Upload to Codecov"
command: |
docker cp \
test-$CIRCLE_BUILD_NUM:/go/src/github.com/docker/cli/coverage.txt \
coverage.txt
apk add -U bash curl
docker cp $(cat .cid):/go/src/github.com/docker/cli/coverage.txt coverage.txt
curl -s https://codecov.io/bash | bash
validate:
working_directory: /work
docker: [{image: 'docker:17.05-git'}]
docker: [{image: 'dnephin/docker-circleci-task-runner:17.05'}]
steps:
- run: apk add -U git openssh
- checkout
Expand All @@ -85,12 +66,9 @@ jobs:
- run:
name: "Validate Vendor, Docs, and Code Generation"
command: |
dockerfile=dockerfiles/Dockerfile.dev
echo "COPY . ." >> $dockerfile
rm -f .dockerignore # include .git
docker build -f $dockerfile --tag cli-builder-with-git:$CIRCLE_BUILD_NUM .
docker run --rm cli-builder-with-git:$CIRCLE_BUILD_NUM \
make -B vendor compose-jsonschema manpages yamldocs
export TASK_UNIQUE_ID=$CIRCLE_BUILD_NUM
./tasks vendor compose-jsonschema manpages yamldocs
workflows:
version: 2
Expand Down
3 changes: 2 additions & 1 deletion scripts/build/.variables
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -eu

default_version=$(cat VERSION)
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
default_version=$(cat $scriptdir/../../VERSION)
VERSION=${VERSION:-"$default_version"}
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
BUILDTIME=${BUILDTIME:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')}
Expand Down
65 changes: 48 additions & 17 deletions tasks
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

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
unique_id=${TASK_UNIQUE_ID:-$USER}
dev_image="docker-cli-dev:$unique_id"
linter_image="docker-cli-lint:$unique_id"
cross_image="docker-cli-cross:$unique_id"

function run_task {
local task=$1
Expand All @@ -17,37 +15,70 @@ function run_task {
else
local cmd="make $task"
fi

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"
# Use an array to preserve whitespace in $PWD
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[@]+"${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 2d03cfc

Please sign in to comment.