2018-03-17 22:04:12 +00:00
|
|
|
# Pre-define ARGs to ensure correct scope
|
2018-08-02 09:06:38 +00:00
|
|
|
ARG GLIBC_VER=2.28
|
2018-08-19 23:51:46 +00:00
|
|
|
ARG BUSYB_VER=1.29.2
|
2018-07-09 14:40:33 +00:00
|
|
|
ARG SU_EXEC_VER=0.3
|
|
|
|
ARG TINI_VER=0.18.0
|
2018-03-17 22:04:12 +00:00
|
|
|
|
2018-03-16 16:11:54 +00:00
|
|
|
FROM spritsail/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
|
|
|
|
2018-03-17 22:04:12 +00:00
|
|
|
ARG GLIBC_VER
|
|
|
|
ARG BUSYB_VER
|
|
|
|
ARG SU_EXEC_VER
|
|
|
|
ARG TINI_VER
|
2017-05-12 00:30:49 +00:00
|
|
|
|
2017-05-22 16:06:05 +00:00
|
|
|
ARG PREFIX=/output
|
|
|
|
WORKDIR $PREFIX
|
2017-05-11 09:36:22 +00:00
|
|
|
|
2017-05-11 22:37:11 +00:00
|
|
|
#Set up our dependencies, configure the output filesystem a bit
|
2017-09-20 11:32:21 +00:00
|
|
|
RUN mkdir -p dev etc home proc root tmp usr/{bin,lib/pkgconfig,lib32} var && \
|
2017-08-16 00:39:57 +00:00
|
|
|
# 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
|
2017-05-11 22:37:11 +00:00
|
|
|
|
2017-08-15 20:54:36 +00:00
|
|
|
WORKDIR /tmp/glibc/build
|
2017-05-10 20:55:40 +00:00
|
|
|
|
2017-05-12 10:50:24 +00:00
|
|
|
# Download and build glibc from source
|
2018-02-04 22:10:40 +00:00
|
|
|
RUN apt install -y bison && \
|
|
|
|
curl -fL https://ftp.gnu.org/gnu/glibc/glibc-${GLIBC_VER}.tar.xz \
|
2017-08-15 20:54:36 +00:00
|
|
|
| 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 && \
|
2017-05-12 10:50:24 +00:00
|
|
|
echo "sbindir=/bin" >> configparms && \
|
2017-08-15 20:54:36 +00:00
|
|
|
echo "rootsbindir=/sbin" >> configparms && \
|
|
|
|
echo "build-programs=yes" >> configparms && \
|
2017-08-09 20:29:31 +00:00
|
|
|
\
|
2017-08-15 20:54:36 +00:00
|
|
|
../configure \
|
2017-08-16 16:43:37 +00:00
|
|
|
--prefix=/usr \
|
|
|
|
--libdir=/usr/lib \
|
|
|
|
--libexecdir=/usr/lib \
|
2017-05-12 10:50:24 +00:00
|
|
|
--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 && \
|
2017-08-09 20:42:08 +00:00
|
|
|
make -j "$(nproc)" && \
|
2017-08-15 20:54:36 +00:00
|
|
|
make -j "$(nproc)" install_root="$(pwd)/out" install
|
2017-05-12 10:50:24 +00:00
|
|
|
|
2017-08-16 16:43:37 +00:00
|
|
|
RUN strip -s out/sbin/ldconfig && \
|
2017-08-15 20:54:36 +00:00
|
|
|
# Patch ldd to use sh not bash
|
2017-08-16 16:43:37 +00:00
|
|
|
sed -i '1s/.*/#!\/bin\/sh/' out/usr/bin/ldd && \
|
2017-09-08 23:18:24 +00:00
|
|
|
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" && \
|
2017-08-15 20:54:36 +00:00
|
|
|
cp -d out/sbin/ldconfig "${PREFIX}/sbin" && \
|
|
|
|
\
|
2017-08-16 16:43:37 +00:00
|
|
|
echo /usr/lib32 > "${PREFIX}/etc/ld.so.conf"
|
2017-05-12 10:50:24 +00:00
|
|
|
|
2017-08-09 20:16:39 +00:00
|
|
|
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 && \
|
2018-09-05 12:41:21 +00:00
|
|
|
# Use minimal configuration for standalone applets
|
|
|
|
make allnoconfig && \
|
|
|
|
sed -i -e 's/# CONFIG_PING is not set/CONFIG_PING=y/' \
|
|
|
|
-e 's/# CONFIG_FEATURE_FANCY_PING is not set/CONFIG_FEATURE_FANCY_PING=y/' \
|
|
|
|
-e 's/# CONFIG_SU is not set/CONFIG_SU=y/' \
|
|
|
|
.config && \
|
|
|
|
# Build ping and su
|
|
|
|
./make_single_applets.sh && \
|
|
|
|
cp busybox_PING "${PREFIX}/bin/ping" && \
|
|
|
|
cp busybox_SU "${PREFIX}/bin/su" && \
|
|
|
|
\
|
2017-08-09 20:29:31 +00:00
|
|
|
# Use default configuration
|
|
|
|
make defconfig && \
|
2018-09-05 12:41:21 +00:00
|
|
|
# Disable `busybox --install` function
|
|
|
|
sed -i -e 's/CONFIG_INSTALLER=y/# CONFIG_INSTALLER is not set/' \
|
|
|
|
-e 's/CONFIG_PING=y/# CONFIG_PING is not set/' \
|
|
|
|
-e 's/CONFIG_SU=y/# CONFIG_SU is not set/' \
|
|
|
|
.config && \
|
|
|
|
\
|
2017-08-09 20:42:08 +00:00
|
|
|
make -j "$(nproc)" && \
|
2017-08-09 20:29:31 +00:00
|
|
|
cp busybox "${PREFIX}/bin" && \
|
2017-08-09 20:16:39 +00:00
|
|
|
# "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-08-09 20:16:39 +00:00
|
|
|
|
2018-08-31 15:31:25 +00:00
|
|
|
WORKDIR /tmp/su-exec
|
|
|
|
|
|
|
|
# Download and build su-exec from source
|
|
|
|
RUN apt-get -y install xxd
|
|
|
|
RUN curl -fL https://github.com/frebib/su-exec/archive/v${SU_EXEC_VER}.tar.gz \
|
|
|
|
| tar xz --strip-components=1 && \
|
|
|
|
make && \
|
|
|
|
strip -s su-exec && \
|
|
|
|
mv su-exec "${PREFIX}/sbin"
|
|
|
|
|
|
|
|
WORKDIR /tmp/tini
|
|
|
|
|
|
|
|
# Download and build tini from source
|
|
|
|
ADD tini-gnudef.patch /tmp
|
|
|
|
RUN curl -fL https://github.com/krallin/tini/archive/v${TINI_VER}.tar.gz \
|
|
|
|
| tar xz --strip-components=1 && \
|
|
|
|
patch -p1 < /tmp/tini-gnudef.patch && \
|
|
|
|
cmake . && \
|
|
|
|
make tini && \
|
|
|
|
mv tini "${PREFIX}/sbin"
|
|
|
|
|
2017-05-22 17:09:32 +00:00
|
|
|
WORKDIR $PREFIX
|
|
|
|
|
2017-08-15 22:14:46 +00:00
|
|
|
# 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-08-15 22:14:46 +00:00
|
|
|
|
2018-09-04 18:09:16 +00:00
|
|
|
# Add default skeleton configuration files
|
|
|
|
COPY skel/ .
|
|
|
|
RUN install -dm 1777 tmp && \
|
2018-09-05 12:41:21 +00:00
|
|
|
chroot . chmod 755 usr/bin/* sbin/* && \
|
|
|
|
# Ensure ping and su have correct permissions
|
|
|
|
chroot . chmod 4755 usr/bin/ping usr/bin/su
|
2018-09-04 18:09:16 +00:00
|
|
|
|
2017-05-11 21:15:10 +00:00
|
|
|
# =============
|
|
|
|
|
|
|
|
FROM scratch
|
2018-03-17 22:04:12 +00:00
|
|
|
|
|
|
|
ARG BUSYB_VER
|
|
|
|
ARG GLIBC_VER
|
2018-03-26 14:56:13 +00:00
|
|
|
ARG SU_EXEC_VER
|
|
|
|
ARG TINI_VER
|
2018-03-17 22:04:12 +00:00
|
|
|
|
|
|
|
LABEL maintainer="Spritsail <busybox@spritsail.io>" \
|
|
|
|
org.label-schema.vendor="Spritsail" \
|
|
|
|
org.label-schema.name="Busybox" \
|
|
|
|
org.label-schema.url="https://github.com/spritsail/busybox" \
|
|
|
|
org.label-schema.description="Busybox and GNU libc built from source" \
|
2018-03-26 14:56:13 +00:00
|
|
|
org.label-schema.version=${BUSYB_VER}/${GLIBC_VER} \
|
|
|
|
io.spritsail.version.busybox=${BUSYB_VER} \
|
|
|
|
io.spritsail.version.glibc=${GLIBC_VER} \
|
|
|
|
io.spritsail.version.su-exec=${SU_EXEC_VER} \
|
|
|
|
io.spritsail.version.tini=${TINI_VER}
|
2018-03-17 22:04:12 +00:00
|
|
|
|
2017-05-10 20:55:40 +00:00
|
|
|
WORKDIR /
|
2017-08-09 13:06:52 +00:00
|
|
|
|
2018-04-17 13:19:46 +00:00
|
|
|
SHELL ["/bin/sh", "-exc"]
|
|
|
|
|
2017-05-11 23:34:57 +00:00
|
|
|
COPY --from=builder /output/ /
|
2018-09-05 12:41:21 +00:00
|
|
|
# Workaround for Docker bug (not retaining setuid bit)
|
2018-09-12 11:33:50 +00:00
|
|
|
# https://github.com/moby/moby/issues/37830
|
2018-09-05 12:41:21 +00:00
|
|
|
RUN chmod 4755 usr/bin/ping usr/bin/su
|
2018-02-05 21:10:26 +00:00
|
|
|
|
2017-08-16 19:30:14 +00:00
|
|
|
ENV ENV="/etc/profile"
|
2018-07-09 12:14:35 +00:00
|
|
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
|
2017-08-16 00:55:47 +00:00
|
|
|
|
2018-04-17 13:19:46 +00:00
|
|
|
ENTRYPOINT ["/sbin/tini" , "--"]
|
2017-08-09 13:21:09 +00:00
|
|
|
CMD ["/bin/sh"]
|