diff --git a/.dockerignore b/.dockerignore index 91b2b63..ca9f25a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -**/LICENSE **/*.md **/.hadolint.yml **/node_modules diff --git a/.hadolint.yml b/.hadolint.yml new file mode 100644 index 0000000..4ac7429 --- /dev/null +++ b/.hadolint.yml @@ -0,0 +1,8 @@ +ignored: + - DL3041 # Specify version with `dnf install -y -`. + - DL3042 # Avoid use of cache directory with pip. Use `pip install --no-cache-dir ` + - DL4006 # Set the SHELL option -o pipefail before RUN with a pipe in it + - DL3013 # Pin versions in pip. Instead of `pip install ` use `pip install ==` + - SC2015 # Note that A && B || C is not if-then-else. C may run when A is true. + - DL3006 # Always tag the version of an image explicitly + - DL3018 # Pin versions in apk add. Instead of `apk add ` use `apk add =` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ca615fc..f340276 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,53 @@ # syntax=docker/dockerfile:1 ARG UID=1001 +ARG VERSION=EDGE +ARG RELEASE=0 +######################################## +# Compress stage +######################################## +FROM minio/mc as mc + +FROM alpine:3.19 as compress + +# RUN mount cache for multi-arch: https://github.com/docker/buildx/issues/549#issuecomment-1788297892 +ARG TARGETARCH +ARG TARGETVARIANT + +# Compress mc and dumb-init with upx +RUN --mount=type=cache,id=apk-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apk \ + --mount=from=mc,source=/usr/bin/mc,target=/tmp/mc,rw \ + apk update && apk add -u \ + -X "https://dl-cdn.alpinelinux.org/alpine/edge/community" \ + upx dumb-init && \ + cp /tmp/mc / && \ + #! UPX will skip small files and large files + # https://github.com/upx/upx/blob/5bef96806860382395d9681f3b0c69e0f7e853cf/src/p_unix.cpp#L80 + # https://github.com/upx/upx/blob/b0dc48316516d236664dfc5f1eb5f2de00fc0799/src/conf.h#L134 + upx --best --lzma /mc || true; \ + upx --best --lzma /usr/bin/dumb-init || true; \ + apk del upx + +######################################## +# Final stage +######################################## FROM busybox:1 as final ARG UID -RUN install -d -m 774 -o $UID -g 0 /app && \ +# Create directories with correct permissions +RUN install -d -m 775 -o $UID -g 0 /app && \ + install -d -m 775 -o $UID -g 0 /licenses \ install -d -m 774 -o $UID -g 0 /.mc -WORKDIR /app -COPY --link --from=minio/mc:latest /usr/bin/mc /bin/mc -COPY --link --from=minio/mc:latest /etc/pki/ca-trust/extracted/pem/ /etc/pki/ca-trust/extracted/pem/ +# Copy licenses (OpenShift Policy) +COPY --link --chown=$UID:0 --chmod=775 LICENSE /licenses/LICENSE -ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /bin/dumb-init -RUN chmod +x /bin/dumb-init +COPY --link --chown=$UID:0 --chmod=775 --from=compress /mc /usr/bin/dumb-init /usr/bin/ +COPY --link --chown=$UID:0 --chmod=775 --from=mc /etc/pki/ca-trust/extracted/pem/ /etc/pki/ca-trust/extracted/pem/ # Copy the bash script into the container -COPY --chown=$UID:0 --chmod=774 \ - s3-uploader.sh . +COPY --link --chown=$UID:0 --chmod=775 s3-uploader.sh /app/ # Set environment variables ENV S3_ENDPOINT="" @@ -26,7 +56,28 @@ ENV S3_SECRET_KEY="" ENV DESTINATION_BUCKET="" ENV DESTINATION_DIRECTORY="" -USER $UID +WORKDIR /app + VOLUME [ "/sharedvolume" ] -ENTRYPOINT [ "dumb-init", "--", "./s3-uploader.sh" ] \ No newline at end of file +USER $UID + +STOPSIGNAL SIGINT + +ENTRYPOINT [ "dumb-init", "--", "./s3-uploader.sh" ] + +ARG VERSION +ARG RELEASE +LABEL name="Recorder-moe/s3-uploader" \ + # Authors for Recorder-moe + vendor="Recorder-moe" \ + # Maintainer for this docker image + maintainer="jim60105" \ + # Dockerfile source repository + url="https://github.com/Recorder-moe/s3-uploader" \ + version=${VERSION} \ + # This should be a number, incremented with each change + release=${RELEASE} \ + io.k8s.display-name="s3-uploader" \ + summary="s3-uploader: This script automates the process of uploading *.mp4 files from a local folder to S3 Blob Storage and delete them from the local folder." \ + description="This script automates the process of uploading *.mp4 files from a local folder to S3 Blob Storage and delete them from the local folder. It utilizes the MinIO Client(mc) to perform the upload. For more information about this tool, please visit the following website: https://github.com/Recorder-moe/s3-uploader" diff --git a/README.md b/README.md index 8f1a9de..c44c13d 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,10 @@ This script automates the process of uploading *.mp4 files from a local folder t ## LICENSE -> [!CAUTION] -> An AGPLv3 licensed Dockerfile means that you _**MUST**_ **distribute the source code with the same license**, if you -> -> - Re-distribute the image. (You can simply point to this GitHub repository if you doesn't made any code changes.) -> - Distribute a image that uses code from this repository. -> - Or **distribute a image based on this image**. (`FROM ghcr.io/recorder-moe/s3-uploader` in your Dockerfile) -> -> "Distribute" means to make the image available for other people to download, usually by pushing it to a public registry. If you are solely using it for your personal purposes, this has no impact on you. -> -> Please consult the [LICENSE](LICENSE) for more details. +> [!NOTE] +> The main program, [MinIO Client(mc)](https://min.io/docs/minio/linux/reference/minio-mc.html), is distributed under [AGPL-3.0 license](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/LICENSE.txt). +> Please consult their website for access to the source code and licenses. +> The following is the license for the shell script, Dockerfiles and CI workflows in this repository. agplv3 @@ -65,3 +59,14 @@ This program is free software: you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + +> [!CAUTION] +> An AGPLv3 licensed Dockerfile means that you _**MUST**_ **distribute the source code with the same license**, if you +> +> - Re-distribute the image. (You can simply point to this GitHub repository if you doesn't made any code changes.) +> - Distribute a image that uses code from this repository. +> - Or **distribute a image based on this image**. (`FROM ghcr.io/recorder-moe/s3-uploader` in your Dockerfile) +> +> "Distribute" means to make the image available for other people to download, usually by pushing it to a public registry. If you are solely using it for your personal purposes, this has no impact on you. +> +> Please consult the [LICENSE](LICENSE) for more details. diff --git a/docker-compose.yml b/docker-compose.yml index 2eaa0b2..90469f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,14 @@ -version: '3.4' - services: s3-uploader: - build: . + build: + context: . + target: final + args: + - UID=1001 + cache_from: + - ghcr.io/recorder-moe/s3-uploader:cache + cache_to: + - type=inline environment: - S3_ENDPOINT=https://your-s3-endpoint - S3_ACCESS_KEY=your-s3-access-key