From 55153403aabaf3ba8890c1f48b6e460a252b7a3d Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Wed, 26 May 2021 12:43:50 +0300 Subject: [PATCH] build docker plugin (#5415) --- .../build_publish_release_docker_image.yml | 37 +++++++++++ Makefile | 33 ++++++++++ cmd/serve/docker/contrib/plugin/Dockerfile | 31 +++++++++ cmd/serve/docker/contrib/plugin/config.json | 66 +++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 cmd/serve/docker/contrib/plugin/Dockerfile create mode 100644 cmd/serve/docker/contrib/plugin/config.json diff --git a/.github/workflows/build_publish_release_docker_image.yml b/.github/workflows/build_publish_release_docker_image.yml index e6add518b..936cdc44e 100644 --- a/.github/workflows/build_publish_release_docker_image.yml +++ b/.github/workflows/build_publish_release_docker_image.yml @@ -32,3 +32,40 @@ jobs: publish: true dockerHubUser: ${{ secrets.DOCKER_HUB_USER }} dockerHubPassword: ${{ secrets.DOCKER_HUB_PASSWORD }} + + build_docker_volume_plugin: + if: github.repository == 'rclone/rclone' + needs: build + runs-on: ubuntu-latest + name: Build and publish docker volume plugin + steps: + - name: Checkout master + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set plugin parameters + shell: bash + run: | + GITHUB_REF=${{ github.ref }} + + PLUGIN_IMAGE_USER=rclone + PLUGIN_IMAGE_NAME=docker-volume-rclone + PLUGIN_IMAGE_TAG=${GITHUB_REF#refs/tags/} + PLUGIN_IMAGE=${PLUGIN_IMAGE_USER}/${PLUGIN_IMAGE_NAME}:${PLUGIN_IMAGE_TAG} + PLUGIN_IMAGE_LATEST=${PLUGIN_IMAGE_USER}/${PLUGIN_IMAGE_NAME}:latest + + echo "PLUGIN_IMAGE_USER=${PLUGIN_IMAGE_USER}" >> $GITHUB_ENV + echo "PLUGIN_IMAGE_NAME=${PLUGIN_IMAGE_NAME}" >> $GITHUB_ENV + echo "PLUGIN_IMAGE_TAG=${PLUGIN_IMAGE_TAG}" >> $GITHUB_ENV + echo "PLUGIN_IMAGE=${PLUGIN_IMAGE}" >> $GITHUB_ENV + echo "PLUGIN_IMAGE_LATEST=${PLUGIN_IMAGE_LATEST}" >> $GITHUB_ENV + - name: Build image + shell: bash + run: | + make docker-plugin + - name: Push image + shell: bash + run: | + docker login -u ${{ secrets.DOCKER_HUB_USER }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} + make docker-plugin-push PLUGIN_IMAGE=${PLUGIN_IMAGE} + make docker-plugin-push PLUGIN_IMAGE=${PLUGIN_IMAGE_LATEST} diff --git a/Makefile b/Makefile index ddacd6dbe..3541592fa 100644 --- a/Makefile +++ b/Makefile @@ -256,3 +256,36 @@ startstable: winzip: zip -9 rclone-$(TAG).zip rclone.exe + +# docker volume plugin +PLUGIN_IMAGE_USER ?= rclone +PLUGIN_IMAGE_TAG ?= latest +PLUGIN_IMAGE_NAME ?= docker-volume-rclone +PLUGIN_IMAGE ?= $(PLUGIN_IMAGE_USER)/$(PLUGIN_IMAGE_NAME):$(PLUGIN_IMAGE_TAG) + +PLUGIN_BASE_IMAGE := rclone/rclone:latest +PLUGIN_BUILD_DIR := ./build/docker-plugin +PLUGIN_CONTRIB_DIR := ./cmd/serve/docker/contrib/plugin +PLUGIN_CONFIG := $(PLUGIN_CONTRIB_DIR)/config.json +PLUGIN_DOCKERFILE := $(PLUGIN_CONTRIB_DIR)/Dockerfile +PLUGIN_CONTAINER := docker-volume-rclone-dev-$(shell date +'%Y%m%d-%H%M%S') + +docker-plugin: docker-plugin-rootfs docker-plugin-create + +docker-plugin-image: rclone + docker build --no-cache --pull --build-arg BASE_IMAGE=${PLUGIN_BASE_IMAGE} -t ${PLUGIN_IMAGE} -f ${PLUGIN_DOCKERFILE} . + +docker-plugin-rootfs: docker-plugin-image + mkdir -p ${PLUGIN_BUILD_DIR}/rootfs + docker create --name ${PLUGIN_CONTAINER} ${PLUGIN_IMAGE} + docker export ${PLUGIN_CONTAINER} | tar -x -C ${PLUGIN_BUILD_DIR}/rootfs + docker rm -vf ${PLUGIN_CONTAINER} + cp ${PLUGIN_CONFIG} ${PLUGIN_BUILD_DIR}/config.json + +docker-plugin-create: + docker plugin rm -f ${PLUGIN_IMAGE} 2>/dev/null || true + docker plugin create ${PLUGIN_IMAGE} ${PLUGIN_BUILD_DIR} + +docker-plugin-push: docker-plugin-create + docker plugin push ${PLUGIN_IMAGE} + docker plugin rm ${PLUGIN_IMAGE} diff --git a/cmd/serve/docker/contrib/plugin/Dockerfile b/cmd/serve/docker/contrib/plugin/Dockerfile new file mode 100644 index 000000000..f74f3c4f3 --- /dev/null +++ b/cmd/serve/docker/contrib/plugin/Dockerfile @@ -0,0 +1,31 @@ +ARG BASE_IMAGE=rclone/rclone:latest +ARG BUILD_PLATFORM=linux/amd64 +ARG TARGET_PLATFORM=linux/amd64 + +# temporary build image +FROM --platform=${BUILD_PLATFORM} golang:alpine AS BUILD_ENV + +COPY . /src +WORKDIR /src + +RUN apk add --no-cache make git bash && \ + CGO_ENABLED=0 \ + GOARCH=$(echo ${TARGET_PLATFORM} | cut -d '/' -f2) \ + make rclone + +# plugin image +FROM ${BASE_IMAGE} + +COPY --from=BUILD_ENV /src/rclone /usr/local/bin/rclone + +RUN mkdir -p /data/config /data/cache /mnt \ + && /usr/local/bin/rclone version + +ENV RCLONE_CONFIG=/data/config/rclone.conf +ENV RCLONE_CACHE_DIR=/data/cache +ENV RCLONE_BASE_DIR=/mnt +ENV RCLONE_VERBOSE=0 + +WORKDIR /data +ENTRYPOINT ["/usr/local/bin/rclone"] +CMD ["serve", "docker"] diff --git a/cmd/serve/docker/contrib/plugin/config.json b/cmd/serve/docker/contrib/plugin/config.json new file mode 100644 index 000000000..217fba1ff --- /dev/null +++ b/cmd/serve/docker/contrib/plugin/config.json @@ -0,0 +1,66 @@ +{ + "description": "Rclone volume plugin for Docker", + "documentation": "https://rclone.org/", + "interface": { + "socket": "rclone.sock", + "types": ["docker.volumedriver/1.0"] + }, + "linux": { + "capabilities": [ + "CAP_SYS_ADMIN" + ], + "devices": [ + { + "path": "/dev/fuse" + } + ] + }, + "network": { + "type": "host" + }, + "entrypoint": ["/usr/local/bin/rclone", "serve", "docker"], + "workdir": "/data", + "args": { + "name": "args", + "value": [], + "settable": ["value"] + }, + "env": [ + { + "name": "RCLONE_VERBOSE", + "value": "0", + "settable": ["value"] + }, + { + "name": "RCLONE_CONFIG", + "value": "/data/config/rclone.conf" + }, + { + "name": "RCLONE_CACHE_DIR", + "value": "/data/cache" + }, + { + "name": "RCLONE_BASE_DIR", + "value": "/mnt" + } + ], + "mounts": [ + { + "name": "config", + "source": "/var/lib/docker-plugins/rclone/config", + "destination": "/data/config", + "type": "bind", + "options": ["rbind"], + "settable": ["source"] + }, + { + "name": "cache", + "source": "/var/lib/docker-plugins/rclone/cache", + "destination": "/data/cache", + "type": "bind", + "options": ["rbind"], + "settable": ["source"] + } + ], + "propagatedMount": "/mnt" +}