diff --git a/Cargo.lock b/Cargo.lock index ba0d9d8..4b058ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,7 +85,7 @@ dependencies = [ "serde", "sha-1", "smallvec", - "time", + "time 0.2.27", "tokio", ] @@ -233,7 +233,7 @@ dependencies = [ "serde_urlencoded", "smallvec", "socket2", - "time", + "time 0.2.27", "url", ] @@ -995,7 +995,7 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.3.0-alpha.12" +version = "0.3.0-alpha.13" dependencies = [ "actix-form-data", "actix-fs", @@ -1016,7 +1016,7 @@ dependencies = [ "sled", "structopt", "thiserror", - "time", + "time 0.3.2", "tokio", "tracing", "tracing-futures", @@ -1530,7 +1530,6 @@ checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" dependencies = [ "const_fn", "libc", - "serde", "standback", "stdweb", "time-macros", @@ -1538,6 +1537,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0a10c9a9fb3a5dce8c2239ed670f1a2569fcf42da035f5face1b19860d52b0" +dependencies = [ + "libc", + "serde", +] + [[package]] name = "time-macros" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index dbc3250..c8a2c7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.3.0-alpha.12" +version = "0.3.0-alpha.13" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" @@ -30,7 +30,7 @@ sha2 = "0.9.0" sled = { version = "0.34.6" } structopt = "0.3.14" thiserror = "1.0" -time = { version = "0.2.23", features = ["serde"] } +time = { version = "0.3.0", features = ["serde"] } tokio = { version = "1", default-features = false, features = ["io-util", "process", "sync"] } tracing = "0.1.15" tracing-futures = "0.2.4" diff --git a/docker/prod/Dockerfile.amd64 b/docker/prod/Dockerfile.amd64 index f668588..947d55b 100644 --- a/docker/prod/Dockerfile.amd64 +++ b/docker/prod/Dockerfile.amd64 @@ -1,165 +1,55 @@ -# Target environment -FROM amd64/ubuntu:20.04 as target-env +# cross-build environment +FROM rustembedded/cross:x86_64-unknown-linux-musl AS x86_64-builder -ENV \ - TARGET=x86_64-unknown-linux-gnu \ - BUILD_MODE=release - -# Basic cross-build environment -FROM ubuntu:20.04 as cross-build - -ENV \ - ARCH=amd64 \ - HOST=x86_64-unknown-linux \ - TOOL=x86_64-linux-gnu \ - TARGET=x86_64-unknown-linux-gnu \ - CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \ - CC_X86_64_UNKNOWN_LINUX_GNU=x86_64-linux-gnu-gcc \ - CXX_X86_64_UNKNOWN_LINUX_GNU=x86_64-linux-gnu-g++ \ - BUILD_MODE=release +ARG UID=991 +ARG GID=991 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" + TARGET=x86_64-unknown-linux-musl \ + TOOL=x86_64-linux-musl \ + BUILD_MODE=release 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 && \ + apt-get update && \ + apt-get upgrade -y + +RUN \ + addgroup --gid "${GID}" build && \ adduser \ --disabled-password \ --gecos "" \ --ingroup build \ - --uid 991 \ + --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 + build +ADD https://sh.rustup.rs /opt/build/rustup.sh + +RUN \ + chown -R build:build /opt/build + +USER build 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 +ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 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 - -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 +# build script +FROM x86_64-builder as builder ARG TAG=main ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs +ARG BINARY=pict-rs -ADD --chown=build:build $GIT_REPOSITORY/archive/$TAG.tar.gz /opt/build/$TAG.tar.gz +ADD \ + --chown=build:build \ + $GIT_REPOSITORY/archive/$TAG.tar.gz \ + /opt/build/$TAG.tar.gz USER build @@ -169,55 +59,27 @@ RUN \ 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 + USER=build cargo build --release --target $TARGET --$BUILD_MODE && \ + $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# Producing target binary -FROM target-env +# production environment +FROM amd64/alpine:3.14 ARG UID=991 ARG GID=991 +ARG BINARY=pict-rs + +COPY --from=builder \ + /opt/build/repo/target/x86_64-unknown-linux-musl/release/$BINARY \ + /usr/local/bin/$BINARY 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 --no-install-recommends \ - 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 + apk add tini ffmpeg imagemagick exiv2 && \ + addgroup -g $GID pictrs && \ + adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs RUN \ - chown pictrs:pictrs /mnt + chown -R pictrs:pictrs /mnt COPY root/ / @@ -225,5 +87,5 @@ VOLUME /mnt WORKDIR /opt/pict-rs USER pictrs EXPOSE 8080 -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/sbin/tini", "--"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/Dockerfile.arm32v7 b/docker/prod/Dockerfile.arm32v7 index d4209da..ac5d3c9 100644 --- a/docker/prod/Dockerfile.arm32v7 +++ b/docker/prod/Dockerfile.arm32v7 @@ -1,166 +1,55 @@ -# Target environment -FROM arm32v7/ubuntu:20.04 as target-env +# cross-build environment +FROM rustembedded/cross:arm-unknown-linux-musleabihf AS arm32v7-builder -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 +ARG UID=991 +ARG GID=991 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" + TARGET=arm-unknown-linux-musleabihf \ + TOOL=arm-linux-musleabihf \ + BUILD_MODE=release 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 && \ + apt-get update && \ + apt-get upgrade -y + +RUN \ + addgroup --gid "${GID}" build && \ adduser \ --disabled-password \ --gecos "" \ --ingroup build \ - --uid 991 \ + --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 + build +ADD https://sh.rustup.rs /opt/build/rustup.sh + +RUN \ + chown -R build:build /opt/build + +USER build 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 +ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 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 +# build script +FROM arm32v7-builder as builder ARG TAG=main ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs +ARG BINARY=pict-rs -ADD --chown=build:build $GIT_REPOSITORY/archive/$TAG.tar.gz /opt/build/$TAG.tar.gz +ADD \ + --chown=build:build \ + $GIT_REPOSITORY/archive/$TAG.tar.gz \ + /opt/build/$TAG.tar.gz USER build @@ -170,55 +59,27 @@ RUN \ 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 + USER=build cargo build --release --target $TARGET --$BUILD_MODE && \ + $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# Producing target binary -FROM target-env +# production environment +FROM amd64/alpine:3.14 ARG UID=991 ARG GID=991 +ARG BINARY=pict-rs + +COPY --from=builder \ + /opt/build/repo/target/arm-unknown-linux-musleabihf/release/$BINARY \ + /usr/local/bin/$BINARY 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 --no-install-recommends \ - 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 + apk add tini ffmpeg imagemagick exiv2 && \ + addgroup -g $GID pictrs && \ + adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs RUN \ - chown pictrs:pictrs /mnt + chown -R pictrs:pictrs /mnt COPY root/ / @@ -226,5 +87,5 @@ VOLUME /mnt WORKDIR /opt/pict-rs USER pictrs EXPOSE 8080 -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/sbin/tini", "--"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/Dockerfile.arm64v8 b/docker/prod/Dockerfile.arm64v8 index 931fdd2..6994ca1 100644 --- a/docker/prod/Dockerfile.arm64v8 +++ b/docker/prod/Dockerfile.arm64v8 @@ -1,166 +1,55 @@ -# Target environment -FROM arm64v8/ubuntu:20.04 as target-env +# cross-build environment +FROM rustembedded/cross:aarch64-unknown-linux-musl AS aarch64-builder -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 +ARG UID=991 +ARG GID=991 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" + TARGET=aarch64-unknown-linux-musl \ + TOOL=aarch64-linux-musl \ + BUILD_MODE=release 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 && \ + apt-get update && \ + apt-get upgrade -y + +RUN \ + addgroup --gid "${GID}" build && \ adduser \ --disabled-password \ --gecos "" \ --ingroup build \ - --uid 991 \ + --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 + build +ADD https://sh.rustup.rs /opt/build/rustup.sh + +RUN \ + chown -R build:build /opt/build + +USER build 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 +ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 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 +# build script +FROM aarch64-builder as builder ARG TAG=main ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs +ARG BINARY=pict-rs -ADD --chown=build:build $GIT_REPOSITORY/archive/$TAG.tar.gz /opt/build/$TAG.tar.gz +ADD \ + --chown=build:build \ + $GIT_REPOSITORY/archive/$TAG.tar.gz \ + /opt/build/$TAG.tar.gz USER build @@ -170,55 +59,27 @@ RUN \ 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 + USER=build cargo build --release --target $TARGET --$BUILD_MODE && \ + $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# Producing target binary -FROM target-env +# production environment +FROM amd64/alpine:3.14 ARG UID=991 ARG GID=991 +ARG BINARY=pict-rs + +COPY --from=builder \ + /opt/build/repo/target/aarch64-unknown-linux-musl/release/$BINARY \ + /usr/local/bin/$BINARY 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 --no-install-recommends \ - 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 + apk add tini ffmpeg imagemagick exiv2 && \ + addgroup -g $GID pictrs && \ + adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs RUN \ - chown pictrs:pictrs /mnt + chown -R pictrs:pictrs /mnt COPY root/ / @@ -226,5 +87,5 @@ VOLUME /mnt WORKDIR /opt/pict-rs USER pictrs EXPOSE 8080 -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/sbin/tini", "--"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/deploy.sh b/docker/prod/deploy.sh index b810c0f..42763e7 100755 --- a/docker/prod/deploy.sh +++ b/docker/prod/deploy.sh @@ -12,31 +12,41 @@ function print_help() { echo "deploy.sh" echo "" echo "Usage:" - echo " deploy.sh [tag] [branch]" + echo " deploy.sh [tag] [branch] [push]" echo "" echo "Args:" echo " tag: The git tag to be applied to the repository and docker build" echo " branch: The git branch to use for tagging and publishing" + echo " push: Whether or not to push the image" + echo "" + echo "Examples:" + echo " ./deploy.sh v0.3.0-alpha.13 main true" + echo " ./deploy.sh v0.3.0-alpha.13-shell-out asonix/shell-out false" } function build_image() { tag=$1 arch=$2 + push=$3 ./build-image.sh asonix/pictrs $tag $arch sudo docker tag asonix/pictrs:$arch-$tag asonix/pictrs:$arch-latest - sudo docker push asonix/pictrs:$arch-$tag - sudo docker push asonix/pictrs:$arch-latest + if [ "$push" == "true" ]; then + sudo docker push asonix/pictrs:$arch-$tag + sudo docker push asonix/pictrs:$arch-latest + fi } # Creating the new tag new_tag="$1" branch="$2" +push=$3 require "$new_tag" "tag" require "$branch" "branch" +require "$push" "push" if ! sudo docker run --rm -it arm64v8/alpine:3.11 /bin/sh -c 'echo "docker is configured correctly"' then @@ -51,7 +61,6 @@ git checkout $branch # Changing the docker-compose prod sed -i "s/asonix\/pictrs:.*/asonix\/pictrs:$new_tag/" docker-compose.yml git add ../prod/docker-compose.yml - # The commit git commit -m"Version $new_tag" git tag $new_tag @@ -61,12 +70,14 @@ git push origin $new_tag git push # Build for arm64v8, arm32v7 and amd64 -build_image $new_tag arm64v8 -build_image $new_tag arm32v7 -build_image $new_tag amd64 +build_image $new_tag arm64v8 $push +build_image $new_tag arm32v7 $push +build_image $new_tag amd64 $push # Build for other archs # TODO -./manifest.sh $new_tag -./manifest.sh latest +if [ "$push" == "true" ]; then + ./manifest.sh $new_tag + ./manifest.sh latest +fi diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index e2e1fac..cfae8e2 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.3' services: pictrs: - image: asonix/pictrs:v0.3.0-alpha.12-r0 + image: asonix/pictrs:v0.3.0-alpha.13-shell-out ports: - "127.0.0.1:8080:8080" restart: always