docker: refine Dockerfile, make cache happy.

This commit is contained in:
honwen.chan
2022-07-26 19:24:34 +08:00
committed by Nick Peng
parent ac042e8bee
commit 2f1d83cc2c

View File

@@ -1,35 +1,41 @@
FROM ubuntu:latest as smartdns-builder FROM ubuntu:latest as smartdns-builder
LABEL previous-stage=smartdns-builder LABEL previous-stage=smartdns-builder
COPY . /smartdns/
# prepare builder
ARG OPENSSL_VER=1.1.1f
RUN apt update && \ RUN apt update && \
apt install -y perl wget make musl-tools musl-dev && \ apt install -y perl curl make musl-tools musl-dev && \
OPENSSL_VER=1.1.1f && \
mkdir /build -p && \
ln -s /usr/include/linux /usr/include/$(uname -m)-linux-musl && \ ln -s /usr/include/linux /usr/include/$(uname -m)-linux-musl && \
ln -s /usr/include/asm-generic /usr/include/$(uname -m)-linux-musl && \ ln -s /usr/include/asm-generic /usr/include/$(uname -m)-linux-musl && \
ln -s /usr/include/$(uname -m)-linux-gnu/asm /usr/include/$(uname -m)-linux-musl && \ ln -s /usr/include/$(uname -m)-linux-gnu/asm /usr/include/$(uname -m)-linux-musl && \
cd /build && \ \
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_${OPENSSL_VER}.orig.tar.gz && \ mkdir -p /build/openssl && \
tar xf openssl_${OPENSSL_VER}.orig.tar.gz && \ cd /build/openssl && \
cd openssl-${OPENSSL_VER} && \ curl -sSL http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_${OPENSSL_VER}.orig.tar.gz | tar --strip-components=1 -zxv && \
\
export CC=musl-gcc && \ export CC=musl-gcc && \
if [ "$(uname -m)" = "aarch64" ]; then \ if [ "$(uname -m)" = "aarch64" ]; then \
./config --prefix=/opt/build no-tests -mno-outline-atomics ; \ ./config --prefix=/opt/build no-tests -mno-outline-atomics ; \
else \ else \
./config --prefix=/opt/build no-tests; \ ./config --prefix=/opt/build no-tests ; \
fi && \ fi && \
make all -j8 && make install_sw && \ make all -j8 && make install_sw && \
cd /smartdns && \ cd / && rm -rf /build
# do make
COPY . /build/smartdns/
RUN cd /build/smartdns && \
export CC=musl-gcc && \
export CFLAGS="-I /opt/build/include" && \ export CFLAGS="-I /opt/build/include" && \
export LDFLAGS="-L /opt/build/lib" && \ export LDFLAGS="-L /opt/build/lib" && \
sh ./package/build-pkg.sh --platform linux --arch `dpkg --print-architecture` --static && \ sh ./package/build-pkg.sh --platform linux --arch `dpkg --print-architecture` --static && \
mkdir /release -p && \ \
cd /smartdns/package && tar xf *.tar.gz && \ ( cd package && tar -xvf *.tar.gz && chmod a+x smartdns/etc/init.d/smartdns ) && \
cp /smartdns/package/smartdns/etc /release/ -a && \ \
cp /smartdns/package/smartdns/usr /release/ -a && \ mkdir -p /release/var/log /release/var/run && \
chmod +x /release/etc/init.d/smartdns && \ cp package/smartdns/etc /release/ -a && \
mkdir /release/var/log/ /release/var/run/ -p && \ cp package/smartdns/usr /release/ -a && \
rm -fr /build /smartdns cd / && rm -rf /build
FROM busybox:latest FROM busybox:latest
COPY --from=smartdns-builder /release/ / COPY --from=smartdns-builder /release/ /