2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-12 23:43:57 +00:00
pict-rs/docker/prod/Dockerfile.arm32v7

171 lines
3.8 KiB
Text

FROM rustembedded/cross:arm-unknown-linux-gnueabihf AS arm32v7-builder
ARG UID=991
ARG GID=991
RUN \
apt-get update && \
apt-get upgrade -y && \
addgroup --gid "${GID}" build && \
adduser \
--disabled-password \
--gecos "" \
--ingroup build \
--uid "${UID}" \
--home /opt/build \
build
ADD https://sh.rustup.rs /opt/build/rustup.sh
RUN \
chown -R build:build /opt/build
USER build
WORKDIR /opt/build
ENV \
PATH=$PATH:/opt/build/.cargo/bin \
TOOLCHAIN=stable \
HOST=arm-unknown-linux \
TARGET=arm-unknown-linux-gnueabihf \
TOOL=arm-linux-gnueabihf \
ARCH=armhf
RUN \
chmod +x rustup.sh && \
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
rustup target add $TARGET
FROM arm32v7-builder as builder
USER root
ADD https://imagemagick.org/download/ImageMagick.tar.gz ./
RUN \
dpkg --add-architecture $ARCH && \
apt-get update && \
apt-get -y install \
libgexiv2-dev:$ARCH \
libltdl-dev:$ARCH \
libjpeg-dev:$ARCH \
libpng-dev:$ARCH \
libwebp-dev:$ARCH \
libxml2-dev:$ARCH \
liblzma-dev:$ARCH \
libc6-dev-$ARCH-cross \
llvm-dev \
libclang-dev \
clang \
libexpat1-dev:$ARCH && \
ln -s /usr/lib/$TOOL/libpcre.so /usr/lib/$TOOL/libpcre.so.3 && \
ln -s /usr/lib/$TOOL/libz.so /usr/lib/$TOOL/libz.so.1 && \
ln -s /usr/lib/$TOOL/libexpatw.so /usr/lib/$TOOL/libexpat.so.1 && \
chown build:build ImageMagick.tar.gz
USER build
RUN \
tar xzf ImageMagick.tar.gz && \
mv ImageMagick-* ImageMagick
WORKDIR /opt/build/ImageMagick
ENV \
USER=build \
PKG_CONFIG_ALLOW_CROSS=1 \
PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/pkgconfig \
LD_LIBRARY_PATH=/usr/lib/$TOOL \
LD_RUN_PATH=$LD_RUN_PATH:/usr/lib/$TOOL \
LDFLAGS="$LDFLAGS -L/usr/lib/$TOOL -Wl,-rpath-link,/usr/lib/$TOOL" \
CFLAGS="$CFLAGS -I/usr/include/$TOOL -I/usr/$TOOL/include -I/usr/include" \
CPPFLAGS="$CPPFLAGS -I/usr/include/$TOOL -I/usr/$TOOL/include -I/usr/include"
RUN \
./configure \
CC=$TOOL-gcc \
CXX=$TOOL-g++ \
--prefix=/imagemagick \
--disable-docs \
--with-modules \
--enable-shared \
--disable-static \
--without-perl \
--with-xml=yes \
--with-png=yes \
--with-jpeg=yes \
--with-webp=yes \
--host=$HOST && \
make
USER root
RUN \
make install && \
ldconfig /imagemagick/lib && \
rm -r /usr/include/x86_64-linux-gnu
USER build
WORKDIR /opt/build
ARG TAG=master
ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs
ARG BINARY=pict-rs
RUN \
git clone -b $TAG $REPOSITORY repo
WORKDIR /opt/build/repo
ENV \
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib \
LD_RUN_PATH=$LD_RUN_PATH:/imagemagick/lib \
LDFLAGS="$LDFLAGS -L/imagemagick/lib" \
RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL" \
IMAGE_MAGICK_LIB_DIRS=/imagemagick/lib \
IMAGE_MAGICK_INCLUDE_DIRS=/imagemagick/include/ImageMagick-7 \
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/imagemagick/lib/pkgconfig \
CFLAGS="$CFLAGS -I/imagemagick/include/ImageMagick-7" \
CPPFLAGS="$CPPFLAGS -I/imagemagick/include/ImageMagick-7"
RUN \
cargo build --release --target $TARGET && \
$TOOL-strip target/$TARGET/release/$BINARY
FROM arm32v7/ubuntu:20.04
ARG TARGET=arm-unknown-linux-gnueabihf
ARG UID=991
ARG GID=991
ARG BINARY=pict-rs
RUN \
apt-get update && \
apt-get -y upgrade && \
apt-get -y install \
tini \
libgexiv2-2 \
libgomp1 \
libltdl7 && \
addgroup --gid $GID pictrs && \
adduser \
--disabled-password \
--gecos "" \
--ingroup pictrs \
--uid $UID \
--home /opt/pictrs \
pictrs && \
chown -R pictrs:pictrs /mnt
COPY --from=builder /imagemagick /imagemagick
COPY --from=builder /opt/build/repo/target/$TARGET/release/$BINARY /usr/bin/$BINARY
VOLUME /mnt
WORKDIR /opt/pictrs
USER pictrs
EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"]