pict-rs/docker/prod/Dockerfile.arm64v8

209 lines
5 KiB
Docker
Raw Normal View History

2020-06-16 20:55:24 +00:00
# Target environment
FROM arm64v8/ubuntu:20.04 as target-env
ENV \
TARGET=aarch64-unknown-linux-gnu \
BUILD_MODE=release
# Basic cross-build environment
FROM ubuntu:20.04 as cross-build
ENV \
ARCH=arm64 \
HOST=aarch64-unknown-linux \
TOOL=aarch64-linux-gnu \
TARGET=aarch64-unknown-linux-gnu \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_AARCH64_UNKNOWN_LINUX_GNU=aarch64-linux-gnu-gcc \
CXX_AARCH64_UNKNOWN_LINUX_GNU=aarch64-linux-gnu-g++ \
BUILD_MODE=release
ENV \
TOOLCHAIN=stable \
DEBIAN_FRONTEND=noninteractive \
PKG_CONFIG_ALLOW_CROSS=1 \
PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/pkgconfig \
LD_LIBRARY_PATH=/usr/lib/$TOOL:/usr/$TOOL/lib \
LD_RUN_PATH=/usr/lib/$TOOL:/usr/$TOOL/lib \
LDFLAGS="-L/usr/lib/$TOOL -L/usr/$TOOL/lib -Wl,-rpath-link,/usr/lib/$TOOL -Wl,-rpath-link,/usr/$TOOL/lib" \
CFLAGS="-I/usr/include/$TOOL -I/usr/$TOOL/include -I/usr/include" \
CPPFLAGS="-I/usr/include/$TOOL -I/usr/$TOOL/include -I/usr/include"
2020-06-07 23:29:41 +00:00
RUN \
2020-06-16 20:55:24 +00:00
sed 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch-=amd64,i386] http:\/\/ports.ubuntu.com\/ubuntu-ports\//g' /etc/apt/sources.list > /etc/apt/sources.list.d/ports.list && \
sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list && \
addgroup --gid 991 build && \
2020-06-07 23:29:41 +00:00
adduser \
--disabled-password \
--gecos "" \
--ingroup build \
--uid 991 \
2020-06-07 23:29:41 +00:00
--home /opt/build \
2020-06-16 20:55:24 +00:00
build && \
dpkg --add-architecture $ARCH && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
pkg-config \
build-essential \
crossbuild-essential-$ARCH
2020-06-07 23:29:41 +00:00
WORKDIR /opt/build
2020-06-08 17:43:28 +00:00
2020-06-16 20:55:24 +00:00
# Environment for ImageMagick
FROM cross-build as imagemagick-builder
2020-06-15 19:20:25 +00:00
2020-06-15 02:41:45 +00:00
RUN \
2020-06-16 20:55:24 +00:00
apt-get install -y \
2020-06-15 19:20:25 +00:00
libltdl-dev:$ARCH \
libjpeg-dev:$ARCH \
libpng-dev:$ARCH \
libwebp-dev:$ARCH \
2020-06-16 00:35:39 +00:00
liblzma-dev:$ARCH \
2020-06-16 20:55:24 +00:00
libxml2-dev:$ARCH
2020-06-15 19:20:25 +00:00
2020-06-16 20:55:24 +00:00
ADD --chown=build:build https://imagemagick.org/download/ImageMagick.tar.gz /opt/build/ImageMagick.tar.gz
2020-06-15 19:20:25 +00:00
USER build
RUN \
2020-06-16 20:55:24 +00:00
tar zxf ImageMagick.tar.gz && \
2020-06-15 19:20:25 +00:00
mv ImageMagick-* ImageMagick
WORKDIR /opt/build/ImageMagick
RUN \
./configure \
2020-06-16 20:55:24 +00:00
CC=$TOOL-gcc \
CXX=$TOOL-g++ \
--enable-shared \
--with-modules \
--disable-static \
--disable-docs \
--prefix=/usr/local \
--with-utilities=no \
2020-06-18 03:50:57 +00:00
--with-magick-plus-plus=no \
2020-06-16 20:55:24 +00:00
--without-perl \
--with-xml=yes \
--with-png=yes \
--with-jpeg=yes \
--with-webp=yes \
--host=$HOST && \
2020-06-15 19:20:25 +00:00
make
USER root
RUN \
make install && \
2020-06-16 20:55:24 +00:00
ldconfig /usr/local/lib
2020-06-15 02:41:45 +00:00
2020-06-16 20:55:24 +00:00
# Environment for Rust
FROM cross-build as rust
2020-06-16 00:35:39 +00:00
2020-06-16 20:55:24 +00:00
RUN \
apt-get install -y curl
ENV \
PATH=$PATH:/opt/build/.cargo/bin
ADD --chown=build:build https://sh.rustup.rs /opt/build/rustup.sh
USER build
2020-06-08 17:43:28 +00:00
2020-06-07 23:29:41 +00:00
RUN \
2020-06-16 20:55:24 +00:00
chmod +x rustup.sh && \
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
rustup target add $TARGET
2020-06-07 23:29:41 +00:00
2020-06-16 20:55:24 +00:00
USER root
# Environment for pict-rs
FROM cross-build as pict-rs-builder
RUN \
apt-get install -y \
libgexiv2-dev:$ARCH \
libxml2:$ARCH \
libltdl7:$ARCH \
llvm-dev \
libclang-dev \
clang && \
rm -rf /usr/include/x86_64-linux-gnu
2020-06-07 23:29:41 +00:00
2020-06-16 00:35:39 +00:00
ENV \
2020-06-16 20:55:24 +00:00
PATH=$PATH:/opt/build/.cargo/bin \
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig \
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib \
LD_RUN_PATH=$LD_RUN_PATH:/usr/local/lib \
LDFLAGS="$LDFLAGS -L/usr/local/lib" \
IMAGE_MAGICK_LIB_DIRS=/usr/local/lib \
IMAGE_MAGICK_INCLUDE_DIRS=/usr/local/include/ImageMagick-7 \
CFLAGS="$CFLAGS -I/usr/local/include/ImageMagick-7" \
CPPFLAGS="$CPPFLAGS -I/usr/local/include/ImageMagick-7" \
RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL -L/usr/$TOOL/lib -C link-arg=-Wl,-rpath-link,/usr/$TOOL/lib"
COPY --from=rust --chown=build:build /opt/build/.cargo /opt/build/.cargo
COPY --from=rust --chown=build:build /opt/build/.rustup /opt/build/.rustup
COPY --from=imagemagick-builder /usr/local/ /usr/local
2020-06-18 15:01:21 +00:00
ARG TAG=main
2020-06-16 20:55:24 +00:00
ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs
ADD --chown=build:build $GIT_REPOSITORY/archive/$TAG.tar.gz /opt/build/$TAG.tar.gz
USER build
2020-06-16 00:35:39 +00:00
2020-06-07 23:29:41 +00:00
RUN \
2020-06-16 20:55:24 +00:00
tar zxf $TAG.tar.gz
2020-06-07 23:29:41 +00:00
2020-06-16 20:55:24 +00:00
WORKDIR /opt/build/pict-rs
RUN \
USER=build cargo build --target=$TARGET --$BUILD_MODE && \
$TOOL-strip /opt/build/pict-rs/target/$TARGET/$BUILD_MODE/pict-rs
# Producing target binary
FROM target-env
2020-06-07 23:29:41 +00:00
ARG UID=991
ARG GID=991
RUN \
2020-06-15 02:41:45 +00:00
addgroup --gid $GID pictrs && \
adduser \
--disabled-password \
--gecos "" \
--ingroup pictrs \
--uid $UID \
2020-06-16 20:55:24 +00:00
--home /opt/pict-rs \
2020-06-16 00:35:39 +00:00
pictrs && \
2020-06-16 20:55:24 +00:00
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
libgexiv2-2 \
libpng16-16 \
libjpeg8 \
libwebp6 \
libwebpdemux2 \
libwebpmux3 \
libltdl7 \
libgomp1 \
libxml2 \
tini
COPY --from=pict-rs-builder /opt/build/pict-rs/target/$TARGET/$BUILD_MODE/pict-rs /usr/local/bin/pict-rs
COPY --from=imagemagick-builder /usr/local /usr/local
2020-06-08 01:28:16 +00:00
2020-06-16 20:55:24 +00:00
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
2020-06-16 00:35:39 +00:00
2020-06-08 14:12:12 +00:00
VOLUME /mnt
2020-06-16 20:55:24 +00:00
WORKDIR /opt/pict-rs
2020-06-07 23:29:41 +00:00
USER pictrs
2020-06-16 00:35:39 +00:00
EXPOSE 8080
2020-06-15 02:41:45 +00:00
ENTRYPOINT ["/usr/bin/tini", "--"]
2020-06-16 20:55:24 +00:00
CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"]