diff --git a/.circleci/config.yml b/.circleci/config.yml index 01eb804..92108f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,3 +8,4 @@ jobs: - checkout - run: make circleci - run: sudo make test + - run: make -f plugin/Makefile create diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c3c8874 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +* +!/plugin/ +!/docker-lvm-plugin diff --git a/README.md b/README.md index fd0054c..1164487 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ This plugin can be used to create lvm volumes of specified size, which can then be bind mounted into the container using `docker run` command. ## Setup +### Using Docker + docker plugin install --alias lvm containers/docker-lvm-plugin/docker-lvm-plugin VOLUME_GROUP=vg0 +### Manual 1) git clone git@github.com:projectatomic/docker-lvm-plugin.git (You can also use HTTPS to clone: git clone https://github.com/projectatomic/docker-lvm-plugin.git) 2) cd docker-lvm-plugin 3) export GO111MODULE=on diff --git a/plugin/Dockerfile b/plugin/Dockerfile new file mode 100644 index 0000000..165ea24 --- /dev/null +++ b/plugin/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine +RUN apk update && apk add lvm2 xfsprogs cryptsetup thin-provisioning-tools +RUN mkdir -p /var/lib/docker-lvm-plugin +COPY docker-lvm-plugin / diff --git a/plugin/Makefile b/plugin/Makefile new file mode 100644 index 0000000..d5eb060 --- /dev/null +++ b/plugin/Makefile @@ -0,0 +1,39 @@ +name := containers/docker-lvm-plugin + +.PHONY: build +build: docker-lvm-plugin + +docker-lvm-plugin: main.go driver.go utils.go go.mod go.sum + docker run --rm --tmpfs /tmp -v $(shell pwd):/tmp/docker-lvm-plugin -w /tmp/docker-lvm-plugin golang:latest go build + +.PHONY: create +create: plugin/config.json plugin/rootfs + docker plugin rm --force $(name) || true + docker plugin create $(name) plugin + +.PHONY: install +install: create + docker plugin rm --force $(name) || true + docker plugin install $(name) --grant-all-permissions + +.PHONY: push +push: create + docker plugin push $(name) + +.PHONY: enable +enable: create + docker plugin enable $(name) + +.PHONY: clean +clean: + rm -rf plugin + +plugin/rootfs: .dockerignore plugin/Dockerfile docker-lvm-plugin + docker build --tag $(name):rootfs -f plugin/Dockerfile . + docker rm --force --volumes rootfs || true + docker create --name rootfs $(name):rootfs + rm -rf $@ + mkdir -p $@ + docker export rootfs | tar -x -C $@ + docker rm --force --volumes rootfs + diff --git a/plugin/config.json b/plugin/config.json new file mode 100644 index 0000000..55a97ba --- /dev/null +++ b/plugin/config.json @@ -0,0 +1,36 @@ +{ + "Description": "LVM volume plugin for Docker", + "Documentation": "https://docs.docker.com/engine/extend/plugins/", + "Entrypoint": ["/docker-lvm-plugin"], + "Env": [ + { + "Name": "VOLUME_GROUP", + "Description": "LVM volume group to create volumes in.", + "Settable": ["value"], + "Value": null + } + ], + "Interface": { + "Socket": "lvm.sock", + "Types": ["docker.volumedriver/1.0"] + }, + "Linux": { + "Capabilities": ["CAP_SYS_ADMIN"], + "AllowAllDevices": true, + "Devices": null + }, + "Mounts": [ + { + "description": "Device access for devicemapper (/dev/mapper/*, /dev/*/*)", + "destination": "/dev", + "options": ["rbind"], + "name": "dev", + "source": "/dev", + "type": "bind" + } + ], + "Network": { + "Type": "host" + }, + "PropagatedMount": "/var/lib/docker-lvm-plugin" +}