From 93dba912444689e12b902e7cfaeea9000afdf576 Mon Sep 17 00:00:00 2001 From: Beorn Facchini Date: Thu, 27 Jun 2024 17:21:22 +1000 Subject: [PATCH] Add support for Docker Swarm --- deploy/docker-swarm/Dockerfile | 14 +++++++++ deploy/docker-swarm/Makefile | 34 +++++++++++++++++++++ deploy/docker-swarm/config.json | 50 +++++++++++++++++++++++++++++++ deploy/docker-swarm/entrypoint.sh | 6 ++++ 4 files changed, 104 insertions(+) create mode 100644 deploy/docker-swarm/Dockerfile create mode 100644 deploy/docker-swarm/Makefile create mode 100644 deploy/docker-swarm/config.json create mode 100755 deploy/docker-swarm/entrypoint.sh diff --git a/deploy/docker-swarm/Dockerfile b/deploy/docker-swarm/Dockerfile new file mode 100644 index 0000000..fdd6c40 --- /dev/null +++ b/deploy/docker-swarm/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.21-alpine as builder +ARG VERSION=0.0.0-dev + +WORKDIR /go/src/github.com/vultr/vultr-csi +COPY --from=src . /go/src/github.com/vultr/vultr-csi +RUN CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION}" -o csi-vultr-plugin ./cmd/csi-vultr-driver + +FROM alpine:3.18 + +RUN apk add --no-cache ca-certificates e2fsprogs findmnt bind-tools e2fsprogs-extra xfsprogs xfsprogs-extra blkid + +COPY --from=builder /go/src/github.com/vultr/vultr-csi/csi-vultr-plugin / +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] diff --git a/deploy/docker-swarm/Makefile b/deploy/docker-swarm/Makefile new file mode 100644 index 0000000..59f9a03 --- /dev/null +++ b/deploy/docker-swarm/Makefile @@ -0,0 +1,34 @@ +PLUGIN_NAME = vultr/vultr-csi +PLUGIN_TAG = latest +PLUGIN_ARCH = amd64 + +all: clean rootfs create + +clean: + @echo "### rm ./plugin" + @rm -rf ./plugin + +rootfs: + @echo "### docker build: rootfs image with ${PLUGIN_NAME}" + @docker build --build-context src=../../ --platform linux/${PLUGIN_ARCH} -t ${PLUGIN_NAME}:rootfs . + @echo "### create rootfs directory in ./plugin/rootfs" + @mkdir -p ./plugin/rootfs + @docker create --name tmp ${PLUGIN_NAME}:rootfs + @docker export tmp | tar -x -C ./plugin/rootfs + @echo "### copy config.json to ./plugin/" + @cp config.json ./plugin/ + @docker rm -vf tmp + +create: + @echo "### remove existing plugin ${PLUGIN_NAME}:${PLUGIN_TAG} if exists" + @docker plugin rm -f ${PLUGIN_NAME}:${PLUGIN_TAG} || true + @echo "### create new plugin ${PLUGIN_NAME}:${PLUGIN_TAG} from ./plugin" + @docker plugin create ${PLUGIN_NAME}:${PLUGIN_TAG} ./plugin + +enable: + @echo "### enable plugin ${PLUGIN_NAME}:${PLUGIN_TAG}" + @docker plugin enable ${PLUGIN_NAME}:${PLUGIN_TAG} + +push: clean rootfs create enable + @echo "### push plugin ${PLUGIN_NAME}:${PLUGIN_TAG}" + @docker plugin push ${PLUGIN_NAME}:${PLUGIN_TAG} diff --git a/deploy/docker-swarm/config.json b/deploy/docker-swarm/config.json new file mode 100644 index 0000000..bd592b0 --- /dev/null +++ b/deploy/docker-swarm/config.json @@ -0,0 +1,50 @@ +{ + "description": "Vultr csi plugin for Docker", + "documentation": "https://github.com/moby/moby/blob/master/docs/cluster_volumes.md", + "entrypoint": [ + "/entrypoint.sh" + ], + "env": [ + { + "name": "VULTR_API_URL", + "settable": [ + "value" + ], + "value": "" + }, + { + "name": "VULTR_API_TOKEN", + "settable": [ + "value" + ], + "value": "" + } + ], + "interface": { + "socket": "csi-vultr.sock", + "types": [ + "docker.csicontroller/1.0", + "docker.csinode/1.0" + ] + }, + "linux": { + "allowAllDevices": true, + "capabilities": [ + "CAP_SYS_ADMIN" + ] + }, + "mounts": [ + { + "destination": "/dev", + "options": [ + "rbind" + ], + "source": "/dev", + "type": "bind" + } + ], + "network": { + "type": "host" + }, + "propagatedMount": "/data/published" +} diff --git a/deploy/docker-swarm/entrypoint.sh b/deploy/docker-swarm/entrypoint.sh new file mode 100755 index 0000000..a6ae72c --- /dev/null +++ b/deploy/docker-swarm/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +exec /csi-vultr-plugin \ + -endpoint "unix:///run/docker/plugins/csi-vultr.sock" \ + -api-url "${VULTR_API_URL}" \ + -token "${VULTR_API_TOKEN}"