From b17cf1794cfa52f6e1490d4d104fe5615ea5ba03 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 10 Oct 2020 20:27:57 -0500 Subject: [PATCH] v0.2.1 - re-enable arm32 --- Cargo.lock | 2 +- Cargo.toml | 9 +- docker/dev/Dockerfile.arm32v7 | 169 ++++++++++++++++++++++++ docker/dev/docker-compose.yml | 16 +++ docker/prod/Dockerfile.arm32v7 | 228 +++++++++++++++++++++++++++++++++ docker/prod/deploy.sh | 3 +- docker/prod/manifest.sh | 4 + 7 files changed, 422 insertions(+), 9 deletions(-) create mode 100644 docker/dev/Dockerfile.arm32v7 create mode 100644 docker/prod/Dockerfile.arm32v7 diff --git a/Cargo.lock b/Cargo.lock index 934dcf4..3a2db60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1440,7 +1440,7 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pict-rs" -version = "0.2.0" +version = "0.2.1" dependencies = [ "actix-form-data", "actix-fs", diff --git a/Cargo.toml b/Cargo.toml index d5c84d2..30f869d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.2.0" +version = "0.2.1" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" @@ -10,11 +10,6 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -ffmpeg43 = ["ffmpeg", "ffmpeg-next/ffmpeg43"] -ffmpeg42 = ["ffmpeg", "ffmpeg-next/ffmpeg42"] -ffmpeg = ["ffmpeg-next/codec", "ffmpeg-next/filter", "ffmpeg-next/device", "ffmpeg-next/format", "ffmpeg-next/resampling", "ffmpeg-next/postprocessing", "ffmpeg-next/software-resampling", "ffmpeg-next/software-scaling"] - [dependencies] actix-form-data = "0.5.0" actix-fs = { git = "https://git.asonix.dog/asonix/actix-fs", branch = "main" } @@ -44,7 +39,7 @@ uuid = { version = "0.8", features = ["v4"] } [dependencies.ffmpeg-next] version = "4.3.7" default-features = false -features = ["ffmpeg42", "codec", "filter", "device", "format", "resampling", "postprocessing", "software-resampling", "software-scaling"] +features = ["codec", "filter", "device", "format", "resampling", "postprocessing", "software-resampling", "software-scaling"] [dependencies.ffmpeg-sys-next] version = "4.3.5" diff --git a/docker/dev/Dockerfile.arm32v7 b/docker/dev/Dockerfile.arm32v7 new file mode 100644 index 0000000..357eb4d --- /dev/null +++ b/docker/dev/Dockerfile.arm32v7 @@ -0,0 +1,169 @@ +# Basic cross-build environment +FROM ubuntu:20.04 as cross-build + +ARG UID=1000 +ARG GID=1000 + +ENV \ + ARCH=armhf \ + HOST=arm-unknown-linux \ + TOOL=arm-linux-gnueabihf \ + TARGET=armv7-unknown-linux-gnueabihf \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ + CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-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" + +RUN \ + 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 $GID build && \ + adduser \ + --disabled-password \ + --gecos "" \ + --ingroup build \ + --uid $UID \ + --home /opt/build \ + build && \ + dpkg --add-architecture $ARCH && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + pkg-config \ + build-essential \ + crossbuild-essential-$ARCH + +WORKDIR /opt/build + + +# Environment for ImageMagick +FROM cross-build as imagemagick-builder + +RUN \ + apt-get install -y \ + libltdl-dev:$ARCH \ + libjpeg-dev:$ARCH \ + libpng-dev:$ARCH \ + libwebp-dev:$ARCH \ + liblzma-dev:$ARCH \ + libxml2-dev:$ARCH + +ADD --chown=build:build https://imagemagick.org/download/ImageMagick.tar.gz /opt/build/ImageMagick.tar.gz + +USER build + +RUN \ + tar zxf ImageMagick.tar.gz && \ + mv ImageMagick-* ImageMagick + +WORKDIR /opt/build/ImageMagick + +RUN \ + ./configure \ + CC=$TOOL-gcc \ + CXX=$TOOL-g++ \ + --enable-shared \ + --with-modules \ + --disable-static \ + --disable-docs \ + --prefix=/usr/local \ + --with-utilities=no \ + --with-magick-plus-plus=no \ + --without-perl \ + --with-xml=yes \ + --with-png=yes \ + --with-jpeg=yes \ + --with-webp=yes \ + --host=$HOST && \ + make + +USER root + +RUN \ + make install && \ + ldconfig /usr/local/lib + + +# Environment for Rust +FROM cross-build as rust + +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 + +RUN \ + chmod +x rustup.sh && \ + ./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \ + rustup target add $TARGET + +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 \ + libpng16-16:$ARCH \ + libjpeg8:$ARCH \ + libwebp6:$ARCH \ + libwebpdemux2:$ARCH \ + libwebpmux3:$ARCH \ + libgomp1:$ARCH \ + libavcodec-dev:$ARCH \ + libavfilter-dev:$ARCH \ + libavdevice-dev:$ARCH \ + libavformat-dev:$ARCH \ + libavresample-dev:$ARCH \ + libavutil-dev:$ARCH \ + libswscale-dev:$ARCH \ + libswresample-dev:$ARCH \ + ffmpeg && \ + rm -rf /usr/include/x86_64-linux-gnu + +ENV \ + 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 +COPY root/ / + +USER build + +RUN \ + mkdir -p /opt/build/repo + +WORKDIR /opt/build/repo diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 4b65fc7..349b658 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -32,3 +32,19 @@ services: - RUST_LOG=info,pict_rs=debug volumes: - ../../:/opt/build/repo + + pictrs-arm32v7: + build: + context: . + dockerfile: Dockerfile.arm32v7 + args: + UID: "${USER_ID:-1000}" + GID: "${GROUP_ID:-1000}" + ports: + - "8080:8080" + stdin_open: true + tty: true + environment: + - RUST_LOG=info,pict_rs=debug + volumes: + - ../../:/opt/build/repo diff --git a/docker/prod/Dockerfile.arm32v7 b/docker/prod/Dockerfile.arm32v7 new file mode 100644 index 0000000..5c143cc --- /dev/null +++ b/docker/prod/Dockerfile.arm32v7 @@ -0,0 +1,228 @@ +# Target environment +FROM arm32v7/ubuntu:20.04 as target-env + +ENV \ + TARGET=armv7-unknown-linux-gnueabihf \ + BUILD_MODE=release + +# Basic cross-build environment +FROM ubuntu:20.04 as cross-build + +ENV \ + ARCH=armhf \ + HOST=arm-unknown-linux \ + TOOL=arm-linux-gnueabihf \ + TARGET=armv7-unknown-linux-gnueabihf \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ + CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-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" + +RUN \ + 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 && \ + adduser \ + --disabled-password \ + --gecos "" \ + --ingroup build \ + --uid 991 \ + --home /opt/build \ + build && \ + dpkg --add-architecture $ARCH && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + pkg-config \ + build-essential \ + crossbuild-essential-$ARCH + +WORKDIR /opt/build + + +# Environment for ImageMagick +FROM cross-build as imagemagick-builder + +RUN \ + apt-get install -y \ + libltdl-dev:$ARCH \ + libjpeg-dev:$ARCH \ + libpng-dev:$ARCH \ + libwebp-dev:$ARCH \ + liblzma-dev:$ARCH \ + libxml2-dev:$ARCH + +ADD --chown=build:build https://imagemagick.org/download/ImageMagick.tar.gz /opt/build/ImageMagick.tar.gz + +USER build + +RUN \ + tar zxf ImageMagick.tar.gz && \ + mv ImageMagick-* ImageMagick + +WORKDIR /opt/build/ImageMagick + +RUN \ + ./configure \ + CC=$TOOL-gcc \ + CXX=$TOOL-g++ \ + --enable-shared \ + --with-modules \ + --disable-static \ + --disable-docs \ + --prefix=/usr/local \ + --with-utilities=no \ + --with-magick-plus-plus=no \ + --without-perl \ + --with-xml=yes \ + --with-png=yes \ + --with-jpeg=yes \ + --with-webp=yes \ + --host=$HOST && \ + make + +USER root + +RUN \ + make install && \ + ldconfig /usr/local/lib + + +# Environment for Rust +FROM cross-build as rust + +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 + +RUN \ + chmod +x rustup.sh && \ + ./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \ + rustup target add $TARGET + +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 \ + libavcodec-dev:$ARCH \ + libavfilter-dev:$ARCH \ + libavdevice-dev:$ARCH \ + libavformat-dev:$ARCH \ + libavresample-dev:$ARCH \ + libavutil-dev:$ARCH \ + libswscale-dev:$ARCH \ + libswresample-dev:$ARCH \ + llvm-dev \ + libclang-dev \ + clang && \ + rm -rf /usr/include/x86_64-linux-gnu + +ENV \ + 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 + +ARG TAG=main +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 + +RUN \ + tar zxf $TAG.tar.gz + +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 + +ARG UID=991 +ARG GID=991 + +RUN \ + addgroup --gid $GID pictrs && \ + adduser \ + --disabled-password \ + --gecos "" \ + --ingroup pictrs \ + --uid $UID \ + --home /opt/pict-rs \ + pictrs && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + libgexiv2-2 \ + libpng16-16 \ + libjpeg8 \ + libwebp6 \ + libwebpdemux2 \ + libwebpmux3 \ + libltdl7 \ + libgomp1 \ + libxml2 \ + libavcodec58 \ + libavfilter7 \ + libavdevice58 \ + libavformat58 \ + libavresample4 \ + libavutil56 \ + libswscale5 \ + libswresample3 \ + 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 + +ENV \ + LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + +RUN \ + chown pictrs:pictrs /mnt + +VOLUME /mnt +WORKDIR /opt/pict-rs +USER pictrs +EXPOSE 8080 +ENTRYPOINT ["/usr/bin/tini", "--"] +CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/deploy.sh b/docker/prod/deploy.sh index b023729..5bfb7ba 100755 --- a/docker/prod/deploy.sh +++ b/docker/prod/deploy.sh @@ -60,8 +60,9 @@ git tag $new_tag git push origin $new_tag git push -# Build for arm64v8 and amd64 +# Build for arm64v8, arm32v7 and amd64 build_image $new_tag arm64v8 +build_image $new_tag arm32v7 build_image $new_tag amd64 # Build for other archs diff --git a/docker/prod/manifest.sh b/docker/prod/manifest.sh index c4aba97..905205c 100755 --- a/docker/prod/manifest.sh +++ b/docker/prod/manifest.sh @@ -25,11 +25,15 @@ set -xe docker manifest create asonix/pictrs:$new_tag \ -a asonix/pictrs:arm64v8-$new_tag \ + -a asonix/pictrs:arm32v7-$new_tag \ -a asonix/pictrs:amd64-$new_tag docker manifest annotate asonix/pictrs:$new_tag \ asonix/pictrs:arm64v8-$new_tag --os linux --arch arm64 --variant v8 +docker manifest annotate asonix/pictrs:$new_tag \ + asonix/pictrs:arm32v7-$new_tag --os linux --arch arm --variant v7 + docker manifest annotate asonix/pictrs:$new_tag \ asonix/pictrs:amd64-$new_tag --os linux --arch amd64