diff --git a/docker/.gitignore b/docker/.gitignore index cd6c6bdf82..9bde4bb3cb 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,3 +1,4 @@ pantheon-*.tar.gz pantheon/* -pantheon-* \ No newline at end of file +pantheon-* +reports/* \ No newline at end of file diff --git a/docker/test.sh b/docker/test.sh index 43d2f91fa6..41bad75ef9 100755 --- a/docker/test.sh +++ b/docker/test.sh @@ -4,21 +4,26 @@ export GOSS_PATH=tests/goss-linux-amd64 export GOSS_OPTS="$GOSS_OPTS --format junit" export GOSS_FILES_STRATEGY=cp DOCKER_IMAGE=$1 +DOCKER_FILE="${2:-$PWD/Dockerfile}" i=0 +## Checks on the Dockerfile +GOSS_FILES_PATH=tests/00 \ +bash tests/dgoss dockerfile $DOCKER_IMAGE $DOCKER_FILE \ +> ./reports/00.xml || i=`expr $i + 1` +# fail fast if we dont pass static checks +if [[ $i != 0 ]]; then exit $i; fi + # Test for normal startup with ports opened +# we test that things listen on the right interface/port, not what interface the advertise +# hence we dont set p2p-host=0.0.0.0 because this sets what its advertising to devp2p; the important piece is that it defaults to listening on all interfaces GOSS_FILES_PATH=tests/01 \ -bash tests/dgoss \ -run $DOCKER_IMAGE \ +bash tests/dgoss run $DOCKER_IMAGE \ --network=dev \ ---p2p-host=0.0.0.0 \ --rpc-http-enabled \ ---rpc-http-host=0.0.0.0 \ --rpc-ws-enabled \ ---rpc-ws-host=0.0.0.0 \ --graphql-http-enabled \ ---graphql-http-host=0.0.0.0 \ > ./reports/01.xml || i=`expr $i + 1` exit $i diff --git a/docker/tests/00/goss.yaml b/docker/tests/00/goss.yaml new file mode 100644 index 0000000000..c0e8c09ef4 --- /dev/null +++ b/docker/tests/00/goss.yaml @@ -0,0 +1,12 @@ +--- +# static Dockerfile tests + +# ensure there are env vars set in the dockerfile +file: + /goss/Dockerfile: + exists: true + contains: + - "/ENV PANTHEON_RPC_HTTP_HOST 0.0.0.0/" + - "/ENV PANTHEON_RPC_WS_HOST 0.0.0.0/" + - "/ENV PANTHEON_GRAPHQL_HTTP_HOST 0.0.0.0/" + diff --git a/docker/tests/01/goss.yaml b/docker/tests/01/goss.yaml index 1abede5d6b..996e86f843 100644 --- a/docker/tests/01/goss.yaml +++ b/docker/tests/01/goss.yaml @@ -1,3 +1,5 @@ +--- +# runtime docker tests file: /opt/pantheon/bin/pantheon: exists: true @@ -20,21 +22,6 @@ file: group: root filetype: file contains: [] -port: - tcp:8545: - listening: true - tcp:8546: - listening: true - tcp:8547: - listening: true - tcp:30303: - listening: true - ip: - - 0.0.0.0 - udp:30303: - listening: true - ip: - - 0.0.0.0 process: java: running: true diff --git a/docker/tests/01/goss_wait.yaml b/docker/tests/01/goss_wait.yaml index 7e81811985..129efc9734 100644 --- a/docker/tests/01/goss_wait.yaml +++ b/docker/tests/01/goss_wait.yaml @@ -1,8 +1,14 @@ +--- +# runtime docker tests for interfaces & ports port: tcp:30303: listening: true ip: - 0.0.0.0 + udp:30303: + listening: true + ip: + - 0.0.0.0 tcp:8545: listening: true ip: diff --git a/docker/tests/dgoss b/docker/tests/dgoss index e2e06174e1..59bbc4683e 100755 --- a/docker/tests/dgoss +++ b/docker/tests/dgoss @@ -2,7 +2,7 @@ set -e -USAGE="USAGE: $(basename "$0") [run|edit] " +USAGE="USAGE: $(basename "$0") [run|edit|dockerfile] " GOSS_FILES_PATH="${GOSS_FILES_PATH:-.}" info() { @@ -23,13 +23,18 @@ cleanup() { fi } -run(){ - # Copy in goss +# Copy goss & any config into a folder which then gets mounted as a volume +# Run the container and perform the checks +setup_container(){ + info "Setting up test dir" cp "${GOSS_PATH}" "$tmp_dir/goss" chmod 755 "$tmp_dir/goss" [[ -e "${GOSS_FILES_PATH}/goss.yaml" ]] && cp "${GOSS_FILES_PATH}/goss.yaml" "$tmp_dir" [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir" [[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir" + # copy the Dockerfile if path has been provided + [[ ! -z "${3}" ]] && [[ "${3}" == *"Dockerfile"* ]] && cp "${3}" "$tmp_dir" + info "Setup complete" # Switch between mount or cp files strategy GOSS_FILES_STRATEGY=${GOSS_FILES_STRATEGY:="mount"} @@ -54,7 +59,7 @@ run(){ info "Container ID: ${id:0:8}" } -get_docker_file() { +get_file_from_docker() { if docker exec "$id" sh -c "test -e $1" > /dev/null;then mkdir -p "${GOSS_FILES_PATH}" info "Copied '$1' from container to '${GOSS_FILES_PATH}'" @@ -75,7 +80,8 @@ GOSS_SLEEP=${GOSS_SLEEP:-0.2} case "$1" in run) - run "$@" + info "Run Docker tests" + setup_container "$@" if [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]]; then info "Found goss_wait.yaml, waiting for it to pass before running tests" if [[ -z "${GOSS_VARS}" ]]; then @@ -100,13 +106,19 @@ case "$1" in docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS" fi ;; + dockerfile) + info "Run Dockerfile tests" + setup_container "$@" + docker exec "$id" sh -c "cat /goss/goss.yaml" + docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS" + ;; edit) - run "$@" + setup_container "$@" info "Run goss add/autoadd to add resources" docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh' - get_docker_file "/goss/goss.yaml" - get_docker_file "/goss/goss_wait.yaml" - [[ ! -z "${GOSS_VARS}" ]] && get_docker_file "/goss/${GOSS_VARS}" + get_file_from_docker "/goss/goss.yaml" + get_file_from_docker "/goss/goss_wait.yaml" + [[ ! -z "${GOSS_VARS}" ]] && get_file_from_docker "/goss/${GOSS_VARS}" ;; *) error "$USAGE"