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

Version v0.3.0-alpha.13-shell-out

This commit is contained in:
Aode (lion) 2021-08-28 17:50:56 -05:00
parent edd6bb4a60
commit 57a036dacd
7 changed files with 163 additions and 559 deletions

19
Cargo.lock generated
View file

@ -85,7 +85,7 @@ dependencies = [
"serde", "serde",
"sha-1", "sha-1",
"smallvec", "smallvec",
"time", "time 0.2.27",
"tokio", "tokio",
] ]
@ -233,7 +233,7 @@ dependencies = [
"serde_urlencoded", "serde_urlencoded",
"smallvec", "smallvec",
"socket2", "socket2",
"time", "time 0.2.27",
"url", "url",
] ]
@ -995,7 +995,7 @@ dependencies = [
[[package]] [[package]]
name = "pict-rs" name = "pict-rs"
version = "0.3.0-alpha.12" version = "0.3.0-alpha.13"
dependencies = [ dependencies = [
"actix-form-data", "actix-form-data",
"actix-fs", "actix-fs",
@ -1016,7 +1016,7 @@ dependencies = [
"sled", "sled",
"structopt", "structopt",
"thiserror", "thiserror",
"time", "time 0.3.2",
"tokio", "tokio",
"tracing", "tracing",
"tracing-futures", "tracing-futures",
@ -1530,7 +1530,6 @@ checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242"
dependencies = [ dependencies = [
"const_fn", "const_fn",
"libc", "libc",
"serde",
"standback", "standback",
"stdweb", "stdweb",
"time-macros", "time-macros",
@ -1538,6 +1537,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "time"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e0a10c9a9fb3a5dce8c2239ed670f1a2569fcf42da035f5face1b19860d52b0"
dependencies = [
"libc",
"serde",
]
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.1.1" version = "0.1.1"

View file

@ -1,7 +1,7 @@
[package] [package]
name = "pict-rs" name = "pict-rs"
description = "A simple image hosting service" description = "A simple image hosting service"
version = "0.3.0-alpha.12" version = "0.3.0-alpha.13"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
license = "AGPL-3.0" license = "AGPL-3.0"
readme = "README.md" readme = "README.md"
@ -30,7 +30,7 @@ sha2 = "0.9.0"
sled = { version = "0.34.6" } sled = { version = "0.34.6" }
structopt = "0.3.14" structopt = "0.3.14"
thiserror = "1.0" 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"] } tokio = { version = "1", default-features = false, features = ["io-util", "process", "sync"] }
tracing = "0.1.15" tracing = "0.1.15"
tracing-futures = "0.2.4" tracing-futures = "0.2.4"

View file

@ -1,165 +1,55 @@
# Target environment # cross-build environment
FROM amd64/ubuntu:20.04 as target-env FROM rustembedded/cross:x86_64-unknown-linux-musl AS x86_64-builder
ENV \ ARG UID=991
TARGET=x86_64-unknown-linux-gnu \ ARG GID=991
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
ENV \ ENV \
TOOLCHAIN=stable \ TOOLCHAIN=stable \
DEBIAN_FRONTEND=noninteractive \ TARGET=x86_64-unknown-linux-musl \
PKG_CONFIG_ALLOW_CROSS=1 \ TOOL=x86_64-linux-musl \
PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/pkgconfig \ BUILD_MODE=release
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 \ 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 && \ apt-get update && \
sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list && \ apt-get upgrade -y
addgroup --gid 991 build && \
RUN \
addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--ingroup build \ --ingroup build \
--uid 991 \ --uid "${UID}" \
--home /opt/build \ --home /opt/build \
build && \ build
dpkg --add-architecture $ARCH && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
pkg-config \
build-essential \
crossbuild-essential-$ARCH
ADD https://sh.rustup.rs /opt/build/rustup.sh
RUN \
chown -R build:build /opt/build
USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 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 \ 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
USER root # build script
FROM x86_64-builder as builder
# 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
ARG TAG=main ARG TAG=main
ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs 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 USER build
@ -169,55 +59,27 @@ RUN \
WORKDIR /opt/build/pict-rs WORKDIR /opt/build/pict-rs
RUN \ RUN \
USER=build cargo build --target=$TARGET --$BUILD_MODE && \ USER=build cargo build --release --target $TARGET --$BUILD_MODE && \
$TOOL-strip /opt/build/pict-rs/target/$TARGET/$BUILD_MODE/pict-rs $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY
# production environment
# Producing target binary FROM amd64/alpine:3.14
FROM target-env
ARG UID=991 ARG UID=991
ARG GID=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 \ RUN \
addgroup --gid $GID pictrs && \ apk add tini ffmpeg imagemagick exiv2 && \
adduser \ addgroup -g $GID pictrs && \
--disabled-password \ adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs
--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
RUN \ RUN \
chown pictrs:pictrs /mnt chown -R pictrs:pictrs /mnt
COPY root/ / COPY root/ /
@ -225,5 +87,5 @@ VOLUME /mnt
WORKDIR /opt/pict-rs WORKDIR /opt/pict-rs
USER pictrs USER pictrs
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"]

View file

@ -1,166 +1,55 @@
# Target environment # cross-build environment
FROM arm32v7/ubuntu:20.04 as target-env FROM rustembedded/cross:arm-unknown-linux-musleabihf AS arm32v7-builder
ENV \ ARG UID=991
TARGET=armv7-unknown-linux-gnueabihf \ ARG GID=991
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 \ ENV \
TOOLCHAIN=stable \ TOOLCHAIN=stable \
DEBIAN_FRONTEND=noninteractive \ TARGET=arm-unknown-linux-musleabihf \
PKG_CONFIG_ALLOW_CROSS=1 \ TOOL=arm-linux-musleabihf \
PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/pkgconfig \ BUILD_MODE=release
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 \ 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 && \ apt-get update && \
sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list && \ apt-get upgrade -y
addgroup --gid 991 build && \
RUN \
addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--ingroup build \ --ingroup build \
--uid 991 \ --uid "${UID}" \
--home /opt/build \ --home /opt/build \
build && \ build
dpkg --add-architecture $ARCH && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
pkg-config \
build-essential \
crossbuild-essential-$ARCH
ADD https://sh.rustup.rs /opt/build/rustup.sh
RUN \
chown -R build:build /opt/build
USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 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 \ 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
USER root # build script
FROM arm32v7-builder as builder
# 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 TAG=main
ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs 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 USER build
@ -170,55 +59,27 @@ RUN \
WORKDIR /opt/build/pict-rs WORKDIR /opt/build/pict-rs
RUN \ RUN \
USER=build cargo build --target=$TARGET --$BUILD_MODE && \ USER=build cargo build --release --target $TARGET --$BUILD_MODE && \
$TOOL-strip /opt/build/pict-rs/target/$TARGET/$BUILD_MODE/pict-rs $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY
# production environment
# Producing target binary FROM amd64/alpine:3.14
FROM target-env
ARG UID=991 ARG UID=991
ARG GID=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 \ RUN \
addgroup --gid $GID pictrs && \ apk add tini ffmpeg imagemagick exiv2 && \
adduser \ addgroup -g $GID pictrs && \
--disabled-password \ adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs
--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
RUN \ RUN \
chown pictrs:pictrs /mnt chown -R pictrs:pictrs /mnt
COPY root/ / COPY root/ /
@ -226,5 +87,5 @@ VOLUME /mnt
WORKDIR /opt/pict-rs WORKDIR /opt/pict-rs
USER pictrs USER pictrs
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"]

View file

@ -1,166 +1,55 @@
# Target environment # cross-build environment
FROM arm64v8/ubuntu:20.04 as target-env FROM rustembedded/cross:aarch64-unknown-linux-musl AS aarch64-builder
ENV \ ARG UID=991
TARGET=aarch64-unknown-linux-gnu \ ARG GID=991
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 \ ENV \
TOOLCHAIN=stable \ TOOLCHAIN=stable \
DEBIAN_FRONTEND=noninteractive \ TARGET=aarch64-unknown-linux-musl \
PKG_CONFIG_ALLOW_CROSS=1 \ TOOL=aarch64-linux-musl \
PKG_CONFIG_PATH=/usr/lib/$TOOL/pkgconfig:/usr/lib/pkgconfig \ BUILD_MODE=release
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 \ 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 && \ apt-get update && \
sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list && \ apt-get upgrade -y
addgroup --gid 991 build && \
RUN \
addgroup --gid "${GID}" build && \
adduser \ adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--ingroup build \ --ingroup build \
--uid 991 \ --uid "${UID}" \
--home /opt/build \ --home /opt/build \
build && \ build
dpkg --add-architecture $ARCH && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
pkg-config \
build-essential \
crossbuild-essential-$ARCH
ADD https://sh.rustup.rs /opt/build/rustup.sh
RUN \
chown -R build:build /opt/build
USER build
WORKDIR /opt/build WORKDIR /opt/build
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 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 \ 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
USER root # build script
FROM aarch64-builder as builder
# 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 TAG=main
ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/pict-rs 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 USER build
@ -170,55 +59,27 @@ RUN \
WORKDIR /opt/build/pict-rs WORKDIR /opt/build/pict-rs
RUN \ RUN \
USER=build cargo build --target=$TARGET --$BUILD_MODE && \ USER=build cargo build --release --target $TARGET --$BUILD_MODE && \
$TOOL-strip /opt/build/pict-rs/target/$TARGET/$BUILD_MODE/pict-rs $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY
# production environment
# Producing target binary FROM amd64/alpine:3.14
FROM target-env
ARG UID=991 ARG UID=991
ARG GID=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 \ RUN \
addgroup --gid $GID pictrs && \ apk add tini ffmpeg imagemagick exiv2 && \
adduser \ addgroup -g $GID pictrs && \
--disabled-password \ adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs
--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
RUN \ RUN \
chown pictrs:pictrs /mnt chown -R pictrs:pictrs /mnt
COPY root/ / COPY root/ /
@ -226,5 +87,5 @@ VOLUME /mnt
WORKDIR /opt/pict-rs WORKDIR /opt/pict-rs
USER pictrs USER pictrs
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"]

View file

@ -12,31 +12,41 @@ function print_help() {
echo "deploy.sh" echo "deploy.sh"
echo "" echo ""
echo "Usage:" echo "Usage:"
echo " deploy.sh [tag] [branch]" echo " deploy.sh [tag] [branch] [push]"
echo "" echo ""
echo "Args:" echo "Args:"
echo " tag: The git tag to be applied to the repository and docker build" 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 " 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() { function build_image() {
tag=$1 tag=$1
arch=$2 arch=$2
push=$3
./build-image.sh asonix/pictrs $tag $arch ./build-image.sh asonix/pictrs $tag $arch
sudo docker tag asonix/pictrs:$arch-$tag asonix/pictrs:$arch-latest sudo docker tag asonix/pictrs:$arch-$tag asonix/pictrs:$arch-latest
if [ "$push" == "true" ]; then
sudo docker push asonix/pictrs:$arch-$tag sudo docker push asonix/pictrs:$arch-$tag
sudo docker push asonix/pictrs:$arch-latest sudo docker push asonix/pictrs:$arch-latest
fi
} }
# Creating the new tag # Creating the new tag
new_tag="$1" new_tag="$1"
branch="$2" branch="$2"
push=$3
require "$new_tag" "tag" require "$new_tag" "tag"
require "$branch" "branch" require "$branch" "branch"
require "$push" "push"
if ! sudo docker run --rm -it arm64v8/alpine:3.11 /bin/sh -c 'echo "docker is configured correctly"' if ! sudo docker run --rm -it arm64v8/alpine:3.11 /bin/sh -c 'echo "docker is configured correctly"'
then then
@ -51,7 +61,6 @@ git checkout $branch
# Changing the docker-compose prod # Changing the docker-compose prod
sed -i "s/asonix\/pictrs:.*/asonix\/pictrs:$new_tag/" docker-compose.yml sed -i "s/asonix\/pictrs:.*/asonix\/pictrs:$new_tag/" docker-compose.yml
git add ../prod/docker-compose.yml git add ../prod/docker-compose.yml
# The commit # The commit
git commit -m"Version $new_tag" git commit -m"Version $new_tag"
git tag $new_tag git tag $new_tag
@ -61,12 +70,14 @@ git push origin $new_tag
git push git push
# Build for arm64v8, arm32v7 and amd64 # Build for arm64v8, arm32v7 and amd64
build_image $new_tag arm64v8 build_image $new_tag arm64v8 $push
build_image $new_tag arm32v7 build_image $new_tag arm32v7 $push
build_image $new_tag amd64 build_image $new_tag amd64 $push
# Build for other archs # Build for other archs
# TODO # TODO
if [ "$push" == "true" ]; then
./manifest.sh $new_tag ./manifest.sh $new_tag
./manifest.sh latest ./manifest.sh latest
fi

View file

@ -2,7 +2,7 @@ version: '3.3'
services: services:
pictrs: pictrs:
image: asonix/pictrs:v0.3.0-alpha.12-r0 image: asonix/pictrs:v0.3.0-alpha.13-shell-out
ports: ports:
- "127.0.0.1:8080:8080" - "127.0.0.1:8080:8080"
restart: always restart: always