Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/http_client…
Browse files Browse the repository at this point in the history
…_cert
  • Loading branch information
aelsabbahy committed Oct 7, 2022
2 parents bb130ae + 86da245 commit 1ace6e6
Show file tree
Hide file tree
Showing 42 changed files with 1,116 additions and 211 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ updates:
- "aelsabbahy"
reviewers:
- "aelsabbahy"
open-pull-requests-limit: 0

File renamed without changes.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ env:
language: go

go:
- 1.13.x
- 1.17.x

os:
- osx
- linux
- windows

dist: trusty
osx_image: xcode12.2

services:
- docker
Expand All @@ -37,8 +38,8 @@ after_script:

deploy:
provider: releases
token:
secure: hEHCC4EN7iHz7pIWKRn2qw22NTqUxnuBp59wfAlLBtV26j5rHMzSu8mlxkJInusDUGLJiNLrZPRWN0mzOdIXalbUeLhlX7EflJgEj6Q0MchUR69LzCAp0KMIFL1Sfq0v81VgujRLUUy5utxDL8Er4tZknn2PpXAMzpO+ozjNRDhhSEM4iMXfY3bcOIMnx6XRgCjFCb036wlBgOfdgv5fwm2PP638DTKar4W6ZZbqCQByhJ5RyL3BMDPTT0moA/tYbG+FA6p6Rme1OcBkMnpsiJZoB3u8gxsNiEJ43/C2RcULW/18qqp2UVD5FipSDYP7GQ5ugKCbgpWXb0Ctl8o4hv1UsNl0XoyJhAt0PRp6vqnyy6LWB2FzX30Xj/vGIhO/IfiJvspHxpatTk7Esjr46K4u9ao/x63LX6F6yI1ZTfbzt2MhRYRjwh4ORNfqhysuzXChftX1S9hj6s6gO0/zqoOsRK/PK8DProbUn4bxrGOBzi16P0GEk4agWWUm74Pis9qCThXNW8MXEV936KvE1wb1RxTACYvFBtO2IM5eQ26t2Y7mGJd7FJup9LR4oUtUTSbYo5P2Sal6xntBKH5P4nwEtM+TtHoeSCKQ3X5i1VSdvAH7soEAly6rP5d5wwPhqqx9mgUPYO/3ulvxLJOYHamrbj6nlHDXnCEoj1ZMxX4=
api_key:
secure: nPeixJfnxE94mJizq864tqtwYsbDD/pJ/zvlG2iv2y2Ixx9kqtWTWrjQ/J4n+lmSag1WLYvCWf/pc6u2nYrWX0ycYkpjy9zNUgF8Pc+ixzB2K/KjTIhclX6bOOzkrOsJbylC8d2trsJ1MSgMUxLknCY6lDE+I3J3xFGweo3sfTaRWKMHwJLMlkARZg/WYUlfW7qa8Wg6ll3Ty5q+0+uRKiHRcey8cSq/dh3u5RN8pTMljDvcbtw05sQCDfv9Kf3Q+LVEj3wm+EnRF7KLafaIcAjsPtB+/mnMPBZ4g3aGNjDwbh80Giunc0oK9Ji/v6WaBwCHZlrCL+HdF1l36HqrN6dJPwuPjncysyyvu0y8pS+fA1Vd39BsUOn4xqVU6msfPEn8ObVGt5B5oM1DZPD21UpQoMTOCOCHUF9t4VL3Y2K6eLNiE8jzhwp0j3fXTffDP9pnht3a+3OY5dQTECIg9TLU9uo+5xK9vhUJ4Mqj5I+FpEhEq4S6nwrxUP56SpDV89QPfmMOJP2+j68xw78GVnYhJ6SjxaLu5zTnfTV3dPiclRUWcjxeVgtnhMOm7zV1iuFiS8AcxkijwfjD7nXAbywbdss/UPoa9scb3df2P8umo2WE3q1qnSFsU8ThNBoQ2fMbKnW4k3GLrw14FhK/8lHyCqiiDrC6Jdrf2HeCRjY=
file:
- release/goss-alpha-darwin-amd64
- release/goss-alpha-darwin-amd64.sha256
Expand All @@ -48,6 +49,8 @@ deploy:
- release/goss-linux-386.sha256
- release/goss-linux-arm
- release/goss-linux-arm.sha256
- release/goss-linux-arm64
- release/goss-linux-arm64.sha256
- release/goss-alpha-windows-amd64.exe
- release/goss-alpha-windows-amd64.exe.sha256
- extras/dgoss/dgoss
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ release:
$(MAKE) clean
$(MAKE) build

build: release/goss-alpha-darwin-amd64 release/goss-linux-386 release/goss-linux-amd64 release/goss-linux-arm release/goss-alpha-windows-amd64
build: release/goss-alpha-darwin-amd64 release/goss-linux-386 release/goss-linux-amd64 release/goss-linux-arm release/goss-linux-arm64 release/goss-alpha-windows-amd64

gen:
$(info INFO: Starting build $@)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ This will install goss and [dgoss](https://github.com/aelsabbahy/goss/tree/maste
# Install latest version to /usr/local/bin
curl -fsSL https://goss.rocks/install | sh

# Install v0.3.6 version to ~/bin
curl -fsSL https://goss.rocks/install | GOSS_VER=v0.3.6 GOSS_DST=~/bin sh
# Install v0.3.16 version to ~/bin
curl -fsSL https://goss.rocks/install | GOSS_VER=v0.3.16 GOSS_DST=~/bin sh
```

### Manual installation
Expand Down Expand Up @@ -248,6 +248,7 @@ package:
* tap - TAP style
* junit - JUnit style
* nagios - Nagios/Sensu compatible output /w exit code 2 for failures.
* prometheus - Prometheus compatible output.
* silent - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).

## Community Contributions
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Commands are the actions goss can run.
* [add](#add-a---add-system-resource-to-test-suite): add a single test for a resource
* [autoadd](#autoadd-aa---auto-add-all-matching-resources-to-test-suite): automatically add multiple tests for a resource
* [render](#render-r---render-gossfile-after-importing-all-referenced-gossfiles): renders and outputs the gossfile, importing all included gossfiles
* [serve](#serve-s---serve-a-health-endpoint): serves the gossfile validation as an HTTP endpoint on a specified address and port, so you can use your gossfile as a health repor for the host
* [serve](#serve-s---serve-a-health-endpoint): serves the gossfile validation as an HTTP endpoint on a specified address and port, so you can use your gossfile as a health report for the host
* [validate](#validate-v---validate-the-system): runs the goss test suite on your server


Expand Down Expand Up @@ -310,6 +310,7 @@ The `application/vnd.goss-{output format}` media type can be used in the `Accept
* `nagios` - Nagios/Sensu compatible output /w exit code 2 for failures
* `rspecish` **(default)** - Similar to rspec output
* `tap`
* `prometheus` - Prometheus compatible output.
* `silent` - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint)
* `--format-options`, `-o` (output format option)
* `perfdata` - Outputs Nagios "performance data". Applies to `nagios` output
Expand Down
3 changes: 3 additions & 0 deletions extras/dgoss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ Strategy used for copying goss files into the docker container. If set to `'moun

##### CONTAINER_LOG_OUTPUT
Location of the file that contains tested container logs. Logs are retained only if the variable is set to a non-empty string. (Default `''`)

##### CONTAINER_RUNTIME
Container runtime to use - `docker` or `podman`. Defaults to `docker`. Note that `podman` requires a run command to keep the container running. This defaults to `sleep infinity` in case only an image is passed to `dgoss` commands.
49 changes: 29 additions & 20 deletions extras/dgoss/dgoss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -e
USAGE="USAGE: $(basename "$0") [run|edit] <docker_run_params>"
GOSS_FILES_PATH="${GOSS_FILES_PATH:-.}"

# Container runtime
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-docker}"

info() {
echo -e "INFO: $*" >&2;
}
Expand All @@ -22,7 +25,7 @@ cleanup() {
rm -rf "$tmp_dir"
if [[ $id ]];then
info "Deleting container"
docker rm -vf "$id" > /dev/null
$CONTAINER_RUNTIME rm -vf "$id" > /dev/null
fi
}

Expand All @@ -38,21 +41,25 @@ run(){
GOSS_FILES_STRATEGY=${GOSS_FILES_STRATEGY:="mount"}
case "$GOSS_FILES_STRATEGY" in
mount)
info "Starting docker container"
id=$(docker run -d -v "$tmp_dir:/goss:z" "${@:2}")
info "Starting $CONTAINER_RUNTIME container"
if [ "$CONTAINER_RUNTIME" == "podman" -a $# == 2 ]; then
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}" sleep infinity)
else
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}")
fi
;;
cp)
info "Creating docker container"
id=$(docker create "${@:2}")
info "Creating $CONTAINER_RUNTIME container"
id=$($CONTAINER_RUNTIME create "${@:2}")
info "Copy goss files into container"
docker cp $tmp_dir/. $id:/goss
info "Starting docker container"
docker start $id > /dev/null
$CONTAINER_RUNTIME cp $tmp_dir/. $id:/goss
info "Starting $CONTAINER_RUNTIME container"
$CONTAINER_RUNTIME start $id > /dev/null
;;
*) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"."
esac

docker logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
$CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
log_pid=$!
info "Container ID: ${id:0:8}"
}
Expand All @@ -62,9 +69,9 @@ get_docker_file() {
local src=$2 # Source file path (in the container)
local dst=$3 # Destination file path

if docker exec "${cid}" sh -c "test -e ${src}" > /dev/null; then
if $CONTAINER_RUNTIME exec "${cid}" sh -c "test -e ${src}" > /dev/null; then
mkdir -p "${GOSS_FILES_PATH}"
docker cp "${cid}:${src}" "${dst}"
$CONTAINER_RUNTIME cp "${cid}:${src}" "${dst}"
info "Copied '${src}' from container to '${dst}'"
fi
}
Expand All @@ -80,40 +87,42 @@ GOSS_PATH="${GOSS_PATH:-$(which goss 2> /dev/null || true)}"
[[ ${GOSS_WAIT_OPTS+x} ]] || GOSS_WAIT_OPTS="-r 30s -s 1s > /dev/null"
GOSS_SLEEP=${GOSS_SLEEP:-0.2}

[[ $CONTAINER_RUNTIME =~ ^(docker|podman)$ ]] || { error "Runtime must be one of docker or podman"; }

case "$1" in
run)
run "$@"
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
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml validate $GOSS_WAIT_OPTS"; then
docker logs $id >&2
if ! $CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml validate $GOSS_WAIT_OPTS"; then
$CONTAINER_RUNTIME logs $id >&2
error "goss_wait.yaml never passed"
fi
else
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_WAIT_OPTS"; then
docker logs $id >&2
if ! $CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_WAIT_OPTS"; then
$CONTAINER_RUNTIME logs $id >&2
error "goss_wait.yaml never passed"
fi
fi
fi
[[ $GOSS_SLEEP ]] && { info "Sleeping for $GOSS_SLEEP"; sleep "$GOSS_SLEEP"; }
info "Container health"
if [ "true" != "$(docker inspect -f '{{.State.Running}}' $id)" ]; then
docker logs $id >&2
if [ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' $id)" ]; then
$CONTAINER_RUNTIME logs $id >&2
error "the container failed to start"
fi
info "Running Tests"
if [[ -z "${GOSS_VARS}" ]]; then
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS"
$CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS"
else
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS"
$CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS"
fi
;;
edit)
run "$@"
info "Run goss add/autoadd to add resources"
docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
$CONTAINER_RUNTIME exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
get_docker_file "$id" "/goss/goss.yaml" "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}"
get_docker_file "$id" "/goss/goss_wait.yaml" "${GOSS_FILES_PATH}/goss_wait.yaml"
[[ ! -z "${GOSS_VARS}" ]] && get_docker_file "$id" "/goss/${GOSS_VARS}" "${GOSS_FILES_PATH}/${GOSS_VARS}"
Expand Down
4 changes: 2 additions & 2 deletions extras/kgoss/kgoss
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ initialize () {
info "Creating Kubernetes pod/container to test"
test_pod_name=kgoss-tester-${RANDOM}
set -x
id=$(${k} run $test_pod_name --image-pull-policy=Always --generator=run-pod/v1 --restart=Never \
id=$(${k} run $test_pod_name --image-pull-policy=Always --restart=Never \
--labels='app=kgoss-test' --output=jsonpath={.metadata.name} ${envs} \
--image=${image} ${to_exec})
set +x
Expand All @@ -220,7 +220,7 @@ get_pod_file() {
if ${k} exec "$id" -- sh -c "test -e ${GOSS_CONTAINER_PATH}/$1" &> /dev/null; then
mkdir -p "${GOSS_FILES_PATH}"
info "Copied '$1' from pod/container to '${GOSS_FILES_PATH}'"
${k} cp "${id}:${GOSS_CONTAINER_PATH}/$1" "${GOSS_FILES_PATH}"
${k} cp "${id}:${GOSS_CONTAINER_PATH}/$1" "${GOSS_FILES_PATH}/$1"
fi
}

Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
module github.com/aelsabbahy/goss

require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/Masterminds/sprig/v3 v3.2.2
github.com/achanda/go-sysctl v0.0.0-20160222034550-6be7678c45d2
github.com/aelsabbahy/GOnetstat v0.0.0-20160428114218-edf89f784e08
github.com/aelsabbahy/GOnetstat v0.0.0-20220505220511-31d79a98d9f2
github.com/aelsabbahy/go-ps v0.0.0-20201009164808-61c449472dcf
github.com/blang/semver v3.5.1+incompatible
github.com/blang/semver/v4 v4.0.0
github.com/cheekybits/genny v1.0.0
github.com/docker/docker v1.13.1
github.com/fatih/color v1.10.0
github.com/google/uuid v1.1.1 // indirect
github.com/huandu/xstrings v1.3.0 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/miekg/dns v1.1.35
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/oleiade/reflections v0.0.0-20160817071559-0e86b3c98b2f
github.com/onsi/gomega v1.10.4
github.com/opencontainers/runc v0.0.0-20161107232042-8779fa57eb4a
github.com/fatih/color v1.13.0
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/miekg/dns v1.1.49
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/moby/sys/mountinfo v0.6.1
github.com/oleiade/reflections v1.0.1
github.com/onsi/gomega v1.19.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/testify v1.6.1
github.com/urfave/cli v0.0.0-20161102131801-d86a009f5e13
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/common v0.37.0
github.com/stretchr/testify v1.7.1
github.com/urfave/cli v1.22.9
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
golang.org/x/tools v0.1.9 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

go 1.13
go 1.16
Loading

0 comments on commit 1ace6e6

Please sign in to comment.