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

Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed May 19, 2017
1 parent faf70cf commit f2afd13
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
22 changes: 5 additions & 17 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,23 @@ jobs:
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"
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 cli-builder make test
./tasks test
- 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
34 changes: 26 additions & 8 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,20 +18,40 @@ 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 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"
fi

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

function usage {
cat <<USAGE
Usage: $0 TASK [TASK...]
Expand Down

0 comments on commit f2afd13

Please sign in to comment.