#!/usr/bin/env bash set -xeuo pipefail main() { GO_VERSION=$(curl -s 'https://go.dev/VERSION?m=text' | head -n1) # 1. ACTION_REPO_DIR="${PWD}" go mod edit -go=$(echo GO_VERSION | sed 's/^go//') #mkdir "${ACTION_REPO_DIR}" #cp -a . "${ACTION_REPO_DIR}/" # 2. Create temp directory TMPDIR="$(mktemp -d)" echo "Using temp dir: ${TMPDIR}" cd "${TMPDIR}" mkdir golang cd golang GOLANG_URL="https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" wget "${GOLANG_URL}" tar xzf "${GO_VERSION}.linux-amd64.tar.gz" PATH="${PATH}:$PWD/go/bin" # 3. Clone latest CoreDNS release cd "${TMPDIR}" COREDNS_REPO_URL="https://github.com/coredns/coredns.git" COREDNS_DIR="${TMPDIR}/coredns" # get latest tag (annotated or lightweight) git clone --depth=1 --filter=blob:none --tags "${COREDNS_REPO_URL}" "${COREDNS_DIR}" cd "${COREDNS_DIR}" git fetch --tags LATEST_TAG="$(git tag --list --sort=-version:refname | head -n 1)" git fetch --tags --depth=1 origin "${LATEST_TAG}" git checkout "${LATEST_TAG}" # 4. cd into the CoreDNS repo cd "${COREDNS_DIR}" # 5. Update plugin.cfg to include netboxdns plugin # Insert netboxdns after the 'cache' plugin entry as recommended. [web:16][web:29] if ! grep -q '^netboxdns:' plugin.cfg; then awk ' /^cache:/ { print print "netboxdns:github.com/doubleu-labs/coredns-netbox-plugin-dns" next } { print } ' plugin.cfg >plugin.cfg.new mv plugin.cfg.new plugin.cfg fi go mod edit -go=$(echo GO_VERSION | sed 's/^go//') # 6. go mod replace plugin path to the cloned action repo # This assumes the plugin lives at github.com/doubleu-labs/coredns-netbox-plugin-dns in your repo. [web:16][web:23] # Adjust relative path if your repo layout differs. go mod edit -replace=github.com/doubleu-labs/coredns-netbox-plugin-dns="${ACTION_REPO_DIR}" # 7. Regenerate plugin source files # CoreDNS uses go generate (via Makefile) to rebuild plugin glue code. [web:20][web:26] make core/plugin/zplugin.go core/dnsserver/zdirectives.go # 8. Update Go version to the latest # Install or pick latest Go and set GOTOOLCHAIN, or rely on pre-installed toolchain in the runner. [web:17] # Here we query the latest stable from golang.org and export it for this build. git diff echo "Using Go version: ${GO_VERSION}" #export GOTOOLCHAIN="${GO_VERSION}" # 9. Compile CoreDNS make coredns || make # 10. Strip the binary STRIP_BIN="${STRIP_BIN:-strip}" "${STRIP_BIN}" ./coredns # 11. Create a .deb installing /usr/local/bin/coredns # Minimal Debian package using dpkg-deb. [web:17] PKG_ROOT="${TMPDIR}/pkg-root" mkdir -p "${PKG_ROOT}/DEBIAN" "${PKG_ROOT}/usr/local/bin" # Basic metadata; tweak as needed PKG_NAME="coredns-netboxdns" PKG_VERSION="$(echo "${LATEST_TAG}" | sed 's/^v//')" PKG_ARCH="$(dpkg --print-architecture 2>/dev/null || echo amd64)" cat >"${PKG_ROOT}/DEBIAN/control" < Description: CoreDNS with netboxdns plugin Custom CoreDNS build with netboxdns plugin compiled in. EOF install -m 0755 ./coredns "${PKG_ROOT}/usr/local/bin/coredns" DEB_OUT="${TMPDIR}/${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb" dpkg-deb --build "${PKG_ROOT}" "${DEB_OUT}" echo "Built Debian package at: ${DEB_OUT}" } main "$@"