meta: add CI to build debian package #1
@@ -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
|
||||
Executable
+113
@@ -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" <<EOF
|
||||
Package: ${PKG_NAME}
|
||||
Version: ${PKG_VERSION}
|
||||
Section: net
|
||||
Priority: optional
|
||||
Architecture: ${PKG_ARCH}
|
||||
Maintainer: CI <ci@example.invalid>
|
||||
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 "$@"
|
||||
Reference in New Issue
Block a user