Skip to content

Commit 211063a

Browse files
committed
refinements and following packaging best practices
1 parent af4c59b commit 211063a

File tree

7 files changed

+173
-91
lines changed

7 files changed

+173
-91
lines changed

Makefile

Lines changed: 22 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -342,27 +342,9 @@ clean:
342342
make -C $(EF_TESTS) clean
343343
make -C $(STATE_TRANSITION_VECTORS) clean
344344

345-
.PHONY: install-cargo-deb deb-cargo deb-cargo-x86_64 deb-cargo-aarch64 deb-cargo-all test-deb-reproducible install-deb-local remove-deb-local clean-deb help-deb
346-
## Install cargo-deb if not present
347-
install-cargo-deb:
348-
@if ! command -v cargo-deb &> /dev/null; then \
349-
echo "Installing cargo-deb..."; \
350-
cargo install cargo-deb; \
351-
else \
352-
echo "cargo-deb already installed"; \
353-
fi
354-
355-
## Build .deb package using cargo-deb with reproducible settings
356-
deb-cargo: install-cargo-deb build-reproducible
345+
.PHONY: deb-cargo
346+
deb-cargo: build-reproducible ## Build .deb package using cargo-deb with reproducible settings
357347
@echo "Building .deb package with cargo-deb..."
358-
@if [ ! -f "lighthouse/lighthouse.service" ]; then \
359-
echo "❌ lighthouse.service not found in lighthouse/ directory"; \
360-
exit 1; \
361-
fi
362-
@if [ ! -f "README.md" ]; then \
363-
echo "❌ README.md not found in current directory"; \
364-
exit 1; \
365-
fi
366348

367349
cd lighthouse && \
368350
SOURCE_DATE_EPOCH=$(SOURCE_DATE) \
@@ -374,65 +356,26 @@ deb-cargo: install-cargo-deb build-reproducible
374356
@echo "✅ Package built successfully!"
375357
@find target/$(RUST_TARGET)/debian -name "*.deb" -exec ls -la {} \;
376358

377-
## Build .deb for specific architectures
378-
deb-cargo-x86_64:
359+
360+
.PHONY: deb-cargo-x86_64
361+
deb-cargo-x86_64: ## Build .deb for specific architectures
379362
$(MAKE) deb-cargo RUST_TARGET=x86_64-unknown-linux-gnu
380363

364+
.PHONY: deb-cargo-aarch64
381365
deb-cargo-aarch64:
382366
$(MAKE) deb-cargo RUST_TARGET=aarch64-unknown-linux-gnu
383367

368+
.PHONY: deb-cargo-all
384369
deb-cargo-all: deb-cargo-x86_64 deb-cargo-aarch64
385370

386-
## Test reproducibility of cargo-deb packages
387-
test-deb-reproducible:
388-
@echo "Testing cargo-deb package reproducibility..."
389-
@if ! command -v diffoscope &> /dev/null; then \
390-
echo "Installing diffoscope..."; \
391-
sudo apt-get update; \
392-
sudo apt-get install -y diffoscope binutils-multiarch; \
393-
fi
394-
395-
@echo "Building first package..."
396-
@rm -f lighthouse_*.deb lighthouse-deb-*.deb
397-
@$(MAKE) clean || true
398-
@$(MAKE) deb-cargo
399-
@FIRST_PACKAGE=$$(find target/$(RUST_TARGET)/debian -name "*.deb" | head -1); \
400-
if [ -n "$$FIRST_PACKAGE" ]; then \
401-
cp "$$FIRST_PACKAGE" ./lighthouse-deb-build-1.deb; \
402-
else \
403-
echo "❌ First package not found"; exit 1; \
404-
fi
405-
406-
@echo "Building second package..."
407-
@$(MAKE) clean || true
408-
@$(MAKE) deb-cargo
409-
@SECOND_PACKAGE=$$(find target/$(RUST_TARGET)/debian -name "*.deb" | head -1); \
410-
if [ -n "$$SECOND_PACKAGE" ]; then \
411-
cp "$$SECOND_PACKAGE" ./lighthouse-deb-build-2.deb; \
412-
else \
413-
echo "❌ Second package not found"; exit 1; \
414-
fi
415-
416-
@echo "Comparing packages..."
417-
@echo "=== Package sizes ==="
418-
@ls -la lighthouse-deb-build-*.deb
419-
@echo "=== SHA256 checksums ==="
420-
@sha256sum lighthouse-deb-build-*.deb
421-
422-
@if cmp -s lighthouse-deb-build-1.deb lighthouse-deb-build-2.deb; then \
423-
echo "✅ SUCCESS: cargo-deb packages are identical!"; \
424-
echo "✅ Reproducible build PASSED"; \
425-
else \
426-
echo "❌ FAILED: cargo-deb packages differ"; \
427-
echo "Running detailed analysis with diffoscope..."; \
428-
diffoscope --text lighthouse-deb-build-1.deb lighthouse-deb-build-2.deb > cargo-deb-diff.txt || true; \
429-
echo "Differences saved to cargo-deb-diff.txt"; \
430-
echo "❌ Reproducible build FAILED"; \
431-
exit 1; \
432-
fi
433371

434-
## Install .deb package locally for testing
435-
install-deb-local:
372+
.PHONY: test-deb-reproducible
373+
test-deb-reproducible: ## Test reproducibility of cargo-deb packages
374+
@./scripts/test-deb-reproducible.sh $(RUST_TARGET)
375+
376+
377+
.PHONY: install-deb-local
378+
install-deb-local: ## Install .deb package locally for testing
436379
@PACKAGE=$$(find target/$(RUST_TARGET)/debian -name "*.deb" | head -1); \
437380
if [ -n "$$PACKAGE" ]; then \
438381
echo "Installing lighthouse package: $$PACKAGE"; \
@@ -449,22 +392,23 @@ install-deb-local:
449392
echo "❌ No .deb package found. Run 'make deb-cargo' first."; \
450393
fi
451394

452-
## Remove installed lighthouse package
453-
remove-deb-local:
395+
396+
.PHONY: remove-deb-local
397+
remove-deb-local: ## Remove installed lighthouse package
454398
@echo "Removing lighthouse package..."
455399
sudo dpkg -r lighthouse || true
456400
sudo systemctl daemon-reload || true
457401

458-
## Clean up debian packaging artifacts
459-
clean-deb:
402+
.PHONY: clean-deb
403+
clean-deb: ## Clean up debian packaging artifacts
460404
@echo "Cleaning up debian packaging artifacts..."
461405
rm -f lighthouse_*.deb lighthouse-deb-*.deb *-diff.txt
462406
rm -rf target/*/debian/
463407

464-
## Show help for debian packaging
465-
help-deb:
408+
409+
.PHONY: help-deb
410+
help-deb: ## Show help for debian packaging
466411
@echo "Clean Debian Packaging Targets:"
467-
@echo " install-cargo-deb - Install cargo-deb tool"
468412
@echo " deb-cargo - Build .deb package with cargo-deb"
469413
@echo " deb-cargo-x86_64 - Build x86_64 .deb package"
470414
@echo " deb-cargo-aarch64 - Build aarch64 .deb package"

lighthouse/Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,24 @@ name = "lighthouse_tests"
9595
path = "tests/main.rs"
9696

9797
[package.metadata.deb]
98-
# Package metadata
9998
maintainer = "Sigma Prime <[email protected]>"
10099
extended-description = """\
101100
Lighthouse is a Rust implementation of the Ethereum beacon chain, \
102101
built by Sigma Prime. It implements the official Ethereum 2.0 specification."""
103102

104-
# Dependencies
105103
depends = "$auto, systemd"
106104
section = "net"
107105
priority = "optional"
106+
maintainer-scripts = "debian/" # This tells cargo-deb where to find scripts
108107

109108
# System integration
110109
systemd-units = { enable = false, start = false }
111110

112111
# Assets to include in the package
113112
assets = [
114-
# Binary - use target/release/ prefix (cargo-deb will replace with actual path)
115113
["target/release/lighthouse", "usr/bin/", "755"],
116-
117-
# Systemd service (in lighthouse directory)
118-
["lighthouse.service", "lib/systemd/system/", "644"],
119-
120-
# Documentation (in parent directory)
114+
["debian/lighthouse.service", "lib/systemd/system/", "644"],
121115
["../README.md", "usr/share/doc/lighthouse/", "644"],
122116
]
123117

124-
# Use default features - let Makefile handle the building
125118
default-features = false

lighthouse/lighthouse.service renamed to lighthouse/debian/lighthouse.service

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
[Unit]
2-
Description=Lighthouse Ethereum Beacon Chain Client
3-
Documentation=https://lighthouse-book.sigmaprime.io/
2+
Description=Lighthouse Ethereum Beacon Node
43
After=network.target
54
Wants=network.target
65

76
[Service]
87
Type=simple
9-
DynamicUser=true
108
User=lighthouse
11-
Group=eth
9+
Group=lighthouse
1210
Restart=always
1311
RestartSec=5
1412
TimeoutStopSec=180

lighthouse/debian/postinst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Create lighthouse user if it doesn't exist
5+
if ! getent passwd lighthouse >/dev/null 2>&1; then
6+
adduser --system --group --home /var/lib/lighthouse \
7+
--shell /bin/false --gecos "Lighthouse Beacon Node" lighthouse
8+
fi
9+
10+
# Create data directory
11+
mkdir -p /var/lib/lighthouse
12+
chown lighthouse:lighthouse /var/lib/lighthouse
13+
chmod 750 /var/lib/lighthouse
14+
15+
# Create log directory
16+
mkdir -p /var/log/lighthouse
17+
chown lighthouse:lighthouse /var/log/lighthouse
18+
chmod 750 /var/log/lighthouse
19+
20+
# Reload systemd
21+
systemctl daemon-reload || true
22+
23+
#DEBHELPER#
24+
25+
exit 0

lighthouse/debian/postrm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = "purge" ]; then
5+
# Remove user (optional - some prefer to keep it)
6+
if getent passwd lighthouse >/dev/null 2>&1; then
7+
deluser lighthouse || true
8+
fi
9+
10+
# Remove data directory (be careful!)
11+
# rm -rf /var/lib/lighthouse || true
12+
# rm -rf /var/log/lighthouse || true
13+
fi
14+
15+
#DEBHELPER#
16+
17+
exit 0

lighthouse/debian/prerm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = "remove" ]; then
5+
# Stop service if running
6+
systemctl stop lighthouse || true
7+
systemctl disable lighthouse || true
8+
fi
9+
10+
#DEBHELPER#
11+
12+
exit 0

scripts/test-deb-reproducible.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
#
3+
# Test reproducibility of cargo-deb packages
4+
#
5+
# Usage: ./scripts/test-deb-reproducible.sh [RUST_TARGET]
6+
#
7+
# This script builds the same Debian package twice with clean builds in between,
8+
# then compares them to ensure reproducible builds are working correctly.
9+
10+
set -euo pipefail
11+
12+
# Default target if not provided
13+
RUST_TARGET="${1:-x86_64-unknown-linux-gnu}"
14+
15+
echo "🔄 Testing cargo-deb package reproducibility for ${RUST_TARGET}..."
16+
17+
# Check if diffoscope is available, install if needed
18+
if ! command -v diffoscope &> /dev/null; then
19+
echo "📦 Installing diffoscope..."
20+
sudo apt-get update
21+
sudo apt-get install -y diffoscope binutils-multiarch
22+
fi
23+
24+
# Clean up any existing test artifacts
25+
echo "🧹 Cleaning up previous test artifacts..."
26+
rm -f lighthouse_*.deb lighthouse-deb-*.deb *-diff.txt
27+
28+
# Build first package
29+
echo "🔨 Building first package..."
30+
make clean || true
31+
make deb-cargo RUST_TARGET="${RUST_TARGET}"
32+
33+
FIRST_PACKAGE=$(find target/"${RUST_TARGET}"/debian -name "*.deb" | head -1)
34+
if [ -n "$FIRST_PACKAGE" ]; then
35+
cp "$FIRST_PACKAGE" ./lighthouse-deb-build-1.deb
36+
echo "✅ First package built: $(basename "$FIRST_PACKAGE")"
37+
else
38+
echo "❌ First package not found"
39+
exit 1
40+
fi
41+
42+
# Build second package
43+
echo "🔨 Building second package..."
44+
make clean || true
45+
make deb-cargo RUST_TARGET="${RUST_TARGET}"
46+
47+
SECOND_PACKAGE=$(find target/"${RUST_TARGET}"/debian -name "*.deb" | head -1)
48+
if [ -n "$SECOND_PACKAGE" ]; then
49+
cp "$SECOND_PACKAGE" ./lighthouse-deb-build-2.deb
50+
echo "✅ Second package built: $(basename "$SECOND_PACKAGE")"
51+
else
52+
echo "❌ Second package not found"
53+
exit 1
54+
fi
55+
56+
# Compare packages
57+
echo "📊 Comparing packages..."
58+
echo ""
59+
echo "=== Package sizes ==="
60+
ls -lah lighthouse-deb-build-*.deb
61+
62+
echo ""
63+
echo "=== SHA256 checksums ==="
64+
sha256sum lighthouse-deb-build-*.deb
65+
66+
echo ""
67+
echo "=== Binary comparison ==="
68+
if cmp -s lighthouse-deb-build-1.deb lighthouse-deb-build-2.deb; then
69+
echo "✅ SUCCESS: cargo-deb packages are identical!"
70+
echo "✅ Reproducible build PASSED for ${RUST_TARGET}"
71+
echo ""
72+
echo "🧹 Cleaning up test artifacts..."
73+
rm -f lighthouse-deb-build-*.deb
74+
exit 0
75+
else
76+
echo "❌ FAILED: cargo-deb packages differ"
77+
echo "🔍 Running detailed analysis with diffoscope..."
78+
79+
# Generate detailed diff report
80+
DIFF_FILE="cargo-deb-diff-${RUST_TARGET}.txt"
81+
if diffoscope --text lighthouse-deb-build-1.deb lighthouse-deb-build-2.deb > "$DIFF_FILE" 2>/dev/null; then
82+
echo "📄 Differences saved to ${DIFF_FILE}"
83+
echo "📄 Summary of first few differences:"
84+
head -20 "$DIFF_FILE" || true
85+
else
86+
echo "⚠️ diffoscope encountered issues, but differences were detected"
87+
fi
88+
89+
echo ""
90+
echo "❌ Reproducible build FAILED for ${RUST_TARGET}"
91+
echo "💡 Tip: Check the diff file for details on what differs between builds"
92+
exit 1
93+
fi

0 commit comments

Comments
 (0)