switch to multi-stage build, prepare multi-arch build

This commit is contained in:
John
2021-01-17 14:02:07 +01:00
parent 9ab7739704
commit d186bc64ff
11 changed files with 248 additions and 76 deletions
+27 -17
View File
@@ -1,13 +1,29 @@
FROM debian:stretch
FROM debian:stretch as build
RUN apt-get update && apt-get install -y \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
curl \
autoconf automake g++ make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH amd64
RUN git clone https://github.com/john30/ebusd.git /build \
&& ./make_debian.sh
ARG UPLOAD_URL
ARG UPLOAD_CREDENTIALS
FROM debian:stretch-slim
RUN apt-get update && apt-get install -y \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
autoconf automake g++ make git \
libmosquitto-dev \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
@@ -17,19 +33,13 @@ ENV EBUSD_ARCH amd64
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}-devel"
WORKDIR /build
COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb
RUN (curl -SL https://github.com/john30/ebusd/archive/master.tar.gz \
| tar xz --strip-components=1) \
&& ./autogen.sh \
&& make install-strip
WORKDIR /
RUN rm -rf /build
RUN dpkg -i ebusd.deb \
&& rm -f ebusd.deb
EXPOSE 8888
COPY release/docker-entrypoint.sh /
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-f", "--scanconfig"]
+45
View File
@@ -0,0 +1,45 @@
FROM multiarch/qemu-user-static as qemu
FROM arm32v7/debian:stretch as build
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/
RUN apt-get update && apt-get install -y \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
curl \
autoconf automake g++ make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH arm32v7
RUN git clone https://github.com/john30/ebusd.git /build \
&& ./make_debian.sh
ARG UPLOAD_URL
ARG UPLOAD_CREDENTIALS
FROM arm32v7/debian:stretch-slim
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/
RUN apt-get update && apt-get install -y \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH arm32v7
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}-devel"
COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb
RUN dpkg -i ebusd.deb \
&& rm -f ebusd.deb /usr/bin/qemu-arm-static
EXPOSE 8888
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-f", "--scanconfig"]
+45
View File
@@ -0,0 +1,45 @@
%QEMU_FROM_LINE%
FROM %BASE_IMAGE% as build
%QEMU_FROM_COPY%
RUN apt-get update && apt-get install -y \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
curl \
autoconf automake g++ make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
ENV EBUSD_VERSION %EBUSD_VERSION%
ENV EBUSD_ARCH %EBUSD_ARCH%
RUN git clone https://github.com/john30/ebusd.git /build \
&& %EBUSD_MAKE%
ARG UPLOAD_URL
ARG UPLOAD_CREDENTIALS
%EBUSD_UPLOAD_LINE%
FROM %BASE_IMAGE%-slim
%QEMU_FROM_COPY%
RUN apt-get update && apt-get install -y \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
ENV EBUSD_VERSION %EBUSD_VERSION%
ENV EBUSD_ARCH %EBUSD_ARCH%
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}%EBUSD_VERSION_VARIANT%"
COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb
RUN dpkg -i ebusd.deb \
&& rm -f ebusd.deb%EXTRA_RM%
EXPOSE 8888
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-f", "--scanconfig"]
-11
View File
@@ -1,11 +0,0 @@
FROM debian:jessie
RUN apt-get update && apt-get install -y \
autoconf automake g++ make git \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
WORKDIR /build
CMD ["/bin/bash"]
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
arch=$(echo "$DOCKERFILE_PATH" | cut -d '.' -f 2)
if [ "$arch" == "Dockerfile" ]; then
echo "QEMU not needed"
exit 0
fi
echo "registering QEMU for $arch"
docker run --rm --privileged multiarch/qemu-user-static:register --reset
echo "QEMU registered for $arch"
+26 -6
View File
@@ -1,8 +1,29 @@
FROM debian:stretch
FROM debian:stretch as build
RUN apt-get update && apt-get install -y \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
curl \
autoconf automake g++ make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH amd64
RUN git clone https://github.com/john30/ebusd.git /build \
&& ./make_all.sh
ARG UPLOAD_URL
ARG UPLOAD_CREDENTIALS
RUN if [ -n "$UPLOAD_URL" ] && [ -n "$UPLOAD_CREDENTIALS" ]; then for img in ebusd-*.deb; do echo "upload $img"; curl -u "$UPLOAD_CREDENTIALS" -s -X POST --data-binary "@$img" -H "Content-Type: application/octet-stream" "$UPLOAD_URL/$img?a=$EBUSD_ARCH&v=$EBUSD_VERSION"; done; fi
FROM debian:stretch-slim
RUN apt-get update && apt-get install -y \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
curl \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
@@ -12,11 +33,10 @@ ENV EBUSD_ARCH amd64
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}"
RUN curl -SL https://github.com/john30/ebusd/releases/download/v${EBUSD_VERSION}/ebusd-${EBUSD_VERSION}_${EBUSD_ARCH}-stretch_mqtt1.deb > ebusd.deb
COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb
RUN dpkg -i ebusd.deb
RUN rm ebusd.deb
RUN dpkg -i ebusd.deb \
&& rm -f ebusd.deb
EXPOSE 8888
+45
View File
@@ -0,0 +1,45 @@
FROM multiarch/qemu-user-static as qemu
FROM arm32v7/debian:stretch as build
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/
RUN apt-get update && apt-get install -y \
libmosquitto-dev libstdc++6 libc6 libgcc1 \
curl \
autoconf automake g++ make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH arm32v7
RUN git clone https://github.com/john30/ebusd.git /build \
&& ./make_all.sh
ARG UPLOAD_URL
ARG UPLOAD_CREDENTIALS
RUN if [ -n "$UPLOAD_URL" ] && [ -n "$UPLOAD_CREDENTIALS" ]; then for img in ebusd-*.deb; do echo "upload $img"; curl -u "$UPLOAD_CREDENTIALS" -s -X POST --data-binary "@$img" -H "Content-Type: application/octet-stream" "$UPLOAD_URL/$img?a=$EBUSD_ARCH&v=$EBUSD_VERSION"; done; fi
FROM arm32v7/debian:stretch-slim
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/
RUN apt-get update && apt-get install -y \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
&& rm -rf /var/lib/apt/lists/*
LABEL maintainer "ebusd@ebusd.eu"
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH arm32v7
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}"
COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb
RUN dpkg -i ebusd.deb \
&& rm -f ebusd.deb /usr/bin/qemu-arm-static
EXPOSE 8888
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-f", "--scanconfig"]
-28
View File
@@ -1,28 +0,0 @@
FROM balenalib/raspberrypi3:stretch
RUN [ "cross-build-start" ]
RUN install_packages \
logrotate libmosquitto1 libstdc++6 libc6 libgcc1 \
curl
LABEL maintainer "ebusd@ebusd.eu"
ENV EBUSD_VERSION 21.1
ENV EBUSD_ARCH armhf
LABEL version "${EBUSD_VERSION}-${EBUSD_ARCH}"
RUN curl -SL https://github.com/john30/ebusd/releases/download/v${EBUSD_VERSION}/ebusd-${EBUSD_VERSION}_${EBUSD_ARCH}-stretch_mqtt1.deb > ebusd.deb
RUN dpkg -i ebusd.deb
RUN rm ebusd.deb
RUN [ "cross-build-end" ]
EXPOSE 8888
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-f", "--scanconfig"]
@@ -1,8 +0,0 @@
#!/bin/bash
set -e
if [ "${1#-}" != "$1" ]; then
set -- ebusd "$@"
fi
exec "$@"
+51 -6
View File
@@ -1,7 +1,52 @@
#!/bin/sh
set -e
export EBUSD_VERSION=`cat ../../VERSION`
export EBUSD_ARCH=`docker version|grep -i "Arch[^:]*:"|tail -n 1|sed -e 's#^.*/##'`
sed -i -e "s#^ENV EBUSD_VERSION .*\$#ENV EBUSD_VERSION ${EBUSD_VERSION}#" -e "s#^ENV EBUSD_ARCH .*\$#ENV EBUSD_ARCH ${EBUSD_ARCH}#" Dockerfile release/Dockerfile
sed -i -e "s#^ENV EBUSD_VERSION .*\$#ENV EBUSD_VERSION ${EBUSD_VERSION}#" rpirelease/Dockerfile
#!/bin/bash
BASE_IMAGE=debian:stretch
EBUSD_VERSION=`cat ../../VERSION`
archs='amd64 i386 arm32v7:arm arm64v8:aarch64'
function replaceTemplate () {
prefix=
suffix=
qemu_from_line=
qemu_from_copy=
extra_rm=
if [ "$arch" != "amd64" ]; then
qemu="${arch##*:}"
arch="${arch%%:*}"
prefix="$arch/"
suffix=".$arch"
qemu_from_line="FROM multiarch/qemu-user-static as qemu"
qemu_from_copy="COPY --from=qemu /usr/bin/qemu-$qemu-static /usr/bin/"
extra_rm=" /usr/bin/qemu-$qemu-static"
fi
sed \
-e "s#%QEMU_FROM_LINE%#${qemu_from_line}#g" \
-e "s#%BASE_IMAGE%#${prefix}${BASE_IMAGE}#g" \
-e "s#%QEMU_FROM_COPY%#${qemu_from_copy}#g" \
-e "s#%EBUSD_MAKE%#${make}#g" \
-e "s#%EBUSD_VERSION%#${EBUSD_VERSION}#g" \
-e "s#%EBUSD_VERSION_VARIANT%#${version_variant}#g" \
-e "s#%EBUSD_ARCH%#${arch}#g" \
-e "s#%EXTRA_RM%#${extra_rm}#g" \
-e "s#%EBUSD_UPLOAD_LINE%#${upload_line}#g" \
Dockerfile.template > "${dir}Dockerfile${suffix}"
echo "updated ${dir}Dockerfile${suffix}"
}
# devel updates
version_variant='-devel'
make='./make_debian.sh'
dir=''
upload_line=''
for arch in $archs; do
replaceTemplate
done
# release updates
version_variant=''
make='./make_all.sh'
dir='release/'
upload_line='RUN if [ -n "\$UPLOAD_URL" ] \&\& [ -n "\$UPLOAD_CREDENTIALS" ]; then for img in ebusd-*.deb; do echo "upload \$img"; curl -u "\$UPLOAD_CREDENTIALS" -s -X POST --data-binary "@\$img" -H "Content-Type: application/octet-stream" "\$UPLOAD_URL/\$img?a=\$EBUSD_ARCH\&v=\$EBUSD_VERSION"; done; fi'
for arch in $archs; do
replaceTemplate
done