Support rootless Podman builds
This commit is contained in:
8 files changed
+198
-78
No files matched your search
+83
-17
@@ -1,14 +1,57 @@
|
||||
# Docker helper functions for Omarchy package build system
|
||||
# Container engine helpers for Omarchy package build system
|
||||
|
||||
check_docker() {
|
||||
if ! command -v docker &>/dev/null; then
|
||||
print_error "Docker is not installed"
|
||||
container_engine_supported() {
|
||||
[[ "$CONTAINER_ENGINE" == "docker" || "$CONTAINER_ENGINE" == "podman" ]]
|
||||
}
|
||||
|
||||
if [[ -z "${CONTAINER_ENGINE:-}" ]]; then
|
||||
for engine in docker podman; do
|
||||
if command -v "$engine" >/dev/null 2>&1 && "$engine" info >/dev/null 2>&1; then
|
||||
CONTAINER_ENGINE="$engine"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
export CONTAINER_ENGINE
|
||||
|
||||
# Rootless Podman otherwise maps the image's builder uid 1000 to a subordinate
|
||||
# host uid. keep-id makes files written through bind mounts belong to the user
|
||||
# who invoked the build.
|
||||
CONTAINER_RUN_ARGS=()
|
||||
if [[ "$CONTAINER_ENGINE" == "podman" ]]; then
|
||||
CONTAINER_RUN_ARGS+=("--userns=keep-id:uid=1000,gid=1000")
|
||||
fi
|
||||
|
||||
check_engine() {
|
||||
if [[ -n "$CONTAINER_ENGINE" ]] && ! container_engine_supported; then
|
||||
print_error "Unsupported CONTAINER_ENGINE: $CONTAINER_ENGINE (use docker or podman)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker info &>/dev/null; then
|
||||
print_error "Docker daemon is not running"
|
||||
print_warning "Start Docker with: sudo systemctl start docker"
|
||||
if [[ -z "$CONTAINER_ENGINE" ]]; then
|
||||
print_error "No working container engine found (tried Docker, then Podman)"
|
||||
if command -v docker >/dev/null 2>&1; then
|
||||
print_warning "Docker is installed but unavailable. Start it with: sudo systemctl start docker"
|
||||
elif command -v podman >/dev/null 2>&1; then
|
||||
print_warning "Podman is installed but 'podman info' failed"
|
||||
else
|
||||
print_warning "Install Docker or Podman"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v "$CONTAINER_ENGINE" >/dev/null 2>&1; then
|
||||
print_error "$CONTAINER_ENGINE is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! "$CONTAINER_ENGINE" info >/dev/null 2>&1; then
|
||||
if [[ "$CONTAINER_ENGINE" == "docker" ]]; then
|
||||
print_error "Docker daemon is not running or is not accessible"
|
||||
print_warning "Start Docker with: sudo systemctl start docker"
|
||||
else
|
||||
print_error "Podman is not available to the current user"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -22,8 +65,22 @@ docker_native_arch() {
|
||||
}
|
||||
|
||||
setup_qemu() {
|
||||
local target_arch="${1:-aarch64}"
|
||||
|
||||
if [[ "$CONTAINER_ENGINE" == "podman" ]]; then
|
||||
local registration="/proc/sys/fs/binfmt_misc/qemu-$target_arch"
|
||||
if [[ -r "$registration" ]] && grep -q '^flags:.*F' "$registration"; then
|
||||
print_success "QEMU $target_arch emulation is registered"
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_error "Rootless Podman requires host QEMU binfmt registration with the F flag"
|
||||
print_info "Install it with: sudo pacman -S qemu-user-static qemu-user-static-binfmt"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Register emulators for builds whose target differs from the host.
|
||||
if ! docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes >/dev/null 2>&1; then
|
||||
if ! "$CONTAINER_ENGINE" run --rm --privileged docker.io/multiarch/qemu-user-static --reset -p yes --credential yes >/dev/null 2>&1; then
|
||||
print_error "Failed to set up QEMU emulation"
|
||||
exit 1
|
||||
fi
|
||||
@@ -47,15 +104,24 @@ build_docker_image() {
|
||||
;;
|
||||
esac
|
||||
|
||||
print_info "Building Docker image for $arch ($platform) using $mirror mirror..."
|
||||
|
||||
docker buildx build \
|
||||
--platform "$platform" \
|
||||
--build-arg MIRROR="$mirror" \
|
||||
--load \
|
||||
-t "$image_tag" \
|
||||
-f "$build_dir/Dockerfile" \
|
||||
"$build_dir"
|
||||
print_info "Building container image for $arch ($platform) using $mirror mirror..."
|
||||
|
||||
if [[ "$CONTAINER_ENGINE" == "docker" ]]; then
|
||||
"$CONTAINER_ENGINE" buildx build \
|
||||
--platform "$platform" \
|
||||
--build-arg MIRROR="$mirror" \
|
||||
--load \
|
||||
-t "$image_tag" \
|
||||
-f "$build_dir/Dockerfile" \
|
||||
"$build_dir"
|
||||
else
|
||||
"$CONTAINER_ENGINE" build \
|
||||
--platform "$platform" \
|
||||
--build-arg MIRROR="$mirror" \
|
||||
-t "$image_tag" \
|
||||
-f "$build_dir/Dockerfile" \
|
||||
"$build_dir"
|
||||
fi
|
||||
}
|
||||
|
||||
get_platform_arg() {
|
||||
|
||||
Reference in new issue
Block a user