-
Notifications
You must be signed in to change notification settings - Fork 470
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
Showing
5 changed files
with
429 additions
and
1 deletion.
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
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,157 @@ | ||
# kgoss | ||
|
||
kgoss is a wrapper for goss that aims to bring the simplicity of testing | ||
with goss to containers running in pods in Kubernetes. | ||
|
||
kgoss is a script which when invoked copies and runs goss (the binary) within a | ||
Linux container in Kubernetes. goss itself is only supported on Linux, but | ||
since it need only run in the target container, the kgoss script can be used | ||
from any bash-compatible shell, including Terminal on Mac and git-bash on | ||
Windows. On Windows, [winpty][] is used automatically for interactive | ||
connections to the pod under test, e.g. `kgoss edit ...`. | ||
|
||
[winpty]: https://github.com/rprichard/winpty | ||
|
||
## Install | ||
|
||
Installing kgoss requires copying the kgoss file to a directory in your PATH | ||
and copying the goss file to your home folder (or another path set as | ||
`GOSS_PATH`), as follows. | ||
|
||
#### Manual / UI | ||
|
||
You can manually install kgoss and goss by going through the Web UI, getting | ||
the files and putting them in the right path. To get each of them: | ||
|
||
* **kgoss**: Run `curl -sSLO https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/kgoss/kgoss`. | ||
* **goss**: Download the `goss-linux-amd64` asset from | ||
<https://github.com/aelsabbahy/goss/releases> and rename it `goss`. Place it | ||
in your HOME directory, e.g. C:\\Users\\<username> on Windows; or set the | ||
environment variable `GOSS_PATH` to its path. | ||
|
||
#### Automatic / CLI | ||
|
||
To install from the command line or automatically, use the following commands. | ||
[jq][] is required to parse the Releases API response and find the release | ||
asset's download URL. | ||
|
||
[jq]: https://stedolan.github.io/jq | ||
|
||
First get a GitHub personal access token for accessing the GitHub API from | ||
<https://github.com/settings/tokens>. Input it in the first line below. Set | ||
`dest_dir` to a directory in your `PATH` env var. | ||
|
||
``` | ||
token=<personal_access_token> | ||
username=$(whoami) | ||
dest_dir=${HOME}/bin | ||
host=raw.githubusercontent.com | ||
repo=aelsabbahy/goss | ||
## install kgoss | ||
curl -sSL -u "${username}:${token}" -H 'Accept: application/vnd.github.v3.raw' -o "${dest_dir}/kgoss" \ | ||
https://${host}/api/v3/repos/${repo}/contents/extras/kgoss/kgoss | ||
chmod a+rx "${dest_dir}/kgoss" | ||
## install goss | ||
if [[ ! $(which jq) ]]; then echo "jq is required, get from https://stedolan.github.io/jq"; fi | ||
version=v0.3.7 | ||
arch=amd64 | ||
host=github.com | ||
dl_url=$(curl -sSL -u "${username}:${token}" https://${host}/api/v3/repos/${repo}/releases \ | ||
| jq -r ".[] | select (.name == \"${version}\") | .assets[] | select (.name == \"goss-linux-${arch}\") | .url") | ||
curl -sSL -u "${username}:${token}" -H 'Accept: application/octet-stream' -o "${dest_dir}/goss" $dl_url | ||
chmod a+rx "${dest_dir}/goss" | ||
# If `goss` is not in your path, export a GOSS_PATH variable: | ||
export GOSS_PATH=${dest_dir}/goss | ||
# Now you can use kgoss as described in the following sections. | ||
# kgoss edit ... | ||
# kgoss run ... | ||
``` | ||
|
||
## Use | ||
|
||
`kgoss [run|edit] -i <image_url> [-p | -c "command to run" | -a "args to pass"] [-d] [-e "k=v"]*` | ||
|
||
If none of `-p|-c|-a` are specified the container is run with its configured entry point. | ||
|
||
By default kgoss only copies `goss.yaml` from the current working directory. | ||
Specify `-d` to copy all contents of the directory (useful if you have | ||
additional scripts). Set `GOSS_FILES_PATH` to choose a directory other than the | ||
current workdir, `.`. | ||
|
||
NOTE that `-e` doesn't handle spaces in env var values at the moment. | ||
|
||
#### Run | ||
|
||
The `run` command is used to validate a docker container. It expects a | ||
`./goss.yaml` file to exist in the directory it was invoked from or the | ||
`GOSS_FILES_PATH` env var. | ||
|
||
**Example:** | ||
|
||
`kgoss run -e JENKINS_OPTS="--httpPort=8080" -e JENKINS_OPTS="--httpsPort=-1" -e JAVA_OPTS="-Xmx1048m" -i jenkins:latest` | ||
|
||
`kgoss run` will do the following: | ||
* Run the container with the start commands specified by `-c`, `-a`, or `-p`. | ||
* Run `goss` with `$GOSS_WAIT_OPTS` if `./goss_wait.yaml` file exists in the current dir. | ||
* Run `goss` with `$GOSS_OPTS` using `./goss.yaml` from `GOSS_FILES_PATH`. | ||
|
||
#### Edit | ||
|
||
Edit will launch a docker container, install goss, and drop the user into an | ||
interactive shell. Once the user quits the interactive shell, any `goss.yaml` | ||
or `goss_wait.yaml` are copied out into the current directory. This allows the | ||
user to leverage the `goss add|autoadd` commands to write tests as they would | ||
on a regular machine. | ||
|
||
**Example:** | ||
|
||
`kgoss edit -e JENKINS_OPTS="--httpPort=8080" -e JENKINS_OPTS="--httpsPort=-1" -e JAVA_OPTS="-Xmx1048m" -i jenkins:latest` | ||
|
||
## Environment variables | ||
|
||
The following environment variables effect the behavior of kgoss. | ||
|
||
##### CONTAINER_PATH | ||
|
||
Path within container to put goss binary and YAML files. Change if test user | ||
rights are constrainted to certain paths. (Default: `/tmp/goss`) | ||
|
||
##### GOSS_KUBECTL_BIN | ||
|
||
Kubenetes client tool to use (Default: `$(which kubectl)`) | ||
|
||
##### GOSS_PATH | ||
|
||
Local location of a compatible goss binary to use in container. (Default: | ||
`$(which goss)`) | ||
|
||
##### GOSS_OPTS | ||
|
||
Options to use for the goss test run. (Default: `--color --format documentation`) | ||
|
||
##### GOSS_WAIT_OPTS | ||
|
||
Options to use for the goss wait run, when `./goss_wait.yaml` exists. (Default: | ||
`-r 30s -s 1s > /dev/null`) | ||
|
||
##### GOSS_SLEEP | ||
|
||
Time to sleep after starting pod/container and before running tests. (Default: `3s`) | ||
|
||
##### GOSS_FILES_PATH | ||
|
||
Location of the goss yaml files. (Default: `.`) | ||
|
||
##### GOSS_VARS | ||
|
||
The name of the variables file relative to `GOSS_FILES_PATH` to copy into the | ||
docker container and use for valiation (i.e. `dgoss run`) and copy out of the | ||
docker container when writing tests (i.e. `dgoss edit`). If set, the | ||
`--vars` flag is passed to `goss validate` commands inside the container. | ||
If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. | ||
(Default: `''`). |
Oops, something went wrong.