Some checks failed
Comprehensive CI/CD Pipeline / Build and Test (push) Successful in 16m28s
Comprehensive CI/CD Pipeline / Security Audit (push) Failing after 7s
Comprehensive CI/CD Pipeline / Package Validation (push) Successful in 52s
Comprehensive CI/CD Pipeline / Status Report (push) Has been skipped
- Enhanced check_systemd() function to properly detect container environments - Added detection for Docker, Podman, and other container runtimes - Verify systemd is running as PID 1 before attempting service operations - Check systemd D-Bus availability before service configuration - Gracefully skip systemd setup in containers with helpful messages - Provide manual configuration instructions for real systems Fixes container builds and CI/CD pipelines that install apt-ostree while maintaining full functionality on real systems with systemd.
3.4 KiB
3.4 KiB
apt-ostree Container Installation Fix
Problem Solved
The apt-ostree package was failing to install in container environments due to systemd service configuration attempts that require a running systemd instance.
Root Cause
The original check_systemd() function only checked if the systemctl command existed, but didn't verify:
- If systemd was actually running as PID 1
- If the system was in a container environment
- If the systemd D-Bus interface was available
Solution Implemented
Updated the check_systemd() function in debian/apt-ostree.postinst to:
- Check for systemctl command availability
- Detect container environments using multiple indicators:
/.dockerenvfile (Docker)containerenvironment variable (Podman, Docker, etc.)/run/.containerenvfile (Podman)- Docker in
/proc/1/cgroup(additional Docker detection)
- Verify systemd is running as PID 1 using
ps -p 1 -o comm= - Check systemd D-Bus availability using
systemctl is-system-running
Key Changes
Before (Original Code)
check_systemd() {
if ! command -v systemctl >/dev/null 2>&1; then
log "Warning: systemd not available, skipping service setup"
return 1
fi
return 0
}
After (Fixed Code)
check_systemd() {
# Check if systemctl command exists
if ! command -v systemctl >/dev/null 2>&1; then
log "Warning: systemd not available, skipping service setup"
return 1
fi
# Check if we're in a container environment
if [ -f /.dockerenv ] || [ -n "${container:-}" ] || [ -f /run/.containerenv ] || \
([ -f /proc/1/cgroup ] && grep -q docker /proc/1/cgroup 2>/dev/null); then
log "Warning: Running in container environment, skipping systemd service setup"
return 1
fi
# Check if systemd is actually running as PID 1
if ! ps -p 1 -o comm= | grep -q systemd; then
log "Warning: systemd not running as PID 1, skipping service setup"
return 1
fi
# Check if systemd D-Bus is available
if ! systemctl is-system-running >/dev/null 2>&1; then
log "Warning: systemd not running, skipping service setup"
return 1
fi
return 0
}
Additional Improvements
- Enhanced
setup_service()function to provide helpful manual configuration instructions when skipping systemd setup - Added proper parentheses to fix logical operator precedence in container detection
Testing Results
✅ Container Environment: Package installs successfully, skips systemd configuration gracefully ✅ Real System: Package installs and configures systemd services normally ✅ Podman Container: Verified working with actual Podman container build
Files Modified
debian/apt-ostree.postinst- Updatedcheck_systemd()andsetup_service()functions
Impact
- Fixes: Container builds and CI/CD pipelines that install apt-ostree
- Maintains: Full functionality on real systems with systemd
- Improves: User experience with clear error messages and manual configuration instructions
Verification Commands
# Test in container (should skip systemd)
docker run --rm -it debian:unstable bash -c "apt update && apt install -y apt-ostree"
# Test on real system (should configure systemd)
apt install -y apt-ostree && systemctl status apt-ostreed
Status
✅ COMPLETED - Fix implemented and tested successfully