Skip to content

Commit

Permalink
Cross-compile BusyBox
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Oct 17, 2023
1 parent c32537b commit 8bf149c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/base-glibc-busybox-bash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ jobs:
buildah manifest create "${image_name}:${tag}"
done
iidfile="$( mktemp )"
buildah bud \
--iidfile="${iidfile}" \
--build-arg=busybox_version='${{ env.BUSYBOX_VERSION }}' \
--file=Dockerfile.busybox
busybox_image="$( cat "${iidfile}" )"
rm "${iidfile}"
for arch in amd64 arm64 ; do
iidfile="$( mktemp )"
buildah bud --layers \
--arch="${arch}" \
--iidfile="${iidfile}" \
--build-arg=busybox_version='${{ env.BUSYBOX_VERSION }}' \
--build-arg=busybox_image="${busybox_image}" \
--build-arg=debian_version='${{ env.DEBIAN_VERSION }}'
image_id="$( cat "${iidfile}" )"
rm "${iidfile}"
Expand Down
30 changes: 7 additions & 23 deletions images/base-glibc-busybox-bash/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,16 @@ RUN [ ! -f /etc/apt/sources.list ] || sed --in-place= --regexp-extended \
/etc/apt/sources.list


# Build busybox ourselves to have more fine-grained control over what we want
# (or not want) to include.
# Use old Debian version to ensure compatible (low glibc requirement) binaries.
FROM debian:9-slim AS busybox_builder
RUN [ ! -f /etc/apt/sources.list ] || sed --in-place= --regexp-extended \
'/ stretch/ { s,-updates,-backports, ; s,/(deb|security)\.,/archive., }' \
/etc/apt/sources.list \
&& \
apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install --yes --no-install-recommends \
bzip2 curl ca-certificates tar gcc libc6-dev make patch

WORKDIR /build
COPY build-busybox ./
ARG busybox_version
RUN ./build-busybox "${busybox_version}"
FROM build_base AS rootfs_builder

ARG busybox_image
COPY --from="${busybox_image}" /build /build
WORKDIR /busybox-rootfs
RUN mkdir -p ./bin ./sbin ./usr/bin ./usr/sbin \
RUN arch="$( uname -m )" \
&& \
mkdir -p ./bin ./sbin ./usr/bin ./usr/sbin \
&& \
cp -al /build/busybox ./bin/ \
cp -al "/build/busybox.${arch}" ./bin/busybox \
&& \
ldd ./bin/busybox \
| grep --only-matching --extended-regexp '/lib\S+' \
Expand All @@ -41,10 +29,6 @@ RUN mkdir -p ./bin ./sbin ./usr/bin ./usr/sbin \
&& \
rm -rf ./lib*


FROM build_base AS rootfs_builder

COPY --from=busybox_builder /busybox-rootfs /busybox-rootfs
WORKDIR /rootfs

RUN mkdir -p ./etc ./home ./opt ./root ./run /tmp ./usr ./var/log \
Expand Down
23 changes: 23 additions & 0 deletions images/base-glibc-busybox-bash/Dockerfile.busybox
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Build busybox ourselves to have more fine-grained control over what we want
# (or not want) to include.
# Use old Debian version to ensure compatible (low glibc requirement) binaries.
FROM debian:9-slim AS busybox_builder
RUN [ ! -f /etc/apt/sources.list ] || sed --in-place= --regexp-extended \
'/ stretch/ { s,-updates,-backports, ; s,/(deb|security)\.,/archive., }' \
/etc/apt/sources.list \
&& \
apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install --yes --no-install-recommends \
bzip2 curl ca-certificates tar \
gcc libc6-dev \
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
make patch

WORKDIR /build
COPY build-busybox ./
ARG busybox_version
RUN ./build-busybox \
"${busybox_version}" \
x86_64 aarch64

10 changes: 8 additions & 2 deletions images/base-glibc-busybox-bash/build-busybox
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ build() {

main() {
version="${1}"
shift
download
patch
config
build
for target ; do
export MAKEFLAGS="ARCH=${target} CROSS_COMPILE=${target}-linux-gnu-"
make clean
config
build
cp -al ./busybox "./busybox.${target}"
done
}

main "${@}"

0 comments on commit 8bf149c

Please sign in to comment.