Skip to content

Commit

Permalink
feat: rewrite Dockerfiles and update README.md for efficiency
Browse files Browse the repository at this point in the history
- Remove `**/LICENSE` from `.dockerignore`
- Creation of a new file `.hadolint.yml` with specific exceptions made for linting `Dockerfile`
- Introduce additional build arguments and several new build stages (`compress` and `final`) to the `Dockerfile`
- Changes made to file permissions and method of copying files in the `Dockerfile`
- Introduction of additional metadata labels in the `Dockerfile`
- Updated the `README.md` section regarding the AGPLv3 license requirements and also provided some clarifications
- Changes in `docker-compose.yml` to include a build context, target stage, build arguments and cache options.

Signed-off-by: 陳鈞 <jim60105@gmail.com>
  • Loading branch information
jim60105 committed May 24, 2024
1 parent 22ac9fa commit c77b883
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 24 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
**/LICENSE
**/*.md
**/.hadolint.yml
**/node_modules
Expand Down
8 changes: 8 additions & 0 deletions .hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ignored:
- DL3041 # Specify version with `dnf install -y <package>-<version>`.
- DL3042 # Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
- DL4006 # Set the SHELL option -o pipefail before RUN with a pipe in it
- DL3013 # Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>`
- 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 <package>` use `apk add <package>=<version>`
71 changes: 61 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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=""
Expand All @@ -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" ]
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"
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<img src="https://github.com/Recorder-moe/s3-uploader/assets/16995691/cb3b53a6-7eff-409b-9dca-bb59f52d3117" alt="agplv3" width="300" />

Expand All @@ -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 <https://www.gnu.org/licenses/>.

> [!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.
12 changes: 9 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c77b883

Please sign in to comment.