Change variants to be libc variants instead of build-style variants

This commit is contained in:
Tianon Gravi 2016-01-07 10:46:41 -08:00
parent 3bf655587b
commit 6b303c84f0
13 changed files with 304 additions and 100 deletions

View File

@ -2,8 +2,9 @@ language: bash
services: docker services: docker
env: env:
- VERSION=ubuntu - VERSION=glibc
- VERSION=upstream - VERSION=musl
- VERSION=uclibc
install: install:
- git clone https://github.com/docker-library/official-images.git ~/official-images - git clone https://github.com/docker-library/official-images.git ~/official-images
@ -13,7 +14,7 @@ before_script:
- image="busybox:$VERSION" - image="busybox:$VERSION"
script: script:
- "./build-$VERSION.sh" - ./build.sh "$VERSION"
- ~/official-images/test/run.sh "$image" - ~/official-images/test/run.sh "$image"
after_script: after_script:

View File

@ -1,11 +0,0 @@
#!/bin/bash
set -e
cd "$(readlink -f "$(dirname "$BASH_SOURCE")")/ubuntu"
set -x
docker build -t busybox:ubuntu-builder --pull - < Dockerfile.builder
docker run --rm busybox:ubuntu-builder tar c . | xz -z9 > busybox.tar.xz
docker build -t busybox:ubuntu .
docker run --rm busybox:ubuntu sh -xec 'true'
docker run --rm busybox:ubuntu ping -c 1 google.com

View File

@ -1,11 +0,0 @@
#!/bin/bash
set -e
cd "$(readlink -f "$(dirname "$BASH_SOURCE")")/upstream"
set -x
docker build -t busybox:upstream-builder --pull - < Dockerfile.builder
docker run --rm busybox:upstream-builder tar cC rootfs . | xz -z9 > busybox.tar.xz
docker build -t busybox:upstream .
docker run --rm busybox:upstream sh -xec 'true'
docker run --rm busybox:upstream ping -c 1 google.com

22
build.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
cd "$(readlink -f "$(dirname "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
base='busybox:'
for version in "${versions[@]}"; do
(
set -x
docker build -t "$base$version-builder" --pull -f "$version/Dockerfile.builder" "$version"
docker run --rm "$base$version-builder" tar cC rootfs . | xz -z9 > "$version/busybox.tar.xz"
docker build -t "$base$version" "$version"
docker run --rm "$base$version" sh -xec 'true'
docker run --rm "$base$version" ping -c 1 google.com
)
done

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
set -e set -e
latest='uclibc'
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( */ ) versions=( */ )
@ -16,18 +18,24 @@ for version in "${versions[@]}"; do
fullVersion="${fullVersion#*:}" fullVersion="${fullVersion#*:}"
fullVersion="${fullVersion%-*}" fullVersion="${fullVersion%-*}"
verSuffix="$version" suffix="-$version"
if [ "$version" = 'upstream' ]; then
verSuffix=''
fi
suffix="${verSuffix:+-$verSuffix}"
versionAliases=() versionAliases=()
while [ "${fullVersion%.*}" != "$fullVersion" ]; do while [ "${fullVersion%.*}" != "$fullVersion" ]; do
versionAliases+=( $fullVersion$suffix ) versionAliases+=( $fullVersion$suffix )
if [ "$version" = "$latest" ]; then
versionAliases+=( $fullVersion )
fi
fullVersion="${fullVersion%.*}" fullVersion="${fullVersion%.*}"
done done
versionAliases+=( $fullVersion$suffix ${verSuffix:-latest} ) versionAliases+=( $fullVersion$suffix )
if [ "$version" = "$latest" ]; then
versionAliases+=( $fullVersion )
fi
versionAliases+=( $version )
if [ "$version" = "$latest" ]; then
versionAliases+=( latest )
fi
echo echo
for va in "${versionAliases[@]}"; do for va in "${versionAliases[@]}"; do

127
glibc/Dockerfile.builder Normal file
View File

@ -0,0 +1,127 @@
FROM debian:jessie
RUN apt-get update && apt-get install -y \
bzip2 \
curl \
gcc \
make \
&& rm -rf /var/lib/apt/lists/*
# pub 1024D/ACC9965B 2006-12-12
# Key fingerprint = C9E9 416F 76E6 10DB D09D 040F 47B7 0C55 ACC9 965B
# uid Denis Vlasenko <vda.linux@googlemail.com>
# sub 1024g/2C766641 2006-12-12
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys C9E9416F76E610DBD09D040F47B70C55ACC9965B
ENV BUSYBOX_VERSION 1.24.1
RUN set -x \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2" -o busybox.tar.bz2 \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2.sign" -o busybox.tar.bz2.sign \
&& gpg --verify busybox.tar.bz2.sign \
&& tar -xjf busybox.tar.bz2 \
&& mkdir -p /usr/src \
&& mv "busybox-${BUSYBOX_VERSION}" /usr/src/busybox \
&& rm busybox.tar.bz2*
WORKDIR /usr/src/busybox
# TODO remove CONFIG_FEATURE_SYNC_FANCY from this explicit list after the next release of busybox (since it's disabled by default upstream now)
# As long as we rely on libnss, we have to have libc.so anyhow, so
# we've removed CONFIG_STATIC here for now... :cry:
RUN yConfs=' \
CONFIG_AR \
CONFIG_FEATURE_AR_LONG_FILENAMES \
CONFIG_FEATURE_AR_CREATE \
' \
&& nConfs=' \
CONFIG_FEATURE_SYNC_FANCY \
' \
&& set -xe \
&& make defconfig \
&& for conf in $nConfs; do \
sed -i "s!^$conf=y!# $conf is not set!" .config; \
done \
&& for conf in $yConfs; do \
sed -i "s!^# $conf is not set\$!$conf=y!" .config; \
grep -q "^$conf=y" .config || echo "$conf=y" >> .config; \
done \
&& make oldconfig \
&& for conf in $nConfs; do \
! grep -q "^$conf=y" .config; \
done \
&& for conf in $yConfs; do \
grep -q "^$conf=y" .config; \
done
# hack hack hack hack hack
# with glibc, static busybox uses libnss for DNS resolution :(
RUN set -x \
&& make -j$(nproc) \
busybox \
&& ./busybox --help \
&& mkdir -p rootfs/bin \
&& ln -vL busybox rootfs/bin/ \
\
&& ln -vL "$(which getconf)" rootfs/bin/getconf \
&& mkdir -p rootfs/etc \
&& cp /etc/nsswitch.conf rootfs/etc/ \
&& mkdir -p rootfs/lib \
&& ln -sT lib rootfs/lib64 \
&& set -- \
rootfs/bin/busybox \
rootfs/bin/getconf \
/lib/"$(gcc -print-multiarch)"/libnss*.so.* \
&& while [ "$#" -gt 0 ]; do \
f="$1"; shift; \
fn="$(basename "$f")"; \
if [ -e "rootfs/lib/$fn" ]; then continue; fi; \
if [ "${f#rootfs/}" = "$f" ]; then \
if [ "${fn#ld-}" = "$fn" ]; then \
ln -vL "$f" "rootfs/lib/$fn"; \
else \
cp -v "$f" "rootfs/lib/$fn"; \
fi; \
fi; \
set -- "$@" $(ldd "$f" | awk ' \
$1 ~ /^\// { print $1; next } \
$2 == "=>" && $3 ~ /^\// { print $3; next } \
'); \
done \
&& chroot rootfs /bin/getconf _NPROCESSORS_ONLN \
\
&& chroot rootfs /bin/busybox --install /bin
RUN set -ex \
&& buildrootVersion='2015.11.1' \
&& mkdir -p rootfs/etc \
&& for f in passwd shadow group; do \
curl -fSL \
"http://git.busybox.net/buildroot/plain/system/skeleton/etc/$f?id=$buildrootVersion" \
-o "rootfs/etc/$f"; \
done
# create /tmp
RUN mkdir -p rootfs/tmp \
&& chmod 1777 rootfs/tmp
# create missing home directories
RUN set -ex \
&& cd rootfs \
&& for userHome in $(awk -F ':' '{ print $3 ":" $4 "=" $6 }' etc/passwd); do \
user="${userHome%%=*}"; \
home="${userHome#*=}"; \
home="./${home#/}"; \
if [ ! -d "$home" ]; then \
mkdir -p "$home"; \
chown "$user" "$home"; \
fi; \
done
# test and make sure it works
RUN chroot rootfs /bin/sh -xec 'true'
# test and make sure DNS works too
RUN cp -L /etc/resolv.conf rootfs/etc/ \
&& chroot rootfs /bin/sh -xec 'nslookup google.com' \
&& rm rootfs/etc/resolv.conf

114
musl/Dockerfile.builder Normal file
View File

@ -0,0 +1,114 @@
FROM alpine:3.3
RUN apk add --no-cache \
bzip2 \
curl \
gcc \
make \
\
gnupg \
linux-headers \
musl-dev
# pub 1024D/ACC9965B 2006-12-12
# Key fingerprint = C9E9 416F 76E6 10DB D09D 040F 47B7 0C55 ACC9 965B
# uid Denis Vlasenko <vda.linux@googlemail.com>
# sub 1024g/2C766641 2006-12-12
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys C9E9416F76E610DBD09D040F47B70C55ACC9965B
ENV BUSYBOX_VERSION 1.24.1
RUN set -x \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2" -o busybox.tar.bz2 \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2.sign" -o busybox.tar.bz2.sign \
&& gpg --verify busybox.tar.bz2.sign \
&& tar -xjf busybox.tar.bz2 \
&& mkdir -p /usr/src \
&& mv "busybox-${BUSYBOX_VERSION}" /usr/src/busybox \
&& rm busybox.tar.bz2*
WORKDIR /usr/src/busybox
# see http://wiki.musl-libc.org/wiki/Building_Busybox
# TODO remove CONFIG_FEATURE_SYNC_FANCY from this explicit list after the next release of busybox (since it's disabled by default upstream now)
RUN yConfs=' \
CONFIG_AR \
CONFIG_FEATURE_AR_LONG_FILENAMES \
CONFIG_FEATURE_AR_CREATE \
CONFIG_STATIC \
' \
&& nConfs=' \
CONFIG_FEATURE_SYNC_FANCY \
\
CONFIG_FEATURE_HAVE_RPC \
CONFIG_FEATURE_INETD_RPC \
CONFIG_FEATURE_UTMP \
CONFIG_FEATURE_WTMP \
' \
&& set -xe \
&& make defconfig \
&& for conf in $nConfs; do \
sed -i "s!^$conf=y!# $conf is not set!" .config; \
done \
&& for conf in $yConfs; do \
sed -i "s!^# $conf is not set\$!$conf=y!" .config; \
grep -q "^$conf=y" .config || echo "$conf=y" >> .config; \
done \
&& make oldconfig \
&& for conf in $nConfs; do \
! grep -q "^$conf=y" .config; \
done \
&& for conf in $yConfs; do \
grep -q "^$conf=y" .config; \
done
RUN set -x \
&& make -j$(getconf _NPROCESSORS_ONLN) \
busybox \
&& ./busybox --help \
&& mkdir -p rootfs/bin \
&& ln -v busybox rootfs/bin/ \
&& chroot rootfs /bin/busybox --install /bin
# grab a simplified getconf port from Alpine we can statically compile
RUN set -x \
&& aportsVersion="v$(cat /etc/alpine-release)" \
&& curl -fsSL \
"http://git.alpinelinux.org/cgit/aports/plain/main/musl/getconf.c?h=${aportsVersion}" \
-o /usr/src/getconf.c \
&& gcc -o rootfs/bin/getconf -static -Os /usr/src/getconf.c \
&& chroot rootfs /bin/sh -xec 'getconf _NPROCESSORS_ONLN'
RUN set -ex \
&& buildrootVersion='2015.11.1' \
&& mkdir -p rootfs/etc \
&& for f in passwd shadow group; do \
curl -fSL \
"http://git.busybox.net/buildroot/plain/system/skeleton/etc/$f?id=$buildrootVersion" \
-o "rootfs/etc/$f"; \
done
# create /tmp
RUN mkdir -p rootfs/tmp \
&& chmod 1777 rootfs/tmp
# create missing home directories
RUN set -ex \
&& cd rootfs \
&& for userHome in $(awk -F ':' '{ print $3 ":" $4 "=" $6 }' etc/passwd); do \
user="${userHome%%=*}"; \
home="${userHome#*=}"; \
home="./${home#/}"; \
if [ ! -d "$home" ]; then \
mkdir -p "$home"; \
chown "$user" "$home"; \
fi; \
done
# test and make sure it works
RUN chroot rootfs /bin/sh -xec 'true'
# test and make sure DNS works too
RUN cp -L /etc/resolv.conf rootfs/etc/ \
&& chroot rootfs /bin/sh -xec 'nslookup google.com' \
&& rm rootfs/etc/resolv.conf

View File

@ -1,46 +0,0 @@
FROM ubuntu:trusty
ENV BUSYBOX_VERSION 1:1.21.0-1ubuntu1
RUN apt-get update && apt-get install -y --no-install-recommends \
busybox-static=$BUSYBOX_VERSION \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /rootfs
# create /tmp
RUN mkdir -p tmp \
&& chmod 1777 tmp
RUN mkdir -p etc root \
&& echo root:*:0:0:root:/root:/bin/sh > etc/passwd \
&& echo root::0: > etc/group
RUN mkdir -p bin \
&& ln -v /bin/busybox bin/ \
&& chroot . /bin/busybox --install -s /bin
# test and make sure it works
RUN chroot . /bin/sh -xec 'true'
# hack hack hack hack hack
# with glibc, static busybox uses libnss for DNS resolution :(
RUN set -ex \
&& cp /etc/nsswitch.conf etc/ \
&& mkdir -p lib \
&& set -- /lib/*-linux-gnu/libnss*.so.* \
&& while [ "$#" -gt 0 ]; do \
f="$1"; shift; \
fn="$(basename "$f")"; \
if [ -e "lib/$fn" ]; then continue; fi; \
ln -L "$f" "lib/$fn"; \
set -- "$@" $(ldd "$f" | awk ' \
$1 ~ /^\// { print $1; next } \
$2 == "=>" && $3 ~ /^\// { print $3; next } \
'); \
done
# test and make sure DNS works too
RUN cp -L /etc/resolv.conf etc/ \
&& chroot . /bin/sh -xec 'nslookup google.com' \
&& rm etc/resolv.conf

3
uclibc/Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM scratch
ADD busybox.tar.xz /
CMD ["sh"]

View File

@ -76,17 +76,19 @@ ENV PATH /usr/src/buildroot/output/host/usr/bin:$PATH
# sub 1024g/2C766641 2006-12-12 # sub 1024g/2C766641 2006-12-12
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys C9E9416F76E610DBD09D040F47B70C55ACC9965B RUN gpg --keyserver pool.sks-keyservers.net --recv-keys C9E9416F76E610DBD09D040F47B70C55ACC9965B
WORKDIR /usr/src/busybox
ENV BUSYBOX_VERSION 1.24.1 ENV BUSYBOX_VERSION 1.24.1
RUN set -x \ RUN set -x \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2" -o busybox.tar.bz2 \ && curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2" -o busybox.tar.bz2 \
&& curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2.sign" -o busybox.tar.bz2.sign \ && curl -fsSL "http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2.sign" -o busybox.tar.bz2.sign \
&& gpg --verify busybox.tar.bz2.sign \ && gpg --verify busybox.tar.bz2.sign \
&& tar -xf busybox.tar.bz2 --strip-components 1 \ && tar -xjf busybox.tar.bz2 \
&& mkdir -p /usr/src \
&& mv "busybox-${BUSYBOX_VERSION}" /usr/src/busybox \
&& rm busybox.tar.bz2* && rm busybox.tar.bz2*
WORKDIR /usr/src/busybox
# TODO remove CONFIG_FEATURE_SYNC_FANCY from this explicit list after the next release of busybox (since it's disabled by default upstream now) # TODO remove CONFIG_FEATURE_SYNC_FANCY from this explicit list after the next release of busybox (since it's disabled by default upstream now)
RUN yConfs=' \ RUN yConfs=' \
CONFIG_AR \ CONFIG_AR \
@ -118,19 +120,21 @@ RUN set -x \
&& make -j$(nproc) \ && make -j$(nproc) \
CROSS_COMPILE="$(basename /usr/src/buildroot/output/host/usr/*-buildroot-linux-uclibc)-" \ CROSS_COMPILE="$(basename /usr/src/buildroot/output/host/usr/*-buildroot-linux-uclibc)-" \
busybox \ busybox \
&& ./busybox --help \
&& mkdir -p rootfs/bin \ && mkdir -p rootfs/bin \
&& ln -v busybox rootfs/bin/ \ && ln -vL busybox rootfs/bin/ \
\
&& ln -vL ../buildroot/output/target/usr/bin/getconf rootfs/bin/ \
\
&& chroot rootfs /bin/busybox --install /bin && chroot rootfs /bin/busybox --install /bin
# install "getconf" from buildroot (which is compiled statically already) RUN set -ex \
RUN ln -v ../buildroot/output/target/usr/bin/getconf rootfs/bin/ && mkdir -p rootfs/etc \
&& for f in passwd shadow group; do \
RUN mkdir -p rootfs/etc \ ln -vL \
&& ln -v \ "../buildroot/system/skeleton/etc/$f" \
/usr/src/buildroot/system/skeleton/etc/passwd \ "rootfs/etc/$f"; \
/usr/src/buildroot/system/skeleton/etc/shadow \ done
/usr/src/buildroot/system/skeleton/etc/group \
rootfs/etc/
# create /tmp # create /tmp
RUN mkdir -p rootfs/tmp \ RUN mkdir -p rootfs/tmp \
@ -151,6 +155,7 @@ RUN set -ex \
# test and make sure it works # test and make sure it works
RUN chroot rootfs /bin/sh -xec 'true' RUN chroot rootfs /bin/sh -xec 'true'
# test and make sure DNS works too # test and make sure DNS works too
RUN cp -L /etc/resolv.conf rootfs/etc/ \ RUN cp -L /etc/resolv.conf rootfs/etc/ \
&& chroot rootfs /bin/sh -xec 'nslookup google.com' \ && chroot rootfs /bin/sh -xec 'nslookup google.com' \

View File

@ -3,15 +3,7 @@ set -eo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
upstreamVersion="$(curl -fsSL --compressed 'http://busybox.net/downloads/' | grep -E '<a href="busybox-[0-9][^"/]*.tar.bz2"' | sed -r 's!.*<a href="busybox-([0-9][^"/]*).tar.bz2".*!\1!' | sort -V | tail -1)" upstreamVersion="$(curl -fsSL --compressed 'https://busybox.net/downloads/' | grep -E '<a href="busybox-[0-9][^"/]*.tar.bz2"' | sed -r 's!.*<a href="busybox-([0-9][^"/]*).tar.bz2".*!\1!' | sort -V | tail -1)"
ubuntuImage="$(awk 'toupper($1) == "FROM" { print $2 }' ubuntu/Dockerfile.builder)"
ubuntuVersion="$(docker run --rm ubuntu:trusty bash -ec '
sed -i "s/^deb-src/#&/g" /etc/apt/sources.list
apt-get update -qq
apt-cache show busybox-static | awk -F ": " "\$1 == \"Version\" { print \$2; exit }"
')"
set -x set -x
sed -ri 's/^(ENV BUSYBOX_VERSION) .*/\1 '"$upstreamVersion"'/;' upstream/Dockerfile.builder sed -ri 's/^(ENV BUSYBOX_VERSION) .*/\1 '"$upstreamVersion"'/' */Dockerfile.builder
sed -ri 's/^(ENV BUSYBOX_VERSION) .*/\1 '"$ubuntuVersion"'/;' ubuntu/Dockerfile.builder