Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fix(build): auto detection when to use wh…
Browse files Browse the repository at this point in the history
…en compressing the image using xz
  • Loading branch information
reubenmiller committed Jan 11, 2024
1 parent ced781e commit fc352e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
10 changes: 0 additions & 10 deletions run-bakery
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ set -e
DOCKER=${DOCKER:-docker}
RUGPI_IMAGE=${RUGPI_IMAGE:-ghcr.io/silitics/rugpi-bakery:latest}

OPTIONS=()
if command -V id >/dev/null >&2; then
UID=$(id -u)
GID=$(id -g)
OPTIONS+=(
--user "$UID:$GID"
)
fi

$DOCKER run --rm --privileged \
"${OPTIONS[@]}" \
-v "$(pwd)":/project \
-v /dev:/dev \
--pull always \
Expand Down
18 changes: 8 additions & 10 deletions scripts/compress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ set -e

SUDO=

test_xz() {
# Check if xz can be used without sudo using a dummy file
echo "dummy" > .dummy_compress
failed=0
if ! xz -0 -v .dummy_compress >/dev/null >&2; then
failed=1
requires_sudo() {
if stat --help >/dev/null 2>&1; then
IMAGE_OWNER=$(stat -c "%u" justfile)
else
# bsd version
IMAGE_OWNER=$(stat -f "%u %g" justfile)
fi
rm -f .dummy_compress
rm -f .dummy_compress.xz
return "$failed"
[ "$IMAGE_OWNER" = 0 ]
}

# use sudo when running in the CI otherwise the following error occurs
# regardless of the owner of the file and folder.
# xz: Cannot set the file group: Operation not permitted
if ! test_xz; then
if requires_sudo; then
echo "xz test file returned a warning, so compressing using sudo" >&2
SUDO=sudo
fi
Expand Down

0 comments on commit fc352e4

Please sign in to comment.