Last active
March 13, 2019 08:00
-
-
Save renatomefi/bbf44d4e8a2614b1390416c6189fbb8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# A simple script to start a Docker container | |
# and run Testinfra in it | |
# Original script: https://gist.github.com/renatomefi/bbf44d4e8a2614b1390416c6189fbb8e | |
# Author: @renatomefi https://twitter.com/renatomefi | |
# | |
set -eEuo pipefail | |
# The first parameter is a Docker tag or image id | |
declare -r DOCKER_TAG="$1" | |
printf "Starting a container for '%s'\\n" "$DOCKER_TAG" | |
declare -r DOCKER_CONTAINER=$(docker run --rm -t -d "$DOCKER_TAG") | |
# Let's register a trap function, if our tests fail, finish or the scrip gets | |
# interrupted, we'll still be able to remove the running container | |
function tearDown { | |
docker rm -f "$DOCKER_CONTAINER" &>/dev/null | |
} | |
trap tearDown EXIT TERM ERR | |
# Finally, run the tests! | |
docker run --rm -t \ | |
-v "$(pwd)/test:/tests" \ | |
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | |
renatomefi/docker-testinfra:1 \ | |
--verbose --hosts="docker://$DOCKER_CONTAINER" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment