busybox/Dockerfile

103 lines
3.1 KiB
Docker
Raw Normal View History

FROM frebib/debian-builder as builder
2017-05-10 20:55:40 +00:00
2017-05-11 21:15:10 +00:00
ARG ARCH=x86_64
2017-08-09 18:44:55 +00:00
ARG ARCH_ALT=i686
2017-05-10 20:55:40 +00:00
2017-08-02 21:02:14 +00:00
ARG GLIBC_VER=2.26
2017-08-21 12:25:11 +00:00
ARG BUSYB_VER=1.27.2
2017-05-12 00:30:49 +00:00
ARG SU_EXEC_VER=v0.2
2017-09-19 17:43:56 +00:00
ARG TINI_VER=v0.16.1
2017-05-12 00:30:49 +00:00
ARG PREFIX=/output
WORKDIR $PREFIX
2017-05-11 09:36:22 +00:00
#Set up our dependencies, configure the output filesystem a bit
RUN mkdir -p dev etc home proc root tmp usr/{bin,lib,lib32} var && \
# Set up directories in a very confusing but very worky way
ln -sv usr/lib lib64 && \
ln -sv usr/lib lib && \
ln -sv usr/bin bin && \
ln -sv usr/bin sbin && \
ln -sv bin usr/sbin
# Pull tini and su-exec utilities
2017-08-09 20:39:40 +00:00
RUN curl -fL https://github.com/javabean/su-exec/releases/download/${SU_EXEC_VER}/su-exec.amd64 > sbin/su-exec && \
curl -fL https://github.com/krallin/tini/releases/download/${TINI_VER}/tini-amd64 > sbin/tini && \
chmod +x sbin/su-exec sbin/tini
2017-05-11 23:34:57 +00:00
WORKDIR /tmp/glibc/build
2017-05-10 20:55:40 +00:00
# Download and build glibc from source
RUN curl -fL https://ftp.gnu.org/gnu/glibc/glibc-${GLIBC_VER}.tar.xz \
| tar xJ --strip-components=1 -C .. && \
2017-08-09 20:29:31 +00:00
\
2017-08-16 16:43:37 +00:00
echo "slibdir=/usr/lib" >> configparms && \
echo "rtlddir=/usr/lib" >> configparms && \
echo "sbindir=/bin" >> configparms && \
echo "rootsbindir=/sbin" >> configparms && \
echo "build-programs=yes" >> configparms && \
2017-08-09 20:29:31 +00:00
\
../configure \
2017-08-16 16:43:37 +00:00
--prefix=/usr \
--libdir=/usr/lib \
--libexecdir=/usr/lib \
--enable-add-ons \
--enable-obsolete-rpc \
--enable-kernel=3.10.0 \
--enable-bind-now \
--disable-profile \
--enable-stackguard-randomization \
--enable-stack-protector=strong \
--enable-lock-elision \
--enable-multi-arch \
--disable-werror && \
make -j "$(nproc)" && \
make -j "$(nproc)" install_root="$(pwd)/out" install
2017-08-16 16:43:37 +00:00
RUN strip -s out/sbin/ldconfig && \
# Patch ldd to use sh not bash
2017-08-16 16:43:37 +00:00
sed -i '1s/.*/#!\/bin\/sh/' out/usr/bin/ldd && \
sed -i 's/lib64/lib/g' out/usr/bin/ldd && \
2017-08-16 16:43:37 +00:00
# Copy glibc libs & loader
cp -d out/usr/lib/*.so* "${PREFIX}/usr/lib" && \
cp -d out/usr/bin/ldd "${PREFIX}/bin" && \
cp -d out/sbin/ldconfig "${PREFIX}/sbin" && \
\
2017-08-16 16:43:37 +00:00
echo /usr/lib32 > "${PREFIX}/etc/ld.so.conf"
WORKDIR /tmp/busybox
# Download and build busybox from source
2017-08-09 20:39:40 +00:00
RUN curl -fL https://busybox.net/downloads/busybox-${BUSYB_VER}.tar.bz2 \
2017-08-09 20:29:31 +00:00
| tar xj --strip-components=1 && \
# Use default configuration
make defconfig && \
make -j "$(nproc)" && \
2017-08-09 20:29:31 +00:00
cp busybox "${PREFIX}/bin" && \
# "Install" busybox, creating symlinks to all binaries it provides
2017-08-09 20:42:28 +00:00
./busybox --list-full | xargs -i ln -s /bin/busybox "${PREFIX}/{}"
2017-05-22 17:09:32 +00:00
WORKDIR $PREFIX
# Generate initial ld.so.cache so ELF binaries work.
# This is important otherwise everything will error with
# 'no such file or directory' when looking for libraries
2017-08-16 19:30:14 +00:00
RUN ${PREFIX}/sbin/ldconfig -r ${PREFIX} && \
# Copy UTC localtime to output
cp /usr/share/zoneinfo/Etc/UTC etc/
2017-05-11 21:15:10 +00:00
# =============
FROM scratch
2017-05-10 20:55:40 +00:00
WORKDIR /
2017-05-11 23:34:57 +00:00
COPY --from=builder /output/ /
2017-08-16 19:30:14 +00:00
# Add default skeleton configuration files
ADD skel/* /etc/
RUN chmod 1777 /tmp
2017-08-16 19:30:14 +00:00
ENV ENV="/etc/profile"
2017-08-16 00:55:47 +00:00
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
2017-08-09 13:21:09 +00:00
CMD ["/bin/sh"]