Skip to content

Commit

Permalink
run the test in an isolated directory
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Jun 25, 2024
1 parent dd5e77a commit 674a2fc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
15 changes: 2 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,10 @@ update/provisioner.hcl2spec.go: update/provisioner.go
go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@$(shell go list -m -f '{{.Version}}' github.com/hashicorp/packer-plugin-sdk)
go generate ./...

install: uninstall $(PLUGIN_PATH) build
mkdir -p $(HOME)/.packer.d/plugins
cp -f $(PLUGIN_PATH) $(HOME)/.packer.d/plugins/packer-plugin-windows-update$(GOEXE)

uninstall:
rm -f $(HOME)/.packer.d/plugins/packer-provisioner-windows-update$(GOEXE) # rm the old name too.
rm -f $(HOME)/.packer.d/plugins/packer-plugin-windows-update$(GOEXE)

clean:
rm -rf dist tmp* output-test *.log

test:
rm -rf output-test test.log
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=test.log \
PKR_VAR_disk_image=~/.vagrant.d/boxes/windows-2022-amd64/0.0.0/libvirt/box_0.img \
packer build -only=qemu.test -on-error=abort test.pkr.hcl
test: build
./test.sh

.PHONY: all init build release release-snapshot install uninstall clean test
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,9 @@ Build:
make
```

Install the plugin into `$HOME/.packer.d/plugins` with:
Install the [rgl/windows-vagrant](https://github.com/rgl/windows-vagrant) vagrant box.

```bash
make install
```

**And comment the `required_plugin` block in your packer template file.**

If you are having problems running `packer` set the `PACKER_LOG=1` environment
variable to see more information.

## Test (QEMU)

You can test the plugin with a previously installed [rgl/windows-vagrant](https://github.com/rgl/windows-vagrant) image with:
Test with QEMU:

```bash
make test
Expand Down
17 changes: 16 additions & 1 deletion test.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-qemu
qemu = {
version = "1.1.0"
source = "github.com/hashicorp/qemu"
}
# see https://github.com/rgl/packer-plugin-windows-update
windows-update = {
version = ">= 0.0.0"
source = "github.com/rgl/windows-update"
}
}
}

variable "disk_size" {
type = string
default = "61440"
Expand Down Expand Up @@ -56,7 +71,7 @@ build {
<<-EOF
$p = 'c:/packer.delete.me.to.end.test.wait.txt'
Set-Content $p 'delete this file to end the packer test wait'
Write-Host "ATTENTION To end this test wait, login into the machine and delete the $p file"
Write-Host "ATTENTION To end this test wait, login into the machine and delete the $p file. Or just press Ctrl+C."
while (Test-Path $p) {
Start-Sleep -Seconds 5
}
Expand Down
30 changes: 30 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/bash
set -euo pipefail

GOHOSTOS="$(go env GOHOSTOS)"
GOHOSTARCH="$(go env GOHOSTARCH)"
PLUGIN_PATH="$(
jq -r \
--arg goos "$GOHOSTOS" \
--arg goarch "$GOHOSTARCH" \
'.[] | select(.goos == $goos and .goarch == $goarch and .extra.ID == "packer-plugin-windows-update") | .path' \
dist/artifacts.json)"
PLUGIN_BASE_NAME="$(basename "$PLUGIN_PATH")"
PLUGIN_TEST_PATH="dist/test/plugins/github.com/rgl/windows-update/$PLUGIN_BASE_NAME"

# see https://developer.hashicorp.com/packer/docs/plugins/creation/plugin-load-spec
rm -rf output-test test.log dist/test
install -d dist/test/plugins/github.com/rgl/windows-update
install "$PLUGIN_PATH" "$PLUGIN_TEST_PATH"
(cd "$(dirname "$PLUGIN_TEST_PATH")" && \
sha256sum "$PLUGIN_BASE_NAME" >"${PLUGIN_BASE_NAME}_SHA256SUM")

export CHECKPOINT_DISABLE=1
export PACKER_LOG=1
export PACKER_LOG_PATH=test.log
export PACKER_CONFIG_DIR="$PWD/dist/test"
export PACKER_PLUGIN_PATH="$PWD/dist/test/plugins"
export PKR_VAR_disk_image=~/.vagrant.d/boxes/windows-2022-amd64/0.0.0/libvirt/box_0.img

packer init -only=qemu.test test.pkr.hcl
packer build -only=qemu.test -on-error=abort test.pkr.hcl

0 comments on commit 674a2fc

Please sign in to comment.