Skip to content

Instantly share code, notes, and snippets.

@renatomefi
Last active March 13, 2019 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatomefi/bbf44d4e8a2614b1390416c6189fbb8e to your computer and use it in GitHub Desktop.
Save renatomefi/bbf44d4e8a2614b1390416c6189fbb8e to your computer and use it in GitHub Desktop.
#!/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