Skip to content

Commit 8977f44

Browse files
author
qount25
committed
Problem: pbuilder uses tar, which results in "Cannot readlink: Invalid argument"
The issue is present on podman hosts when they are themslves KVM guests, but is not present if podman is used on host OS, which iteself is installed on bare metal. Solution: create `faketar` script and patch pbuilder to use it instead of tar. The `faketar` script uses simple `cp` and `mv` commands, which not only help us avoid the issue with `tar`, but also make our builds faster by skipping compression & decompression of tgz. Due to a rather esoteric nature of the problem `faketar` script is reasonable workaround, which also saves on build time.
1 parent 0118b31 commit 8977f44

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

lib/pgpm/deb/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# { "builder": {"Entitlements": {"security-insecure": true }} }
88
# ```
99
# ```
10-
# DOCKER_BUILDKIT=1 docker build --allow security.insecure -t IMAGE_NAME /path/to/pgpm
10+
# DOCKER_BUILDKIT=1 docker build --allow security.insecure -t IMAGE_NAME .
1111
# ```
1212

1313
# This Dockerfile is used to build a Debian image, which includes pbuilder and
@@ -21,8 +21,12 @@ MAINTAINER PGPM Debian Maintainer [email protected]
2121
VOLUME /proc
2222
ARG DEBIAN_FRONTEND=noninteractive
2323
RUN apt update
24-
RUN apt install -y build-essential pbuilder fakeroot fakechroot
24+
RUN apt install -y build-essential pbuilder fakeroot fakechroot vim ripgrep
2525
RUN echo 'MIRRORSITE=http://deb.debian.org/debian' > /etc/pbuilderrc
2626
RUN echo 'AUTO_DEBSIGN=${AUTO_DEBSIGN:-no}' > /root/.pbuilderrc
2727
RUN echo 'HOOKDIR=/var/cache/pbuilder/hooks' >> /root/.pbuilderrc
28-
RUN --security=insecure pbuilder create
28+
COPY scripts/faketar /usr/bin/
29+
RUN chmod +x /usr/bin/faketar
30+
RUN sed -E -i "s/local TAR=tar/local TAR=faketar/" /usr/lib/pbuilder/pbuilder-modules
31+
RUN sed -E -i "s/if [!] tar -c --use-compress-program/if ! faketar -c --use-compress-program/" /usr/lib/pbuilder/pbuilder-modules
32+
RUN --security=insecure fakeroot pbuilder create

lib/pgpm/deb/builder.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def initialize(spec)
1414
def build
1515
prepare_image
1616
start_container
17-
patch_pbuilder
1817

1918
prepare_versioned_source
2019
generate_deb_src_files(:versioned)
@@ -127,9 +126,12 @@ def prepare_image
127126

128127
def build_local_image
129128
puts " Building local #{image_name}..."
130-
system("podman create -it --privileged --tmpfs /tmp --name pgpm-deb-tmp #{base_image_name}")
129+
container_opts = "-it --privileged --tmpfs /tmp --name pgpm-deb-tmp"
130+
system("podman create #{container_opts} #{base_image_name}")
131131
system("podman start pgpm-deb-tmp")
132132

133+
patch_pbuilder
134+
133135
# Generate pbuilder_install script.sh, copy it inside the image
134136
pbuild_install_script_path = "#{@pgpm_dir}/pbuilder_install_script.sh"
135137
puts " Generating #{pbuild_install_script_path}..."
@@ -194,7 +196,9 @@ def start_container
194196
# a result.
195197
def patch_pbuilder
196198
cmd = "sed -E -i \"s/(^function clean_subdirectories.*$)/\\1\\n return/g\" /usr/lib/pbuilder/pbuilder-modules"
197-
system("podman exec #{@container_name} /bin/bash -c '#{cmd}'")
199+
system("podman exec pgpm-deb-tmp /bin/bash -c '#{cmd}'")
200+
cmd = "sed -E -i \"s/if [[] [!] -f [\\\"]([$]BASETGZ)/if [ ! -d \\\"\\1/\" /usr/lib/pbuilder/pbuilder-modules"
201+
system("podman exec pgpm-deb-tmp /bin/bash -c '#{cmd}'")
198202
end
199203

200204
def run_build(pkg_type = :versioned)

lib/pgpm/deb/scripts/faketar

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
ARGS="$@"
4+
echo "faketar ${ARGS[@]}"
5+
6+
if [[ " ${ARGS[*]} " =~ [[:space:]]-x[[:space:]] ]]; then # compress
7+
# Replacing this command:
8+
# tar -x -p -f "$BASETGZ"
9+
src="$4"
10+
echo "Copying $src/* to $(pwd)"
11+
cp -pur $src/* ./
12+
elif [[ " ${ARGS[*]} " =~ [[:space:]]-c[[:space:]] ]]; then # extract
13+
# Replacing this command:
14+
# tar -c --use-compress-program "$COMPRESSPROG" -f "${BASETGZ}.tmp" ./*
15+
target="$5"
16+
src="."
17+
mkdir $target
18+
echo "Moving $src/* to $target/"
19+
mv $src/* $target/
20+
# Remove existing directory into which we move the contents.
21+
# Otherwise, pbuilder (when it calls `mv`) will move $target inside it,
22+
# instead of copying $target/* into it.
23+
if [[ -d "${target%".tmp"}" ]]; then
24+
rm -rf "${target%".tmp"}"
25+
fi
26+
fi

0 commit comments

Comments
 (0)