Skip to content

Commit

Permalink
Add support for Docker Swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
beornf committed Jun 27, 2024
1 parent 5dc8822 commit 93dba91
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
14 changes: 14 additions & 0 deletions deploy/docker-swarm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
34 changes: 34 additions & 0 deletions deploy/docker-swarm/Makefile
Original file line number Diff line number Diff line change
@@ -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}
50 changes: 50 additions & 0 deletions deploy/docker-swarm/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions deploy/docker-swarm/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 93dba91

Please sign in to comment.