-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
703e00a
commit c5e0f4f
Showing
4 changed files
with
94 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,12 @@ LABEL org.label-schema.title="Testinfra Docker container" \ | |
org.opencontainers.image.vendor="WyriHaximus.net" \ | ||
org.opencontainers.image.authors="Cees-Jan Kiewiet <[email protected]>" | ||
|
||
WORKDIR /project | ||
|
||
# hadolint ignore=DL3018 | ||
RUN apk add --no-cache docker python3 py-pip | ||
# hadolint ignore=DL3013 | ||
RUN pip install --no-cache-dir docker --break-system-packages && \ | ||
# hadolint ignore=DL3018,DL3013 | ||
RUN apk add --no-cache docker python3 py-pip && \ | ||
pip3 install --no-cache-dir --upgrade pip --break-system-packages && \ | ||
pip install --no-cache-dir docker --break-system-packages && \ | ||
pip install --no-cache-dir pytest-testinfra --break-system-packages | ||
|
||
WORKDIR /tests | ||
|
||
ENTRYPOINT ["py.test", "-p", "no:cacheprovider"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/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://github.com/renatomefi | ||
# | ||
|
||
set -eEuo pipefail | ||
|
||
# The first parameter is a Docker tag or image id | ||
declare -r DOCKER_TAG="$1" | ||
declare -r TESTINFRA_IMAGE="$2" | ||
declare -r PLATFORM="$3" | ||
|
||
printf "Starting a container for '%s'\\n" "$DOCKER_TAG" | ||
|
||
DOCKER_CONTAINER=$(docker run --rm -v "$(pwd)/tests:/tests" -v "/var/run/docker.sock:/var/run/docker.sock:ro" -t -d "$DOCKER_TAG") | ||
readonly DOCKER_CONTAINER | ||
|
||
docker ps | ||
|
||
# Let's register a trap function, if our tests fail, finish or the script gets | ||
# interrupted, we'll still be able to remove the running container | ||
function tearDown { | ||
docker logs "$DOCKER_CONTAINER" | ||
docker rm -f "$DOCKER_CONTAINER" &>/dev/null & | ||
} | ||
trap tearDown EXIT TERM ERR | ||
|
||
# Finally, run the tests! | ||
echo "Running test suite" | ||
docker run --rm -t \ | ||
--platform="$PLATFORM" \ | ||
-v "$(pwd)/tests:/tests" \ | ||
-v "$(pwd)/tmp/test-results:/results" \ | ||
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
"$TESTINFRA_IMAGE" \ | ||
--disable-pytest-warnings \ | ||
--verbose --hosts="docker://$DOCKER_CONTAINER" | ||
|
||
docker ps |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
def test_docker(host): | ||
output = host.run('docker -v') | ||
assert output.rc == 0 | ||
assert u'Docker Version ' in output.stderr | ||
assert output.stderr == '' | ||
|
||
def test_pip(host): | ||
assert host.exists("pip") | ||
|
||
def test_pytest(host): | ||
assert host.exists("py.test") | ||
|
||
# def test_pip_packages(host): | ||
# packages = host.pip_package.get_packages() | ||
# assert "pip" in packages | ||
# assert "docker" in packages | ||
# assert "testinfra" in packages | ||
# assert "paramiko" in packages |