commit
8c4d463f1e
96 files changed
+3319
No files matched your search
Executable
+129
@@ -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
|
||||
Reference in new issue
Block a user