Skip to content

Commit

Permalink
Add the ability to run dgoss when the docker daemon is not local. (#271)
Browse files Browse the repository at this point in the history
* Add the ability to run dgoss when the docker daemon is not local

* Fix a typo
  • Loading branch information
plispe authored and aelsabbahy committed Aug 18, 2017
1 parent 00adcc2 commit 013c595
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions extras/dgoss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ 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: `''`).

##### GOSS_FILES_STRATEGY
Strategy used for copying goss files into the docker container. If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses `'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the local machine.
(Default `'mount'`)
23 changes: 20 additions & 3 deletions extras/dgoss/dgoss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,26 @@ run(){
[[ -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"
info "Starting docker container"
id=$(docker run -d -v "$tmp_dir:/goss" "${@:2}")
docker logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &

# Switch between mount or cp files strategy
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" "${@:2}")
docker logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
;;
cp)
info "Creating docker container"
id=$(docker create "${@:2}")
info "Copy goss files into container"
docker cp $tmp_dir $id:/goss
info "Starting docker container"
docker start $id > /dev/null
;;
*) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"."
esac

log_pid=$!
info "Container ID: ${id:0:8}"
}
Expand Down

0 comments on commit 013c595

Please sign in to comment.