first commit
Go quality gates / test (push) Waiting to run

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-30 11:37:40 +01:00
commit 8c4d463f1e
96 files changed
+3319

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
#!/bin/sh
# Build a standalone EasyDNS UI Debian package; never packages the DNS server.
set -eu
ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
ARCH=${GOARCH:-amd64}
VERSION=${VERSION:-0.1.0}
case "$ARCH" in
amd64|arm64) ;;
*) echo "Unsupported architecture: $ARCH (use amd64 or arm64)" >&2; exit 1 ;;
esac
case "$VERSION" in
*[!a-zA-Z0-9.+~:-]*|'') echo 'Invalid version' >&2; exit 1 ;;
esac
STAGING=$(mktemp -d)
trap 'rm -rf "$STAGING"' EXIT HUP INT TERM
chmod 0755 "$STAGING"
mkdir -p "$STAGING/DEBIAN" "$STAGING/usr/bin" "$STAGING/lib/systemd/system" "$STAGING/etc/default" "$ROOT/dist"
cd "$ROOT"
GOOS=linux GOARCH="$ARCH" CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION" -o "$STAGING/usr/bin/easydns-ui" ./cmd/easydns-ui
chmod 0755 "$STAGING/usr/bin/easydns-ui"
cp packaging/easydns-ui.service "$STAGING/lib/systemd/system/easydns-ui.service"
cp packaging/easydns-ui.default "$STAGING/etc/default/easydns-ui"
chmod 0644 "$STAGING/etc/default/easydns-ui"
cp packaging/debian/postinst packaging/debian/prerm packaging/debian/postrm "$STAGING/DEBIAN/"
cat > "$STAGING/DEBIAN/control" <<CONTROL
Package: easydns-ui
Version: $VERSION
Section: admin
Priority: optional
Architecture: $ARCH
Depends: adduser, coreutils, passwd
Maintainer: EasyDNS UI maintainers
Description: EasyDNS standalone OLED administration panel
A Go web UI for an existing EasyDNS server. Uses the server's
autogenerated control.token or local Unix control socket.
It does not install or replace the Rust DNS service.
CONTROL
cat > "$STAGING/DEBIAN/conffiles" <<CONF
/etc/default/easydns-ui
CONF
# The parent may be non-root while dpkg-deb is available.
OUT="$ROOT/dist/easydns-ui_${VERSION}_${ARCH}.deb"
dpkg-deb --build --root-owner-group "$STAGING" "$OUT" >/dev/null
printf '%s\n' "$OUT"
+129
View File
@@ -0,0 +1,129 @@
#!/bin/sh
# Build standalone EasyDNS UI .deb packages using Docker (no Go or dpkg on host).
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
IMAGE=${IMAGE:-golang:1.23-bookworm}
VERSION=${VERSION:-0.1.0}
ARCH=${ARCH:-${GOARCH:-all}}
usage() {
cat <<'HELP'
Usage: ./scripts/build_deb.sh [--arch all|amd64|arm64] [--version VERSION] [--image IMAGE]
Build Linux Debian packages inside a Docker container. Only Docker is required
on the host; Go, dpkg-deb, and cross-compilation tools run in the container.
Options:
--arch Architectures to build (default: all = amd64 + arm64)
--version Debian package version (default: 0.1.0)
--image Debian-based Go image (default: golang:1.23-bookworm)
-h, --help Show this message
Environment alternatives: ARCH, GOARCH, VERSION, IMAGE.
Packages are written to ./dist/easydns-ui_VERSION_ARCH.deb.
Examples:
./scripts/build_deb.sh
./scripts/build_deb.sh --arch amd64 --version 0.2.0
IMAGE=golang:1.23-bookworm ./scripts/build_deb.sh --arch arm64
HELP
}
while [ "$#" -gt 0 ]; do
case "$1" in
--arch|--version|--image)
option=$1
shift
if [ "$#" -eq 0 ]; then
printf 'Missing value for %s\n' "$option" >&2
usage >&2
exit 2
fi
case "$option" in
--arch) ARCH=$1 ;;
--version) VERSION=$1 ;;
--image) IMAGE=$1 ;;
esac
;;
-h|--help) usage; exit 0 ;;
*) printf 'Unknown argument: %s\n' "$1" >&2; usage >&2; exit 2 ;;
esac
shift
done
case "$ARCH" in
all) ARCHES='amd64 arm64' ;;
amd64|arm64) ARCHES=$ARCH ;;
*) printf 'Unsupported architecture: %s (use all, amd64 or arm64)\n' "$ARCH" >&2; exit 2 ;;
esac
# Debian requires a digit at the start of the version. Reject shell metacharacters,
# path separators, whitespace and newlines; the native builder validates it too.
case "$VERSION" in
''|[!0-9]*|*[!A-Za-z0-9.+~:-]*)
printf 'Invalid Debian package version: %s\n' "$VERSION" >&2
exit 2
;;
esac
case "$IMAGE" in
''|*[!A-Za-z0-9._:/@-]*)
printf 'Invalid Docker image reference: %s\n' "$IMAGE" >&2
exit 2
;;
esac
if ! command -v docker >/dev/null 2>&1; then
printf 'Docker is not installed or not in PATH. Install Docker Engine/Desktop first.\n' >&2
exit 1
fi
if ! docker info >/dev/null 2>&1; then
printf 'Cannot connect to Docker daemon (is Docker running and your user authorized?).\n' >&2
exit 1
fi
# Pre-create as host user: output files will not be owned by container root.
mkdir -p "$ROOT/dist"
uid=$(id -u)
gid=$(id -g)
printf 'Building EasyDNS UI %s for %s using Docker image %s\n' "$VERSION" "$ARCHES" "$IMAGE"
# Native Debian packaging script is the single source of truth for package
# contents, scripts, systemd unit, config, and control metadata. Running one
# normal Docker platform with CGO disabled builds both Linux architectures
# without QEMU, multiarch buildx or a compiler installed on the host.
docker run --rm \
--network none \
--user "$uid:$gid" \
--volume "$ROOT:/workspace:rw" \
--workdir /workspace \
--env "VERSION=$VERSION" \
--env "ARCHES=$ARCHES" \
--env GOOS=linux \
--env CGO_ENABLED=0 \
--env GOPROXY=off \
--env GOTOOLCHAIN=local \
--env GOFLAGS=-buildvcs=false \
--env HOME=/tmp \
--env GOCACHE=/tmp/easydns-go-cache \
--env GOPATH=/tmp/easydns-go-path \
"$IMAGE" sh -ec '
command -v go >/dev/null 2>&1 || { echo "Docker image does not contain Go" >&2; exit 1; }
command -v dpkg-deb >/dev/null 2>&1 || { echo "Docker image does not contain dpkg-deb (use a Debian-based Go image)" >&2; exit 1; }
for arch in $ARCHES; do
echo "==> Building linux/$arch"
GOARCH="$arch" VERSION="$VERSION" ./scripts/build-deb.sh
file="dist/easydns-ui_${VERSION}_${arch}.deb"
test -s "$file"
test "$(dpkg-deb -f "$file" Architecture)" = "$arch"
test "$(dpkg-deb -f "$file" Version)" = "$VERSION"
echo "==> Valid package: $file"
done
'
printf '\nCompleted. Packages:\n'
for arch in $ARCHES; do
output="$ROOT/dist/easydns-ui_${VERSION}_${arch}.deb"
[ -s "$output" ] || { printf 'Missing package: %s\n' "$output" >&2; exit 1; }
printf ' %s\n' "$output"
done