d2040789e5
Replace the packer-images gobuilder with a Dockerfile matrix built on each container-base distro image, on a single repo semver. - install golang, gcc and nfpm - bake the sha256-pinned go-cache-plugin v0.1.0 binary onto PATH - run in-image assertions as a --target test build stage - add pull_request build/test/pre-commit and tag-triggered docker workflows
50 lines
1.7 KiB
Bash
Executable File
50 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# In-image assertions for the gobuilder image. Run via `docker build --target test`.
|
|
set -uo pipefail
|
|
|
|
ARTIFACTAPI=https://artifactapi.k8s.syd1.au.unkin.net
|
|
. ./distro.env
|
|
|
|
fail=0
|
|
check() {
|
|
local name=$1; shift
|
|
if out=$("$@" 2>&1); then
|
|
echo "ok $name"
|
|
else
|
|
echo "NOT OK $name"
|
|
printf '%s\n' "$out" | sed 's/^/ /'
|
|
fail=1
|
|
fi
|
|
}
|
|
|
|
# Inherited from container-base: no -k and no --cacert.
|
|
check "internal CA trusted (artifactapi)" \
|
|
curl -fsS -o /dev/null "$ARTIFACTAPI/api/v1/local/rpm-vendor-el9/repodata/repomd.xml"
|
|
|
|
for p in $PACKAGES; do
|
|
check "package $p installed" rpm -q "$p"
|
|
done
|
|
|
|
# GOCACHEPROG is only enabled by default from Go 1.24, so the toolchain floor matters.
|
|
go_min_ok() {
|
|
local have
|
|
have=$(go env GOVERSION 2>/dev/null | awk '{sub(/^go/,"",$1); print $1}') || return 1
|
|
[ "$(printf '%s\n%s\n' "$GO_MIN" "$have" | sort -V | head -1)" = "$GO_MIN" ]
|
|
}
|
|
check "go >= $GO_MIN (have $(go env GOVERSION 2>/dev/null | awk '{print $1}'))" go_min_ok
|
|
|
|
# gcc is what `go test -race` needs.
|
|
check "gcc runs" gcc --version
|
|
check "nfpm runs" nfpm --version
|
|
check "go-cache-plugin on PATH" command -v go-cache-plugin
|
|
check "go-cache-plugin executable" test -x /usr/local/bin/go-cache-plugin
|
|
# `version` prints correctly but exits 2, so assert on its output.
|
|
check "go-cache-plugin runs" bash -c 'go-cache-plugin version 2>&1 | grep -q "^go-cache-plugin version v"'
|
|
|
|
# cgo must actually link, which is the thing -race depends on.
|
|
check "cgo builds" bash -c 'cd "$(mktemp -d)" && go mod init t >/dev/null &&
|
|
printf "package main\n\nimport \"C\"\n\nfunc main() {}\n" > m.go && CGO_ENABLED=1 go build ./...'
|
|
|
|
[ "$fail" -eq 0 ] || { echo "FAILED"; exit 1; }
|
|
echo "PASS"
|