diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile new file mode 100644 index 0000000..2c47d18 --- /dev/null +++ b/docker/prod/Dockerfile @@ -0,0 +1,48 @@ +ARG REPO_ARCH=amd64 + +# cross-build environment +FROM asonix/$REPO_ARCH-latest AS builder + +ARG TAG=main +ARG BINARY=pict-rs +ARG PROJECT=pict-rs +ARG GIT_REPOSITORY=https://git.asonix.dog/asonix/$PROJECT + +ENV\ + BINARY=${BINARY} + +ADD \ + --chown=build:build \ + $GIT_REPOSITORY/archive/$TAG.tar.gz \ + /opt/build/repo.tar.gz + +RUN \ + tar zxf repo.tar.gz + +WORKDIR /opt/build/$PROJECT + +RUN \ + build + +# production environment +FROM asonix/rust-runner:$REPO_ARCH-latest + +USER root + +COPY --from=builder \ + /opt/build/binary \ + /usr/local/bin/application + +RUN \ + apk add ffmpeg imagemagick exiftool + +RUN \ + chown -R app:app /mnt + +COPY root/ / + +VOLUME /mnt +USER app +EXPOSE 8080 +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["/usr/local/bin/application", "-p", "/mnt"] diff --git a/docker/prod/Dockerfile.amd64 b/docker/prod/Dockerfile.amd64 deleted file mode 100644 index d8b2a1d..0000000 --- a/docker/prod/Dockerfile.amd64 +++ /dev/null @@ -1,92 +0,0 @@ -# cross-build environment -FROM rustembedded/cross:x86_64-unknown-linux-musl AS x86_64-builder - -ARG UID=991 -ARG GID=991 - -ENV \ - TOOLCHAIN=stable \ - TARGET=x86_64-unknown-linux-musl \ - TOOL=x86_64-linux-musl \ - BUILD_MODE=release - -RUN \ - apt-get update && \ - apt-get upgrade -y - -RUN \ - 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=/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 - -# 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 - -USER build - -RUN \ - tar zxf $TAG.tar.gz - -WORKDIR /opt/build/pict-rs - -RUN \ - USER=build cargo build --target $TARGET --$BUILD_MODE && \ - $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# production environment -FROM amd64/alpine:3.14 - -ARG UID=991 -ARG GID=991 -ARG BINARY=pict-rs -ARG BUILD_MODE=release - -COPY --from=builder \ - /opt/build/pict-rs/target/x86_64-unknown-linux-musl/$BUILD_MODE/$BINARY \ - /usr/local/bin/$BINARY - -RUN \ - apk add tini ffmpeg imagemagick exiftool && \ - addgroup -g $GID pictrs && \ - adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs - -RUN \ - chown -R pictrs:pictrs /mnt - -COPY root/ / - -VOLUME /mnt -WORKDIR /opt/pict-rs -USER pictrs -EXPOSE 8080 -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/Dockerfile.arm32v7 b/docker/prod/Dockerfile.arm32v7 deleted file mode 100644 index 7597a9f..0000000 --- a/docker/prod/Dockerfile.arm32v7 +++ /dev/null @@ -1,92 +0,0 @@ -# cross-build environment -FROM rustembedded/cross:arm-unknown-linux-musleabihf AS arm32v7-builder - -ARG UID=991 -ARG GID=991 - -ENV \ - TOOLCHAIN=stable \ - TARGET=arm-unknown-linux-musleabihf \ - TOOL=arm-linux-musleabihf \ - BUILD_MODE=release - -RUN \ - apt-get update && \ - apt-get upgrade -y - -RUN \ - 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=/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 - -# 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 - -USER build - -RUN \ - tar zxf $TAG.tar.gz - -WORKDIR /opt/build/pict-rs - -RUN \ - USER=build cargo build --target $TARGET --$BUILD_MODE && \ - $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# production environment -FROM arm32v7/alpine:3.14 - -ARG UID=991 -ARG GID=991 -ARG BINARY=pict-rs -ARG BUILD_MODE=release - -COPY --from=builder \ - /opt/build/pict-rs/target/arm-unknown-linux-musleabihf/$BUILD_MODE/$BINARY \ - /usr/local/bin/$BINARY - -RUN \ - apk add tini ffmpeg imagemagick exiftool && \ - addgroup -g $GID pictrs && \ - adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs - -RUN \ - chown -R pictrs:pictrs /mnt - -COPY root/ / - -VOLUME /mnt -WORKDIR /opt/pict-rs -USER pictrs -EXPOSE 8080 -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/Dockerfile.arm64v8 b/docker/prod/Dockerfile.arm64v8 deleted file mode 100644 index 53653bd..0000000 --- a/docker/prod/Dockerfile.arm64v8 +++ /dev/null @@ -1,92 +0,0 @@ -# cross-build environment -FROM rustembedded/cross:aarch64-unknown-linux-musl AS aarch64-builder - -ARG UID=991 -ARG GID=991 - -ENV \ - TOOLCHAIN=stable \ - TARGET=aarch64-unknown-linux-musl \ - TOOL=aarch64-linux-musl \ - BUILD_MODE=release - -RUN \ - apt-get update && \ - apt-get upgrade -y - -RUN \ - 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=/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 - -# 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 - -USER build - -RUN \ - tar zxf $TAG.tar.gz - -WORKDIR /opt/build/pict-rs - -RUN \ - USER=build cargo build --target $TARGET --$BUILD_MODE && \ - $TOOL-strip target/$TARGET/$BUILD_MODE/$BINARY - -# production environment -FROM arm64v8/alpine:3.14 - -ARG UID=991 -ARG GID=991 -ARG BINARY=pict-rs -ARG BUILD_MODE=release - -COPY --from=builder \ - /opt/build/pict-rs/target/aarch64-unknown-linux-musl/$BUILD_MODE/$BINARY \ - /usr/local/bin/$BINARY - -RUN \ - apk add tini ffmpeg imagemagick exiftool && \ - addgroup -g $GID pictrs && \ - adduser -D -G pictrs -u $UID -g "" -h /opt/pict-rs pictrs - -RUN \ - chown -R pictrs:pictrs /mnt - -COPY root/ / - -VOLUME /mnt -WORKDIR /opt/pict-rs -USER pictrs -EXPOSE 8080 -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/prod/build-image.sh b/docker/prod/build-image.sh index 73e8fdd..2782f1e 100755 --- a/docker/prod/build-image.sh +++ b/docker/prod/build-image.sh @@ -31,6 +31,7 @@ require "$ARCH" arch sudo docker build \ --pull \ --build-arg TAG=$TAG \ + --build-arg REPO_ARCH=$ARCH \ -t $REPO:$ARCH-$TAG \ - -f Dockerfile.$ARCH \ + -f Dockerfile \ . diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index cf6758e..9859f32 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.26 + image: asonix/pictrs:v0.3.0-alpha.26-r0 ports: - "127.0.0.1:8080:8080" restart: always