#!/usr/bin/env bash set -xeuo pipefail # Inputs expected from the workflow: # GITHUB_REPOSITORY - owner/repo of the current action repo (provided by Actions) # GITHUB_SHA - commit to clone/check out (provided by Actions, optional) # GO_VERSION - optional, e.g. "1.23.3"; if unset, script will query latest. main() { # 1. Create temp directory TMPDIR="$(mktemp -d)" echo "Using temp dir: ${TMPDIR}" # 2. 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}" # 3. Clone the GitHub Action's repo (this repo) ACTION_REPO_DIR="${TMPDIR}/action-repo" mkdir "${ACTION_REPO_DIR}" cp -a . "${ACTION_REPO_DIR}/" # 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 ls -lah docker run --rm \ --user "$(id -u):$(id -g)" \ -v "$PWD":"/work" \ -w "/work" \ golang:latest ls -lah # 6. Regenerate plugin source files # CoreDNS uses go generate (via Makefile) to rebuild plugin glue code. [web:20][web:26] docker run --rm \ --user "$(id -u):$(id -g)" \ -v "$PWD":"/work" \ -w "/work" \ golang:latest bash -c make core/plugin/zplugin.go core/dnsserver/zdirectives.go # 7. 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. docker run --rm -it \ --user "$(id -u):$(id -g)" \ -v "$PWD":"/work" \ -w "/work" \ golang:latest go mod edit -replace=github.com/doubleu-labs/coredns-netbox-plugin-dns="${ACTION_REPO_DIR}" # 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. if [ -z "${GO_VERSION:-}" ]; then GO_VERSION="$(curl -s https://go.dev/VERSION?m=text | head -n1 | sed 's/^go//')" # e.g. "1.23.3" fi echo "Using Go version: ${GO_VERSION}" # If you use setup-go in the workflow, this is optional; otherwise install here. # Example (Debian-based runner): # sudo rm -rf /usr/local/go # curl -sL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" | sudo tar -C /usr/local -xz # export PATH="/usr/local/go/bin:${PATH}" export GOTOOLCHAIN="go${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 "$@"