-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(output_file): add option to specify the test result output file
- Loading branch information
1 parent
fb262d8
commit 41ecd43
Showing
15 changed files
with
209 additions
and
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
example/packer_cache | ||
example/packer_cache | ||
.envrc | ||
packer-plugin-goss | ||
tests/debug-goss-spec.yaml | ||
tests/goss-spec.yaml | ||
tests/goss.json |
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,32 @@ | ||
default: help | ||
|
||
.PHONY: help | ||
help: ## list makefile targets | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: fmt | ||
fmt: ## format go files | ||
gofumpt -w . | ||
gci write . | ||
packer fmt -recursive -write . | ||
|
||
.PHONY: build | ||
build: ## build the plugin | ||
go build -ldflags="-X github.com/YaleUniversity/packer-provisioner-goss/version.VersionPrerelease=dev" -o packer-plugin-goss | ||
|
||
.PHONY: install | ||
install: ## install the plugin | ||
packer plugins install --path packer-plugin-goss github.com/YaleUniversity/goss | ||
|
||
.PHONY: local | ||
local: clean build install ## build and install the plugin locally | ||
cd example && packer init . | ||
cd example && packer build alpine.pkr.hcl | ||
|
||
.PHONY: clean | ||
clean: ## remove tmp files | ||
rm -f example/alpine.tar example/goss_test_results.xml example/debug-goss-spec.yaml example/goss-spec.yaml packer-plugin-goss | ||
|
||
.PHONY: generate | ||
generate: ## go generate | ||
go generate ./... |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ Wouldn't it be nice if you could run [goss](https://github.com/aelsabbahy/goss) | |
Well, I thought it would, so now you can! | ||
|
||
This runs during the provisioning process since the machine being provisioned is only available at that time. | ||
There is an example packer build with goss tests in the `example/` directory. | ||
There is an example packer build with `goss` tests in the [`example/`](https://github.com/YaleUniversity/packer-plugin-goss/tree/master/example) directory. | ||
|
||
## Configuration | ||
|
||
|
@@ -20,6 +20,58 @@ packer { | |
} | ||
``` | ||
|
||
## Quickstart Example | ||
**This example assumes you have a file `goss.yaml` in your `PWD` containing goss tests**: | ||
```hcl | ||
# example/alpine.pkr.hcl | ||
packer { | ||
required_version = ">= 1.9.0" | ||
required_plugins { | ||
goss = { | ||
version = "v0.0.1" | ||
source = "github.com/YaleUniversity/goss" | ||
} | ||
docker = { | ||
source = "github.com/hashicorp/docker" | ||
version = "v1.0.10" | ||
} | ||
} | ||
} | ||
# fetch a normal alpine container and export the image as alpine.tar | ||
source "docker" "alpine" { | ||
image = "alpine" | ||
export_path = "alpine.tar" | ||
} | ||
build { | ||
# apply build params against the alpine container | ||
sources = ["docker.alpine"] | ||
# run goss tests using goss provisioner | ||
provisioner "goss" { | ||
# download and install goss to /tmp/goss_install within the target system | ||
download_path = "/tmp/goss_install" | ||
# run goss tests in goss.yaml | ||
tests = ["./goss.yaml"] | ||
# output results as junit | ||
format = "junit" | ||
# write results to /tmp/goss_test_results.xml, which will then be copied to the hosts CWD that is running packer | ||
output_file = "/tmp/goss_test_results.xml" | ||
} | ||
# output the test results just for demo purposes | ||
provisioner "shell-local" { | ||
inline = ["cat goss_test_results.xml"] | ||
} | ||
} | ||
``` | ||
|
||
### Additional (optional) properties | ||
|
||
```hcl | ||
|
@@ -30,7 +82,7 @@ build { | |
# Provisioner Args | ||
arch ="amd64" | ||
download_path = "/tmp/goss-VERSION-linux-ARCH" | ||
inspect = "{{ inspect_mode }}", | ||
inspect = "{{ inspect_mode }}" | ||
password = "" | ||
skip_install = false | ||
url = "https://github.com/aelsabbahy/goss/releases/download/vVERSION/goss-linux-ARCH" | ||
|
@@ -74,22 +126,6 @@ Goss spec file and debug spec file (`goss render -d`) are downloaded to `/tmp` f | |
|
||
This now has support for Windows. Set the optional parameter `target_os` to `Windows`. Currently, the `vars_env` parameter must include `GOSS_USE_ALPHA=1` as specified in [goss's feature parity document](https://github.com/aelsabbahy/goss/blob/master/docs/platform-feature-parity.md#platform-feature-parity). In the future when goss come of of alpha for Windows this parameter will not be required. | ||
|
||
## Build | ||
|
||
### Using Golang docker image | ||
|
||
```bash | ||
docker run --rm -it -v "$PWD":/usr/src/packer-provisioner-goss -w /usr/src/packer-provisioner-goss -e 'VERSION=v1.0.0' golang:1.13 bash | ||
go test ./... | ||
for GOOS in darwin linux windows; do | ||
for GOARCH in 386 amd64; do | ||
export GOOS GOARCH | ||
go get -v ./... | ||
go build -v -o packer-provisioner-goss-${VERSION}-$GOOS-$GOARCH | ||
done | ||
done | ||
``` | ||
|
||
## Author | ||
|
||
E. Camden Fisher <[email protected]> | ||
|
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,46 @@ | ||
packer { | ||
required_version = ">= 1.9.0" | ||
|
||
required_plugins { | ||
goss = { | ||
version = "v0.0.1" | ||
source = "github.com/YaleUniversity/goss" | ||
} | ||
docker = { | ||
source = "github.com/hashicorp/docker" | ||
version = "v1.0.10" | ||
} | ||
} | ||
} | ||
|
||
# fetch a normal alpine container and export the image as alpine.tar | ||
source "docker" "alpine" { | ||
image = "alpine" | ||
export_path = "alpine.tar" | ||
} | ||
|
||
build { | ||
# apply build params against the alpine container | ||
sources = ["docker.alpine"] | ||
|
||
# run goss tests using goss provisioner | ||
provisioner "goss" { | ||
# download and install goss to /tmp/goss_install | ||
download_path = "/tmp/goss_install" | ||
|
||
# run goss tests in goss.yaml | ||
tests = ["./goss.yaml"] | ||
|
||
# output results as junit | ||
format = "junit" | ||
|
||
# write results to /tmp/goss_test_results.xml, which will be copied to the host | ||
output_file = "/tmp/goss_test_results.xml" | ||
} | ||
|
||
|
||
# output the test results just for demo purposes | ||
provisioner "shell-local" { | ||
inline = ["cat goss_test_results.xml"] | ||
} | ||
} |
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,3 @@ | ||
process: | ||
sshd: | ||
running: true |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.