From 760553b7cf65475403ac889d1b690f2f90531fe9 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 19 May 2017 15:42:40 -0400 Subject: [PATCH] Support NO_BINDMOUNT in tasks Use ./tasks in circleci List task targets with './tasks --help' Signed-off-by: Daniel Nephin --- .gitignore | 1 + README.md | 16 +++++----------- circle.yml | 28 ++++++++-------------------- tasks | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 09d363d1ce56..acdcb8fc8d3f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ cli/winresources/rsrc_386.syso cli/winresources/rsrc_amd64.syso coverage.txt profile.out +.cid diff --git a/README.md b/README.md index 7f64c42c3d9e..10317b35a764 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/circle.yml b/circle.yml index dabc4c5aadce..3491ce4408f7 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/tasks b/tasks index 731d2c84fb5a..d4a2f77b06d7 100755 --- a/tasks +++ b/tasks @@ -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 @@ -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 <