From 071be5e9cc2bc688144a2e6b5f11a2c155cc33df Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Tue, 27 Jun 2023 10:14:07 +0545 Subject: [PATCH] add docker setup for S3 to WebDav proxy --- .dockerignore | 5 +++++ Dockerfile | 42 +++++++++++++++++++++++++++++++++--------- docker/startup | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 docker/startup diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..a86eedd5f6552 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.idea +bin +contrib +rclone +graphics diff --git a/Dockerfile b/Dockerfile index 82f16aad784a1..6afdfea203201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,49 @@ FROM golang:alpine AS builder -COPY . /go/src/github.com/rclone/rclone/ -WORKDIR /go/src/github.com/rclone/rclone/ +WORKDIR /rclone/ +COPY go.mod /rclone/ +RUN go mod download + +COPY . /rclone/ RUN apk add --no-cache make bash gawk git RUN \ CGO_ENABLED=0 \ - make -RUN ./rclone version + make && \ + ./rclone version + # Begin final image FROM alpine:latest -RUN apk --no-cache add ca-certificates fuse3 tzdata && \ - echo "user_allow_other" >> /etc/fuse.conf +COPY --from=builder /rclone/rclone /usr/local/bin/ -COPY --from=builder /go/src/github.com/rclone/rclone/rclone /usr/local/bin/ +COPY ["./docker/startup", "/startup"] -RUN addgroup -g 1009 rclone && adduser -u 1009 -Ds /bin/sh -G rclone rclone +RUN apk --no-cache add \ + ca-certificates \ + fuse3 \ + tzdata \ + && apk cache clean -ENTRYPOINT [ "rclone" ] +RUN echo "user_allow_other" >> /etc/fuse.conf && \ + addgroup -g 1009 rclone && \ + adduser -u 1009 -Ds /bin/sh -G rclone rclone && \ + chmod +x /startup WORKDIR /data + ENV XDG_CONFIG_HOME=/config + +# remote configs +ENV REMOTE_NAME="" +ENV REMOTE_URL="" +ENV REMOTE_VENDOR="" + +# s3 proxy configs +# a space separated list of options +ENV PROXY_ARGS="" + +ENTRYPOINT [ "/startup" ] + +EXPOSE 8080 diff --git a/docker/startup b/docker/startup new file mode 100644 index 0000000000000..9feed78725ffb --- /dev/null +++ b/docker/startup @@ -0,0 +1,40 @@ +#!/bin/sh + +RCLONE_CONFIG=/config/rclone/rclone.conf + +if [ -z "$REMOTE_NAME" ]; then + echo "REMOTE_NAME is not set" + exit 1 +fi +if [ -z "$REMOTE_URL" ]; then + echo "REMOTE_URL is not set" + exit 1 +fi +if [ -z "$REMOTE_VENDOR" ]; then + echo "REMOTE_VENDOR is not set" + exit 1 +fi + +mkdir -p "$(dirname "$RCLONE_CONFIG")" + +cat <"$RCLONE_CONFIG" +[$REMOTE_NAME] +type = webdav +url = $REMOTE_URL +vendor = $REMOTE_VENDOR +nextcloud_chunk_size = 0 +EOF + +# parse args +ifsBak=$IFS +IFS=' ' + +ARGS="$REMOTE_NAME:" +for arg in $PROXY_ARGS; do + ARGS="$ARGS $arg" +done + +IFS=$ifsBak + +# DO NOT QUOTE ARGS +rclone serve s3 ${ARGS}