Skip to content

Commit cdb2eb0

Browse files
committed
Allow creating interactive build container
1 parent 5c18a0f commit cdb2eb0

File tree

7 files changed

+70
-37
lines changed

7 files changed

+70
-37
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
# make sure to collect artifacts in a separate directory
5353
# makes uploading easier
5454
mkdir -p out
55-
(cd out && ../build-with-docker.sh)
55+
(cd out && ../scripts/build-with-docker.sh)
5656
5757
- name: Sign
5858
env:
@@ -61,7 +61,7 @@ jobs:
6161
if: ${{ env.SIGNING_KEY != '' }}
6262
run: |
6363
find out
64-
./sign.sh out/runtime-*
64+
scripts/sign.sh out/runtime-*
6565
# copy pubkey so that it's included with the files uploaded to the release page
6666
cp signing-pubkey.asc out/
6767

Dockerfile

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,8 @@ RUN apk add --no-cache \
77
eudev-dev gettext-dev linux-headers meson \
88
zstd-dev zstd-static zlib-dev zlib-static # fuse3-dev fuse3-static fuse-static fuse-dev
99

10+
COPY scripts/install-dependencies.sh /tmp/scripts/install-dependencies.sh
1011
COPY patches/ /tmp/patches/
1112

1213
WORKDIR /tmp
13-
14-
RUN wget https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz && \
15-
echo "70589cfd5e1cff7ccd6ac91c86c01be340b227285c5e200baa284e401eea2ca0 fuse-3.15.0.tar.xz" | sha256sum -c && \
16-
tar xf fuse-3.*.tar.xz && \
17-
cd fuse-3*/ && \
18-
patch -p1 < /tmp/patches/libfuse/mount.c.diff && \
19-
mkdir build && \
20-
cd build && \
21-
meson setup --prefix=/usr .. && \
22-
meson configure --default-library static && \
23-
ninja -v install && \
24-
rm -r /tmp/fuse-*
25-
26-
# Minimize binary size
27-
ENV CFLAGS="-ffunction-sections -fdata-sections -Os"
28-
29-
RUN wget "https://github.com/vasi/squashfuse/archive/e51978c.tar.gz" && \
30-
echo "f544029ad30d8fbde4e4540c574b8cdc6d38b94df025a98d8551a9441f07d341 e51978c.tar.gz" | sha256sum -c && \
31-
tar xf e51978c.tar.gz && \
32-
cd squashfuse-*/ && \
33-
./autogen.sh && \
34-
./configure CFLAGS="${CFLAGS} -no-pie" LDFLAGS=-static && \
35-
make -j"$(nproc)" && \
36-
make install && \
37-
/usr/bin/install -c -m 644 ./*.h '/usr/local/include/squashfuse' && \
38-
rm -r /tmp/e51978c* /tmp/squashfuse*
14+
RUN bash scripts/install-dependencies.sh
File renamed without changes.

scripts/build-with-docker.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
3+
set -euo pipefail
4+
5+
orig_cwd="$(readlink -f .)"
6+
7+
this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"/
8+
9+
bash "$this_dir"/create-build-container.sh -u "$(id -u):$(id -g)" -- bash scripts/build-in-container.sh
10+
11+
# done!
12+
# you should now have the binary in your current working directory

build-with-docker.sh renamed to scripts/create-build-container.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ case "${ARCH}" in
2121
;;
2222
armhf)
2323
docker_arch=arm32v7
24-
docker_platform=linux/arm32/v7
24+
docker_platform=linux/arm/v7
2525
;;
2626
aarch64)
2727
docker_arch=arm64v8
@@ -37,16 +37,30 @@ image_name="$docker_arch"/type2-runtime-build
3737

3838
# first, we need to build the image
3939
# if nothing has changed, it'll run over this within a few seconds
40-
this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
41-
docker build --build-arg docker_arch="$docker_arch" --platform "$docker_platform" -t "$image_name" "$this_dir"
40+
repo_root_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)"/
41+
docker build --build-arg docker_arch="$docker_arch" --platform "$docker_platform" -t "$image_name" "$repo_root_dir"
4242

4343
docker_run_args=()
4444
[[ -t 0 ]] && docker_run_args+=("-t")
4545

46-
# next, build the binary in a container running this image
47-
# we run the build as an unprivileged user to a) make sure that the build process does not require root permissions and b) make the resulting binary writable to the current user
48-
set -x
49-
docker run -u "$(id -u):$(id -g)" --platform "$docker_platform" --rm -i "${docker_run_args[@]}" -w /ws -v "$this_dir":/ws -v "$orig_cwd":/ws/out "$image_name" bash build-in-container.sh
46+
# split Docker args from command
47+
while true; do
48+
# no more args left
49+
if [[ "${1:-}" == "" ]]; then
50+
break
51+
fi
52+
53+
# consume --, the remaining args will be in the $@ array
54+
if [[ "$1" == "--" ]]; then
55+
shift
56+
break
57+
fi
5058

51-
# done!
52-
# you should now have the binary in your current working directory
59+
# append and consume Docker arg
60+
docker_run_args+=("$1")
61+
shift
62+
done
63+
64+
# finally, we can run the build container
65+
# we run the build as an unprivileged user to a) make sure that the build process does not require root permissions and b) make the resulting binary writable to the current user
66+
exec docker run -u "$(id -u):$(id -g)" --platform "$docker_platform" --rm -i "${docker_run_args[@]}" -w /ws -v "$repo_root_dir":/ws -v "$orig_cwd":/ws/out "$image_name" "$@"

scripts/install-dependencies.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /bin/bash
2+
3+
set -euo pipefail
4+
5+
wget https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz
6+
echo "70589cfd5e1cff7ccd6ac91c86c01be340b227285c5e200baa284e401eea2ca0 fuse-3.15.0.tar.xz" | sha256sum -c -
7+
tar xf fuse-3.*.tar.xz
8+
pushd fuse-3*/
9+
patch -p1 < /tmp/patches/libfuse/mount.c.diff
10+
mkdir build
11+
cd build
12+
meson setup --prefix=/usr ..
13+
meson configure --default-library static
14+
ninja -v install
15+
popd
16+
rm -r fuse-*
17+
18+
# Minimize binary size
19+
export CFLAGS="-ffunction-sections -fdata-sections -Os"
20+
21+
wget "https://github.com/vasi/squashfuse/archive/e51978c.tar.gz"
22+
echo "f544029ad30d8fbde4e4540c574b8cdc6d38b94df025a98d8551a9441f07d341 e51978c.tar.gz" | sha256sum -c -
23+
tar xf e51978c.tar.gz
24+
pushd squashfuse-*/
25+
./autogen.sh
26+
./configure CFLAGS="${CFLAGS} -no-pie" LDFLAGS=-static
27+
make -j"$(nproc)"
28+
make install
29+
/usr/bin/install -c -m 644 ./*.h '/usr/local/include/squashfuse'
30+
popd
31+
rm -r e51978c* squashfuse*
File renamed without changes.

0 commit comments

Comments
 (0)