-
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 90b21a7
Showing
18 changed files
with
447 additions
and
147 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.
File renamed without changes.
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 |
---|---|---|
|
@@ -105,4 +105,4 @@ chkconfig yum-updateonboot off | |
|
||
echo 'useDNS no' >> /etc/ssh/sshd_config | ||
yum clean all | ||
%end | ||
%end |
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,91 @@ | ||
{ | ||
"builders": [ | ||
{ | ||
"boot_command": [ | ||
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks7.cfg<enter>" | ||
], | ||
"boot_wait": "10s", | ||
"communicator": "ssh", | ||
"disk_size": 10240, | ||
"guest_os_type": "RedHat_64", | ||
"hard_drive_interface": "scsi", | ||
"headless": true, | ||
"http_directory": "http", | ||
"iso_checksum": "sha256:{{user `iso_checksum`}}", | ||
"iso_url": "{{user `iso_url`}}", | ||
"name": "centos-7-x86_64", | ||
"output_directory": "img_centos_7_virtualbox", | ||
"shutdown_command": "echo 'packer'|sudo -S /sbin/halt -h -p", | ||
"ssh_handshake_attempts": 50, | ||
"ssh_password": "changeme", | ||
"ssh_port": 22, | ||
"ssh_timeout": "20000s", | ||
"ssh_username": "root", | ||
"type": "virtualbox-iso", | ||
"vboxmanage": [ | ||
[ | ||
"modifyvm", | ||
"{{.Name}}", | ||
"--paravirtprovider", | ||
"kvm" | ||
], | ||
[ | ||
"modifyvm", | ||
"{{.Name}}", | ||
"--nictype1", | ||
"virtio" | ||
], | ||
[ | ||
"modifyvm", | ||
"{{.Name}}", | ||
"--memory", | ||
"1024" | ||
], | ||
[ | ||
"modifyvm", | ||
"{{.Name}}", | ||
"--cpus", | ||
"1" | ||
] | ||
], | ||
"virtualbox_version_file": ".vbox_version" | ||
} | ||
], | ||
"post-processors": [ | ||
{ | ||
"type": "vagrant" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"execute_command": "{{ .Vars }} /bin/sh '{{.Path}}'", | ||
"scripts": [ | ||
"scripts/vagrant.sh" | ||
], | ||
"type": "shell" | ||
}, | ||
{ | ||
"goss_file": "goss.yaml", | ||
"retry_timeout": "5s", | ||
"sleep": "2s", | ||
"tests": [ | ||
"goss/goss.yaml" | ||
], | ||
"type": "goss" | ||
}, | ||
{ | ||
"execute_command": "{{ .Vars }} /bin/sh '{{.Path}}'", | ||
"scripts": [ | ||
"scripts/cleanup.sh", | ||
"scripts/zerodisk.sh" | ||
], | ||
"type": "shell" | ||
} | ||
], | ||
"variables": { | ||
"iso_checksum": "b79079ad71cc3c5ceb3561fff348a1b67ee37f71f4cddfec09480d4589c191d6", | ||
"iso_checksum_type ": "sha256", | ||
"iso_url": "http://mirror.net.cen.ct.gov/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-NetInstall-2009.iso" | ||
} | ||
} | ||
|
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
File renamed without changes.
Oops, something went wrong.