Rework build system
Replace the dpkg-buildpackage / debhelper rig with the same pattern
used in vpp-maglev and govpp-snmp-agentx: a Makefile that
cross-compiles CGO-free static binaries for amd64 and arm64, plus a
debian/build-deb.sh that stages the .deb directly with dpkg-deb. The
two arch packages drop into build/ and run on any glibc/musl Linux of
the matching arch.
VERSION is parsed once from debian/changelog and injected at link
time via -ldflags "-X 'main.Version=...' -X 'main.Commit=...' -X
'main.Date=...'", so 's3-genindex -version' is the source of truth
for which build is running. The Version constant in main.go becomes
a var to make this work; the old sync-version make target is gone.
Removes the now-unused debian/{control,rules,install,compat} files
and the matching debhelper artifact entries from .gitignore. build/
is added to .gitignore.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+1
-10
@@ -1,15 +1,6 @@
|
||||
/s3-genindex
|
||||
build/
|
||||
|
||||
# Generated index files
|
||||
**/index.html
|
||||
coverage.*
|
||||
|
||||
# Debian packaging artifacts
|
||||
debian/.debhelper/
|
||||
debian/.gocache/
|
||||
debian/go/
|
||||
debian/s3-genindex/
|
||||
debian/files
|
||||
debian/*.substvars
|
||||
debian/debhelper-build-stamp
|
||||
debian/*.debhelper
|
||||
|
||||
@@ -1,108 +1,59 @@
|
||||
.PHONY: build clean wipe test help sync-version pkg-deb
|
||||
PROG := s3-genindex
|
||||
MODULE := git.ipng.ch/ipng/s3-genindex
|
||||
NATIVE_ARCH := $(shell go env GOARCH)
|
||||
VERSION := ${shell head -1 debian/changelog | sed -n 's/.*(\([^)]*\)).*/\1/p'}
|
||||
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
LDFLAGS := -s -w \
|
||||
-X 'main.Version=$(VERSION)' \
|
||||
-X 'main.Commit=$(COMMIT_HASH)' \
|
||||
-X 'main.Date=$(DATE)'
|
||||
|
||||
# Default target
|
||||
all: build
|
||||
# CGO_ENABLED=0 yields a fully static binary so the same .deb runs on
|
||||
# any glibc/musl Linux of the matching arch. The AWS SDK and the rest
|
||||
# of this codebase are pure Go, so this has no behavioural impact
|
||||
# beyond switching net/dns to the pure-Go resolver.
|
||||
export CGO_ENABLED := 0
|
||||
|
||||
# Build the binary
|
||||
build:
|
||||
@echo "Building s3-genindex..."
|
||||
go build -o s3-genindex ./cmd/s3-genindex
|
||||
@echo "Build complete: s3-genindex"
|
||||
.PHONY: help all build build-amd64 build-arm64 test pkg-deb fmt vet lint check clean
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
go test -v ./...
|
||||
@echo "Tests complete"
|
||||
help: ## Show this help
|
||||
@printf "Usage: make <target>\n\nTargets:\n"
|
||||
@awk -F ':.*## ' '/^[A-Za-z][A-Za-z0-9_-]*:.*## / {printf " %-16s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
# Run tests with coverage
|
||||
test-coverage:
|
||||
@echo "Running tests with coverage..."
|
||||
go test -v -coverprofile=coverage.out ./...
|
||||
go tool cover -html=coverage.out -o coverage.html
|
||||
@echo "Coverage report generated: coverage.html"
|
||||
all: build ## Alias for build (native arch)
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
rm -f s3-genindex
|
||||
rm -f coverage.out coverage.html
|
||||
rm -rf debian/s3-genindex debian/files debian/*.substvars debian/debhelper-build-stamp
|
||||
[ -d debian/go ] && chmod -R +w debian/go || true
|
||||
rm -rf debian/.gocache debian/go
|
||||
find . -name index.html -delete
|
||||
@echo "Clean complete"
|
||||
build: ## Build the binary for the host architecture
|
||||
mkdir -p build/$(NATIVE_ARCH)
|
||||
go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/$(PROG) ./cmd/$(PROG)
|
||||
|
||||
# Wipe everything including test caches
|
||||
wipe: clean
|
||||
@echo "Wiping test cache and module cache..."
|
||||
go clean -testcache
|
||||
go clean -modcache
|
||||
@echo "Wipe complete"
|
||||
build-amd64: ## Cross-build the binary for linux/amd64
|
||||
mkdir -p build/amd64
|
||||
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/$(PROG) ./cmd/$(PROG)
|
||||
|
||||
# Install binary to $GOPATH/bin or $GOBIN
|
||||
install:
|
||||
@echo "Installing s3-genindex..."
|
||||
go install ./cmd/s3-genindex
|
||||
@echo "Install complete"
|
||||
build-arm64: ## Cross-build the binary for linux/arm64
|
||||
mkdir -p build/arm64
|
||||
GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/$(PROG) ./cmd/$(PROG)
|
||||
|
||||
# Format code
|
||||
fmt:
|
||||
@echo "Formatting code..."
|
||||
test: ## Run all Go unit tests
|
||||
go test ./...
|
||||
|
||||
pkg-deb: build-amd64 build-arm64 ## Build .deb packages for amd64 and arm64
|
||||
debian/build-deb.sh $(PROG) amd64 $(VERSION)
|
||||
debian/build-deb.sh $(PROG) arm64 $(VERSION)
|
||||
|
||||
fmt: ## go fmt everything
|
||||
go fmt ./...
|
||||
@echo "Format complete"
|
||||
|
||||
# Vet code for issues
|
||||
vet:
|
||||
@echo "Vetting code..."
|
||||
vet: ## go vet everything
|
||||
go vet ./...
|
||||
@echo "Vet complete"
|
||||
|
||||
# Lint code (requires golangci-lint)
|
||||
lint:
|
||||
@echo "Linting code..."
|
||||
@if command -v golangci-lint >/dev/null 2>&1; then \
|
||||
golangci-lint run; \
|
||||
else \
|
||||
echo "golangci-lint not found, skipping lint"; \
|
||||
fi
|
||||
lint: ## golangci-lint, if installed
|
||||
@if command -v golangci-lint >/dev/null 2>&1; then golangci-lint run; else echo "golangci-lint not installed, skipping"; fi
|
||||
|
||||
# Run all checks
|
||||
check: fmt vet lint test
|
||||
@echo "All checks passed"
|
||||
check: fmt vet lint test ## Format, vet, lint, and test
|
||||
|
||||
# Run benchmarks
|
||||
bench:
|
||||
@echo "Running benchmarks..."
|
||||
go test -bench=. ./...
|
||||
|
||||
# Sync version from debian/changelog to source code
|
||||
sync-version:
|
||||
@echo "Syncing version..."
|
||||
@version=$$(head -1 debian/changelog | sed -n 's/.*(\([^)]*\)).*/\1/p'); \
|
||||
sed -i "s/const Version = .*/const Version = \"$$version\"/" cmd/s3-genindex/main.go; \
|
||||
echo "Updated version to $$version"
|
||||
|
||||
# Build Debian package
|
||||
pkg-deb: sync-version
|
||||
@echo "Building Debian package..."
|
||||
DEB_BUILD_OPTIONS=noautodbgsym fakeroot dpkg-buildpackage -us -uc -b
|
||||
@echo "Debian package build complete"
|
||||
|
||||
# Show help
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " build - Build the s3-genindex binary"
|
||||
@echo " test - Run all tests"
|
||||
@echo " test-coverage - Run tests with coverage report"
|
||||
@echo " clean - Remove build artifacts"
|
||||
@echo " wipe - Clean everything including caches"
|
||||
@echo " install - Install binary to GOPATH/bin"
|
||||
@echo " fmt - Format code"
|
||||
@echo " vet - Vet code for issues"
|
||||
@echo " lint - Lint code (requires golangci-lint)"
|
||||
@echo " check - Run fmt, vet, lint, and test"
|
||||
@echo " bench - Run benchmarks"
|
||||
@echo " sync-version - Sync version from debian/changelog to source"
|
||||
@echo " pkg-deb - Build Debian package"
|
||||
@echo " help - Show this help message"
|
||||
clean: ## Remove build artifacts
|
||||
rm -rf build/
|
||||
rm -f $(PROG) coverage.out coverage.html
|
||||
find . -name index.html -delete
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"git.ipng.ch/ipng/s3-genindex/internal/indexgen"
|
||||
)
|
||||
|
||||
// Version is the application version (sync'd from debian/changelog)
|
||||
const Version = "1.0.0-1"
|
||||
// Version is set at link time via -ldflags "-X main.Version=...".
|
||||
var Version = "dev"
|
||||
|
||||
// S3Config holds S3 connection configuration
|
||||
type S3Config struct {
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Build one s3-genindex .deb for one architecture.
|
||||
# Usage: build-deb.sh <package> <amd64|arm64> <version>
|
||||
#
|
||||
# The version is also baked into the binary at link time (see Makefile
|
||||
# LDFLAGS), so `s3-genindex -version` is the source of truth for "which
|
||||
# build". The .deb itself only carries the release version.
|
||||
set -euo pipefail
|
||||
|
||||
PACKAGE="${1:?usage: build-deb.sh <package> <amd64|arm64> <version>}"
|
||||
ARCH="${2:?usage: build-deb.sh <package> <amd64|arm64> <version>}"
|
||||
VERSION="${3:?usage: build-deb.sh <package> <amd64|arm64> <version>}"
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
PKG="${PACKAGE}_${VERSION}_${ARCH}"
|
||||
STAGING="$(mktemp -d)"
|
||||
trap 'rm -rf "$STAGING"' EXIT
|
||||
|
||||
echo "Building ${PKG}.deb"
|
||||
|
||||
install -d "$STAGING/DEBIAN"
|
||||
install -d "$STAGING/usr/bin"
|
||||
install -d "$STAGING/usr/share/man/man1"
|
||||
|
||||
# s3-genindex is a CLI tool, so /usr/bin (on every login PATH) is the
|
||||
# right place; no /usr/sbin, no systemd unit, no /etc conffile.
|
||||
install -m 755 "$REPO_ROOT/build/${ARCH}/${PACKAGE}" "$STAGING/usr/bin/${PACKAGE}"
|
||||
gzip -9 -c "$REPO_ROOT/docs/${PACKAGE}.1" > "$STAGING/usr/share/man/man1/${PACKAGE}.1.gz"
|
||||
|
||||
sed "s/@VERSION@/${VERSION}/;s/@ARCH@/${ARCH}/" \
|
||||
"$REPO_ROOT/debian/${PACKAGE}.control.in" > "$STAGING/DEBIAN/control"
|
||||
|
||||
mkdir -p "$REPO_ROOT/build"
|
||||
OUT="$REPO_ROOT/build/${PKG}.deb"
|
||||
dpkg-deb --build --root-owner-group "$STAGING" "$OUT"
|
||||
echo "Built: $OUT"
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
10
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
Source: s3-genindex
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: Pim van Pelt <pim@ipng.ch>
|
||||
Build-Depends: debhelper (>= 10), golang-go
|
||||
Standards-Version: 4.1.2
|
||||
Homepage: https://git.ipng.ch/ipng/s3-genindex
|
||||
|
||||
Package: s3-genindex
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: HTML directory index generator for local and S3 storage
|
||||
Generate HTML directory indexes with file type icons and responsive design
|
||||
for local directories and S3-compatible storage. This is particularly useful
|
||||
for S3 buckets that are publicly readable.
|
||||
.
|
||||
Features include local directory indexing with recursive traversal,
|
||||
S3-compatible storage support (MinIO, AWS S3, etc.), hierarchical directory
|
||||
structure for S3 buckets, responsive HTML design with file type icons,
|
||||
dry run mode for testing, flexible filtering with glob patterns and regex
|
||||
exclusion, and hidden file control.
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
s3-genindex usr/bin
|
||||
docs/s3-genindex.1 usr/share/man/man1
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
export GO111MODULE=on
|
||||
export GOPROXY=direct
|
||||
export GOSUMDB=off
|
||||
export GOCACHE=$(CURDIR)/debian/.gocache
|
||||
export GOPATH=$(CURDIR)/debian/go
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
override_dh_auto_build:
|
||||
go build -o s3-genindex ./cmd/s3-genindex
|
||||
|
||||
override_dh_auto_test:
|
||||
go test ./...
|
||||
|
||||
override_dh_auto_install:
|
||||
mkdir -p debian/s3-genindex/usr/bin
|
||||
cp s3-genindex debian/s3-genindex/usr/bin/
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
Package: s3-genindex
|
||||
Version: @VERSION@
|
||||
Architecture: @ARCH@
|
||||
Maintainer: Pim van Pelt <pim@ipng.ch>
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Homepage: https://git.ipng.ch/ipng/s3-genindex
|
||||
Description: HTML directory index generator for local and S3 storage
|
||||
Generate HTML directory indexes with file type icons and responsive
|
||||
design for local directories and S3-compatible storage. Particularly
|
||||
useful for S3 buckets that are publicly readable.
|
||||
.
|
||||
Features include local directory indexing with recursive traversal,
|
||||
S3-compatible storage support (MinIO, AWS S3, etc.), hierarchical
|
||||
directory structure for S3 buckets, responsive HTML design with file
|
||||
type icons, dry run mode for testing, flexible filtering with glob
|
||||
patterns and regex exclusion, and hidden file control.
|
||||
Reference in New Issue
Block a user