Fix apt-ostree container installation failure
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
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.
This commit is contained in:
parent
6a6f511a51
commit
2306ee2a72
2 changed files with 122 additions and 1 deletions
96
CONTAINER_FIX_SUMMARY.md
Normal file
96
CONTAINER_FIX_SUMMARY.md
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# 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:
|
||||
1. If systemd was actually running as PID 1
|
||||
2. If the system was in a container environment
|
||||
3. If the systemd D-Bus interface was available
|
||||
|
||||
## Solution Implemented
|
||||
Updated the `check_systemd()` function in `debian/apt-ostree.postinst` to:
|
||||
|
||||
1. **Check for systemctl command availability**
|
||||
2. **Detect container environments** using multiple indicators:
|
||||
- `/.dockerenv` file (Docker)
|
||||
- `container` environment variable (Podman, Docker, etc.)
|
||||
- `/run/.containerenv` file (Podman)
|
||||
- Docker in `/proc/1/cgroup` (additional Docker detection)
|
||||
3. **Verify systemd is running as PID 1** using `ps -p 1 -o comm=`
|
||||
4. **Check systemd D-Bus availability** using `systemctl is-system-running`
|
||||
|
||||
## Key Changes
|
||||
|
||||
### Before (Original Code)
|
||||
```bash
|
||||
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)
|
||||
```bash
|
||||
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` - Updated `check_systemd()` and `setup_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
|
||||
```bash
|
||||
# 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
|
||||
27
debian/apt-ostree.postinst
vendored
27
debian/apt-ostree.postinst
vendored
|
|
@ -28,18 +28,43 @@ setup_completions() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Function to check if systemd is available
|
||||
# Function to check if systemd is available and running
|
||||
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
|
||||
}
|
||||
|
||||
# Function to enable and start the service
|
||||
setup_service() {
|
||||
if ! check_systemd; then
|
||||
log "Skipping systemd service configuration"
|
||||
log "To configure services manually on a real system, run:"
|
||||
log " systemctl enable apt-ostreed.service"
|
||||
log " systemctl start apt-ostreed.service"
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue