#!/bin/bash
# This should be run inside a container built from the Dockerfile
# at the root of the repo - script/test will do it automatically.

set -e

>&2 echo "Running lint checks"
docker run --rm \
  ${GIT_VOLUME} \
  --entrypoint="tox" \
  "$TAG" -e pre-commit

if [ "$DOCKER_VERSIONS" == "" ]; then
  DOCKER_VERSIONS="default"
elif [ "$DOCKER_VERSIONS" == "all" ]; then
  DOCKER_VERSIONS="$ALL_DOCKER_VERSIONS"
fi

for version in $DOCKER_VERSIONS; do
  >&2 echo "Running tests against Docker $version"
  docker run \
    --rm \
    --privileged \
    --volume="/var/lib/docker" \
    --volume="${COVERAGE_DIR:-$(pwd)/coverage-html}:/code/coverage-html" \
    -e "DOCKER_VERSION=$version" \
    -e "DOCKER_DAEMON_ARGS" \
    --entrypoint="script/dind" \
    "$TAG" \
    script/wrapdocker tox -e py27,py34 -- "$@"
done