2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 19:31:35 +00:00

Get pretty comfy with dockerfiles

This commit is contained in:
asonix 2020-06-15 19:35:39 -05:00
parent 0801c1141f
commit caa2168e7f
7 changed files with 210 additions and 141 deletions

View file

@ -57,7 +57,7 @@ Run the following to develop in docker:
``` ```
git clone https://git.asonix.dog/asonix/pict-rs git clone https://git.asonix.dog/asonix/pict-rs
cd pict-rs/docker/dev cd pict-rs/docker/dev
docker-compose up --build ./dev.sh
``` ```
### API ### API

View file

@ -3,17 +3,9 @@ FROM rustembedded/cross:x86_64-unknown-linux-gnu AS x86_64-builder
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
ENV TOOLCHAIN=stable
ENV HOST=x86_64-unknown-linux
ENV TARGET=$HOST-gnu
ENV TOOL=x86_64-linux-gnu
ENV ARCH=amd64
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get upgrade -y apt-get upgrade -y && \
RUN \
addgroup --gid "${GID}" build && \ addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -31,7 +23,13 @@ RUN \
USER build USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=$PATH:/opt/build/.cargo/bin ENV \
PATH=$PATH:/opt/build/.cargo/bin \
TOOLCHAIN=stable \
HOST=x86_64-unknown-linux \
TARGET=x86_64-unknown-linux-gnu \
TOOL=x86_64-linux-gnu \
ARCH=amd64
RUN \ RUN \
chmod +x rustup.sh && \ chmod +x rustup.sh && \
@ -53,12 +51,14 @@ RUN \
libjpeg-dev:$ARCH \ libjpeg-dev:$ARCH \
libpng-dev:$ARCH \ libpng-dev:$ARCH \
libwebp-dev:$ARCH \ libwebp-dev:$ARCH \
libxml2-dev:$ARCH && \ liblzma-dev:$ARCH \
llvm-dev \
libclang-dev \
clang && \
chown build:build ImageMagick.tar.gz chown build:build ImageMagick.tar.gz
USER build USER build
ENV USER=build
RUN \ RUN \
tar xvzf ImageMagick.tar.gz && \ tar xvzf ImageMagick.tar.gz && \
@ -66,6 +66,16 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
./configure \ ./configure \
CC=$TOOL-gcc \ CC=$TOOL-gcc \
@ -88,20 +98,11 @@ RUN \
make install && \ make install && \
ldconfig /imagemagick/lib ldconfig /imagemagick/lib
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib
ENV LD_RUN_PATH=$LD_RUN_PATH:/imagemagick/lib
ENV LDFLAGS="$LDFLAGS -L/imagemagick/lib"
ENV RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL"
ENV IMAGE_MAGICK_LIB_DIRS=/imagemagick/lib
ENV IMAGE_MAGICK_INCLUDE_DIRS=/imagemagick/include/ImageMagick-7
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/$TOOL/pkgconfig:/usr/lib/$PKGCONFIG:/imagemagick/lib/pkgconfig
ENV CPPFLAGS="$CPPFLAGS -I/imagemagick/include/ImageMagick-7 -I/usr/lib/llvm-6.0/lib/clang/6.0.0/include"
USER build USER build
WORKDIR /opt/build WORKDIR /opt/build
# Cache deps
RUN \ RUN \
cargo new repo cargo new repo
@ -111,17 +112,20 @@ COPY Cargo.toml Cargo.lock ./
USER root USER root
RUN \ RUN \
chown -R build:build ./ && \ chown -R build:build ./
apt-get install -y \
llvm-dev:$ARCH \
libclang-dev:$ARCH \
clang:$ARCH
USER build USER build
RUN \ ENV \
ls /imagemagick/* && \ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib \
ls /imagemagick/*/* 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 \ RUN \
mkdir -p ./src && \ mkdir -p ./src && \
@ -138,35 +142,38 @@ RUN \
USER build USER build
# Build
RUN cargo build --frozen RUN cargo build --frozen
FROM ubuntu:20.04 FROM ubuntu:20.04
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
ARG BINARY=pict-rs
RUN apt-get update \ ARG TARGET=x86_64-unknown-linux-gnu
&& apt-get install -y \
libgexiv2-2 \
libgomp1 \
libltdl7
# Copy resources
COPY --from=builder /opt/build/repo/target/debug/pict-rs /usr/bin/pict-rs
COPY --from=builder /imagemagick /imagemagick
RUN \ RUN \
addgroup -gid "${GID}" pictrs && \ apt-get update && \
apt-get -y upgrade && \
apt-get -y install \
tini \
libgexiv2-2 \
libgomp1 \
libltdl7 && \
addgroup --gid $GID pictrs && \
adduser \ adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--ingroup pictrs \ --ingroup pictrs \
--uid "${UID}" \ --uid $UID \
--home /opt/pictrs \ --home /opt/pictrs \
pictrs pictrs
COPY --from=builder /imagemagick /imagemagick
COPY --from=builder /opt/build/repo/target/debug/$BINARY /usr/bin/$BINARY
VOLUME /mnt
WORKDIR /opt/pictrs WORKDIR /opt/pictrs
USER pictrs USER pictrs
EXPOSE 8080 EXPOSE 8080
CMD ["/usr/bin/pict-rs"] ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080"]

8
docker/dev/dev.sh Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
mkdir -p ./volumes/pictrs
docker-compose up --build

View file

@ -5,11 +5,13 @@ services:
build: build:
context: ../../ context: ../../
dockerfile: docker/dev/Dockerfile dockerfile: docker/dev/Dockerfile
user: root args:
UID: "${USER_ID:-1000}"
GID: "${GROUP_ID:-1000}"
ports: ports:
- "127.0.0.1:8080:8080" - "127.0.0.1:8080:8080"
restart: always restart: always
environment: environment:
- PICTRS_PATH=/app/data - PICTRS_PATH=/app/data
volumes: volumes:
- ./volumes/pictrs:/app/data - ./volumes/pictrs:/mnt

View file

@ -3,17 +3,9 @@ FROM rustembedded/cross:x86_64-unknown-linux-gnu AS x86_64-builder
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ENV TOOLCHAIN=stable
ENV HOST=x86_64-unknown-linux
ENV TARGET=$HOST-gnu
ENV TOOL=x86_64-linux-gnu
ENV ARCH=amd64
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get upgrade -y apt-get upgrade -y && \
RUN \
addgroup --gid "${GID}" build && \ addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -31,13 +23,20 @@ RUN \
USER build USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=$PATH:/opt/build/.cargo/bin ENV \
PATH=$PATH:/opt/build/.cargo/bin \
TOOLCHAIN=stable \
HOST=x86_64-unknown-linux \
TARGET=x86_64-unknown-linux-gnu \
TOOL=x86_64-linux-gnu \
ARCH=amd64
RUN \ RUN \
chmod +x rustup.sh && \ chmod +x rustup.sh && \
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \ ./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
rustup target add $TARGET rustup target add $TARGET
FROM x86_64-builder as builder FROM x86_64-builder as builder
USER root USER root
@ -54,19 +53,14 @@ RUN \
libpng-dev:$ARCH \ libpng-dev:$ARCH \
libwebp-dev:$ARCH \ libwebp-dev:$ARCH \
libxml2-dev:$ARCH \ libxml2-dev:$ARCH \
liblzma-dev:$ARCH && \ liblzma-dev:$ARCH \
llvm-dev \
libclang-dev \
clang && \
chown build:build ImageMagick.tar.gz chown build:build ImageMagick.tar.gz
USER build USER build
ENV USER=build
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/$PKGCONFIG
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/$TOOL
ENV LD_RUN_PATH=$LD_RUN_PATH:/usr/lib/$TOOL:/usr/lib
ENV LDFLAGS="$LDFLAGS -L/usr/lib/$TOOL -Wl,-rpath-link,/usr/lib/$TOOL"
ENV CPPFLAGS="$CPPFLAGS -I/usr/include -I/usr/include/$TOOL"
RUN \ RUN \
tar xzf ImageMagick.tar.gz && \ tar xzf ImageMagick.tar.gz && \
@ -74,6 +68,16 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
./configure \ ./configure \
CC=$TOOL-gcc \ CC=$TOOL-gcc \
@ -97,14 +101,10 @@ RUN \
make install && \ make install && \
ldconfig /imagemagick/lib ldconfig /imagemagick/lib
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib
ENV LD_RUN_PATH=$LD_RUN_PATH:/imagemagick/lib
ENV LDFLAGS="$LDFLAGS -L/imagemagick/lib"
ENV RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL"
ENV IMAGE_MAGICK_DIR=/imagemagick
USER build USER build
WORKDIR /opt/build
ARG TAG=master ARG TAG=master
ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs
ARG BINARY=pict-rs ARG BINARY=pict-rs
@ -114,22 +114,36 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
cargo build --release --target $TARGET && \ cargo build --release --target $TARGET && \
$TOOL-strip target/$TARGET/release/$BINARY $TOOL-strip target/$TARGET/release/$BINARY
FROM amd64/ubuntu:20.04 FROM amd64/ubuntu:20.04
ARG TARGET=x86_64-unknown-linux-gnu
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ARG BINARY=pict-rs ARG BINARY=pict-rs
COPY --from=builder /opt/build/repo/target/x86_64-unknown-linux-gnu/release/$BINARY /usr/bin/$BINARY
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get -y upgrade && \ apt-get -y upgrade && \
apt-get -y install tini libgexiv2-2 && \ apt-get -y install \
tini \
libgexiv2-2 \
libgomp1 \
libltdl7 && \
addgroup --gid $GID pictrs && \ addgroup --gid $GID pictrs && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -137,13 +151,15 @@ RUN \
--ingroup pictrs \ --ingroup pictrs \
--uid $UID \ --uid $UID \
--home /opt/pictrs \ --home /opt/pictrs \
pictrs pictrs && \
RUN \
chown -R pictrs:pictrs /mnt 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 VOLUME /mnt
WORKDIR /opt/pictrs WORKDIR /opt/pictrs
USER pictrs USER pictrs
EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"] CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"]

View file

@ -3,17 +3,9 @@ FROM rustembedded/cross:arm-unknown-linux-gnueabihf AS arm32v7-builder
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ENV TOOLCHAIN=stable
ENV HOST=arm-unknown-linux
ENV TARGET=$HOST-gnueabihf
ENV TOOL=arm-linux-gnueabihf
ENV ARCH=armhf
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get upgrade -y apt-get upgrade -y && \
RUN \
addgroup --gid "${GID}" build && \ addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -31,13 +23,20 @@ RUN \
USER build USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=$PATH:/opt/build/.cargo/bin 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 \ RUN \
chmod +x rustup.sh && \ chmod +x rustup.sh && \
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \ ./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
rustup target add $TARGET rustup target add $TARGET
FROM arm32v7-builder as builder FROM arm32v7-builder as builder
USER root USER root
@ -55,6 +54,10 @@ RUN \
libwebp-dev:$ARCH \ libwebp-dev:$ARCH \
libxml2-dev:$ARCH \ libxml2-dev:$ARCH \
liblzma-dev:$ARCH \ liblzma-dev:$ARCH \
libc6-dev-$ARCH-cross \
llvm-dev \
libclang-dev \
clang \
libexpat1-dev:$ARCH && \ libexpat1-dev:$ARCH && \
ln -s /usr/lib/$TOOL/libpcre.so /usr/lib/$TOOL/libpcre.so.3 && \ 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/libz.so /usr/lib/$TOOL/libz.so.1 && \
@ -63,14 +66,6 @@ RUN \
USER build USER build
ENV USER=build
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/$PKGCONFIG
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/$TOOL
ENV LD_RUN_PATH=$LD_RUN_PATH:/usr/lib/$TOOL:/usr/lib
ENV LDFLAGS="$LDFLAGS -L/usr/lib/$TOOL -Wl,-rpath-link,/usr/lib/$TOOL"
ENV CPPFLAGS="$CPPFLAGS -I/usr/include -I/usr/include/$TOOL"
RUN \ RUN \
tar xzf ImageMagick.tar.gz && \ tar xzf ImageMagick.tar.gz && \
@ -78,6 +73,16 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
./configure \ ./configure \
CC=$TOOL-gcc \ CC=$TOOL-gcc \
@ -99,16 +104,13 @@ USER root
RUN \ RUN \
make install && \ make install && \
ldconfig /imagemagick/lib ldconfig /imagemagick/lib && \
rm -r /usr/include/x86_64-linux-gnu
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib
ENV LD_RUN_PATH=$LD_RUN_PATH:/imagemagick/lib
ENV LDFLAGS="$LDFLAGS -L/imagemagick/lib"
ENV RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL"
ENV IMAGE_MAGICK_DIR=/imagemagick
USER build USER build
WORKDIR /opt/build
ARG TAG=master ARG TAG=master
ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs
ARG BINARY=pict-rs ARG BINARY=pict-rs
@ -118,22 +120,36 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
cargo build --release --target $TARGET && \ cargo build --release --target $TARGET && \
$TOOL-strip target/$TARGET/release/$BINARY $TOOL-strip target/$TARGET/release/$BINARY
FROM arm32v7/ubuntu:20.04 FROM arm32v7/ubuntu:20.04
ARG TARGET=arm-unknown-linux-gnueabihf
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ARG BINARY=pict-rs ARG BINARY=pict-rs
COPY --from=builder /opt/build/repo/target/arm-unknown-linux-gnueabihf/release/$BINARY /usr/bin/$BINARY
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get -y upgrade && \ apt-get -y upgrade && \
apt-get -y install tini libgexiv2-2 && \ apt-get -y install \
tini \
libgexiv2-2 \
libgomp1 \
libltdl7 && \
addgroup --gid $GID pictrs && \ addgroup --gid $GID pictrs && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -141,13 +157,15 @@ RUN \
--ingroup pictrs \ --ingroup pictrs \
--uid $UID \ --uid $UID \
--home /opt/pictrs \ --home /opt/pictrs \
pictrs pictrs && \
RUN \
chown -R pictrs:pictrs /mnt 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 VOLUME /mnt
WORKDIR /opt/pictrs WORKDIR /opt/pictrs
USER pictrs USER pictrs
EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"] CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"]

View file

@ -3,17 +3,9 @@ FROM rustembedded/cross:aarch64-unknown-linux-gnu AS aarch64-builder
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ENV TOOLCHAIN=stable
ENV HOST=aarch64-unknown-linux
ENV TARGET=$HOST-gnu
ENV TOOL=aarch64-linux-gnu
ENV ARCH=arm64
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get upgrade -y apt-get upgrade -y && \
RUN \
addgroup --gid "${GID}" build && \ addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -31,13 +23,20 @@ RUN \
USER build USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=$PATH:/opt/build/.cargo/bin ENV \
PATH=$PATH:/opt/build/.cargo/bin \
TOOLCHAIN=stable \
HOST=aarch64-unknown-linux \
TARGET=aarch64-unknown-linux-gnu \
TOOL=aarch64-linux-gnu \
ARCH=arm64
RUN \ RUN \
chmod +x rustup.sh && \ chmod +x rustup.sh && \
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \ ./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
rustup target add $TARGET rustup target add $TARGET
FROM aarch64-builder as builder FROM aarch64-builder as builder
USER root USER root
@ -54,19 +53,15 @@ RUN \
libpng-dev:$ARCH \ libpng-dev:$ARCH \
libwebp-dev:$ARCH \ libwebp-dev:$ARCH \
libxml2-dev:$ARCH \ libxml2-dev:$ARCH \
liblzma-dev:$ARCH && \ liblzma-dev:$ARCH \
libc6-dev-$ARCH-cross \
llvm-dev \
libclang-dev \
clang && \
chown build:build ImageMagick.tar.gz chown build:build ImageMagick.tar.gz
USER build USER build
ENV USER=build
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/$PKGCONFIG
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/$TOOL
ENV LD_RUN_PATH=$LD_RUN_PATH:/usr/lib/$TOOL:/usr/lib
ENV LDFLAGS="$LDFLAGS -L/usr/lib/$TOOL -Wl,-rpath-link,/usr/lib/$TOOL"
ENV CPPFLAGS="$CPPFLAGS -I/usr/include -I/usr/include/$TOOL"
RUN \ RUN \
tar xzf ImageMagick.tar.gz && \ tar xzf ImageMagick.tar.gz && \
@ -74,6 +69,16 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
./configure \ ./configure \
CC=$TOOL-gcc \ CC=$TOOL-gcc \
@ -95,16 +100,13 @@ USER root
RUN \ RUN \
make install && \ make install && \
ldconfig /imagemagick/lib ldconfig /imagemagick/lib && \
rm -r /usr/include/x86_64-linux-gnu
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/imagemagick/lib
ENV LD_RUN_PATH=$LD_RUN_PATH:/imagemagick/lib
ENV LDFLAGS="$LDFLAGS -L/imagemagick/lib"
ENV RUSTFLAGS="-L/usr/lib/$TOOL -C link-arg=-Wl,-rpath-link,/usr/lib/$TOOL"
ENV IMAGE_MAGICK_DIR=/imagemagick
USER build USER build
WORKDIR /opt/build
ARG TAG=master ARG TAG=master
ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs ARG REPOSITORY=https://git.asonix.dog/asonix/pict-rs
ARG BINARY=pict-rs ARG BINARY=pict-rs
@ -114,22 +116,36 @@ RUN \
WORKDIR /opt/build/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 \ RUN \
cargo build --release --target $TARGET && \ cargo build --release --target $TARGET && \
$TOOL-strip target/$TARGET/release/$BINARY $TOOL-strip target/$TARGET/release/$BINARY
FROM arm64v8/ubuntu:20.04 FROM arm64v8/ubuntu:20.04
ARG TARGET=aarch64-unknown-linux-gnu
ARG UID=991 ARG UID=991
ARG GID=991 ARG GID=991
ARG BINARY=pict-rs ARG BINARY=pict-rs
COPY --from=builder /opt/build/repo/target/aarch64-unknown-linux-gnu/release/$BINARY /usr/bin/$BINARY
RUN \ RUN \
apt-get update && \ apt-get update && \
apt-get -y upgrade && \ apt-get -y upgrade && \
apt-get -y install tini libgexiv2-2 && \ apt-get -y install \
tini \
libgexiv2-2 \
libgomp1 \
libltdl7 && \
addgroup --gid $GID pictrs && \ addgroup --gid $GID pictrs && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -137,13 +153,15 @@ RUN \
--ingroup pictrs \ --ingroup pictrs \
--uid $UID \ --uid $UID \
--home /opt/pictrs \ --home /opt/pictrs \
pictrs pictrs && \
RUN \
chown -R pictrs:pictrs /mnt 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 VOLUME /mnt
WORKDIR /opt/pictrs WORKDIR /opt/pictrs
USER pictrs USER pictrs
EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"] CMD ["/usr/bin/pict-rs", "-p", "/mnt", "-a", "0.0.0.0:8080", "-w", "thumbnail"]