Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
FalcoSuessgott committed Jul 7, 2024
1 parent 652f867 commit 1112d7e
Show file tree
Hide file tree
Showing 32 changed files with 2,476 additions and 1,263 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: E2E

on:
pull_request:
push:
branches:
- master

jobs:
e2e:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-packer@main
-
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false

- run: go generate -tags tools tools/tools.go

- run: |
make e2e OS=linux
if: matrix.os == 'ubuntu-latest'
- run: |
make e2e OS=windows
if: matrix.os == 'windows-latest'
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: go generate -tags tools tools/tools.go

- uses: actions/setup-go@v5
with:
go-version: '1.21'
Expand All @@ -18,5 +20,6 @@ jobs:
- name: go get
run: go get ./...

- name: Run tests
run: go test -v ./...
- name: Run coverage
run: |
gotestsum -- -v -race -coverprofile="coverage.out" -covermode=atomic ./...
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
example/packer_cache
.envrc
packer-plugin-goss
tests/debug-goss-spec.yaml
tests/goss-spec.yaml
tests/goss.json
e2e/debug-goss-spec.yaml
e2e/goss-spec.yaml
e2e/goss.json
43 changes: 43 additions & 0 deletions .golang-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
linters-settings:
lll:
line-length: 180
allow-leading-space: true
linters:
enable-all: true
disable:
- scopelint
- maligned
- interfacer
- golint
- testpackage
- forbidigo
- paralleltest
- exhaustivestruct
- goerr113
- wrapcheck
- gochecknoglobals
- varnamelen
- funlen
- gomnd
- containedctx
- nlreturn
- wsl
- exhaustruct
- nolintlint
- maintidx
- dupl
- revive
- depguard
- tagalign
- perfsprint
- godox
- structcheck
- ifshort
- deadcode
- intrange
- nosnakecase
- varcheck
- copyloopvar
- gomoddirectives
- goconst
- godot
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-build-mod
- id: go-test-mod
- id: go-vet-mod
- id: go-staticcheck-mod
- id: go-fmt
- id: go-fumpt
- id: go-imports
- id: go-lint
- id: golangci-lint-mod
args: [-c.golang-ci.yml]
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
OS ?= linux
E2E_DIR ?= e2e

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: lint
lint: ## lint go files
golangci-lint run -c .golang-ci.yml

.PHONY: fmt
fmt: ## format go files
gofumpt -w .
gci write .
packer fmt -recursive -write .

.PHONY: build
build: ## build the plugin
build: generate ## 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 tests && packer init .
cd tests && packer build local.pkr.hcl
.PHONY: e2e
e2e: clean build install ## build and install the plugin locally
cd $(E2E_DIR) && packer init .
cd $(E2E_DIR) && packer build e2e_$(OS).pkr.hcl

.PHONY: clean
clean: ## remove tmp files
rm -f packer-plugin-goss tests/goss.json tests/debug-goss-spec.yaml tests/goss-spec.yaml packer-plugin-goss
rm -f $(E2E_DIR)/*.tar $(E2E_DIR)/goss_test_results.xml packer-plugin-goss

.PHONY: generate
generate: ## go generate
Expand Down
42 changes: 42 additions & 0 deletions e2e/e2e_linux.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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" {

# goss download parameter
installation {}

# goss render
render {
vars_file = "./vars.yaml"
goss_file = "./goss.yaml"

env_vars = {
OS = "centos"
}

output_file = "goss-spec.yaml"
}

# goss validate parameter
validate {
goss_file = "./goss-spec.yaml" # created during goss render

output_file = "goss_test_results.xml"
}
}


# output the test results just for demo purposes
provisioner "shell-local" {
inline = ["cat goss_test_results.xml"]
}
}
42 changes: 42 additions & 0 deletions e2e/e2e_windows.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# fetch a normal alpine container and export the image as alpine.tar
source "docker" "windows" {
image = "dockurr/windows"
export_path = "windows.tar"
}

build {
# apply build params against the alpine container
sources = ["docker.windows"]

# run goss tests using goss provisioner
provisioner "goss" {

# goss download parameter
installation {}

# goss render
render {
vars_file = "./vars.yaml"
goss_file = "./goss.yaml"

env_vars = {
OS = "centos"
}

output_file = "goss-spec.yaml"
}

# goss validate parameter
validate {
goss_file = "./goss-spec.yaml" # created during goss render

output_file = "goss_test_results.xml"
}
}


# output the test results just for demo purposes
provisioner "shell-local" {
inline = ["cat goss_test_results.xml"]
}
}
27 changes: 27 additions & 0 deletions e2e/goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package:
# Looping over a variables defined in a vars.yaml using $OS environment variable as a lookup key
{{range $name, $vers := index .Vars .Env.OS "packages"}}
{{$name}}:
installed: true
versions:
{{range $vers}}
- {{.}}
{{end}}
{{end}}

# This test is only when the OS environment variable matches the pattern
{{if .Env.OS | regexMatch "[Cc]ent(OS|os)"}}
libselinux:
installed: true
{{end}}

# Loop over users
user:
{{range .Vars.users}}
{{.}}:
exists: true
groups:
- {{.}}
home: /home/{{.}}
shell: /bin/bash
{{end}}
14 changes: 14 additions & 0 deletions e2e/packer.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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"
}
}
}
13 changes: 13 additions & 0 deletions e2e/vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
centos:
packages:
kernel:
- "4.9.11-centos"
- "4.9.11-centos2"
debian:
packages:
kernel:
- "4.9.11-debian"
- "4.9.11-debian2"
users:
- user1
- user2
47 changes: 0 additions & 47 deletions example/goss/goss.yaml

This file was deleted.

Loading

0 comments on commit 1112d7e

Please sign in to comment.