From 2c6ad3e0bd9fec251c9572fae37a53534c995956 Mon Sep 17 00:00:00 2001 From: restitux Date: Tue, 23 Dec 2025 22:55:11 -0700 Subject: [PATCH] TEST --- .gitea/workflows/build-release.yml | 12 +++ ci/build.sh | 113 +++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 .gitea/workflows/build-release.yml create mode 100755 ci/build.sh diff --git a/.gitea/workflows/build-release.yml b/.gitea/workflows/build-release.yml new file mode 100644 index 0000000..5288269 --- /dev/null +++ b/.gitea/workflows/build-release.yml @@ -0,0 +1,12 @@ +name: Build Coredns with netboxdns plugin +on: [workflow_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Build + run: ./ci/build.sh diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 0000000..74772b6 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +set -euo 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}" + LATEST_TAG="$(git describe --tags "$(git rev-list --tags --max-count=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" + git clone "https://github.com/${GITHUB_REPOSITORY}.git" "${ACTION_REPO_DIR}" + if [ -n "${GITHUB_SHA:-}" ]; then + cd "${ACTION_REPO_DIR}" + git checkout "${GITHUB_SHA}" + fi + + # 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 + + # 6. Regenerate plugin source files + # CoreDNS uses go generate (via Makefile) to rebuild plugin glue code. [web:20][web:26] + make gen || go generate ./... + + # 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. + 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 "$@"