Skip to content

Commit

Permalink
Rewrite docker-quobyte-plugin in golang
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Scheuermann committed Jun 29, 2016
1 parent 3892fa6 commit 0eb0f04
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 277 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-quobyte-plugin
94 changes: 69 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,87 @@
Quobyte volume plug-in for Docker
=================================
# Quobyte volume plug-in for Docker

Setup:
* create a user in Quobyte for the plug-in:
Tested with `CentOS 7.2` and `Docker 1.10.3`. This plugin allows you to use [Quobyte](www.quobyte.com) with Docker without installing the Quobyte client on the host system (e.q. Rancher/CoreOS).

## Build

Get the code

```
$ go get -u github.com/quobyte/api
$ go get -u github.com/quobyte/go-quobyte-docker
```
qmgmt -u <api-url> user config add docker <email>

### Linux

```
$ go build -o docker-quobyte-plugin .
$ cp quobyte-docker-plugin /usr/libexec/docker/docker-quobyte-plugin
```

### OSX/MacOS

* set mandatory configuration in environment
```
export QUOBYTE_API_USER=docker
export QUOBYTE_API_PASSWORD=...
export QUOBYTE_API_URL=http://<host>:7860/
$ GOOS=linux GOARCH=amd64 go build -o docker-quobyte-plugin
$ cp quobyte-docker-plugin /usr/libexec/docker/docker-quobyte-plugin
```

## Setup

### Create a user in Quobyte for the plug-in:

This step is optional.

```
$ qmgmt -u <api-url> user config add docker <email>
```

### Set mandatory configuration in environment

```
$ export QUOBYTE_API_USER=docker
$ export QUOBYTE_API_PASSWORD=...
$ export QUOBYTE_API_URL=http://<host>:7860/
# host[:port][,host:port] or SRV record name
export QUOBYTE_REGISTRY=quobyte.corp
$ export QUOBYTE_REGISTRY=quobyte.corp
```

### Install systemd files Set the variables in systemd/docker-quobyte.env.sample

```
$ cp systemd/docker-quobyte.env.sample /etc/quobyte/docker-quobyte.env
$ cp docker-quobyte-plugin /usr/libexec/docker/
$ cp systemd/* /lib/systemd/system
$ systemctl daemon-reload
$ systemctl start docker-quobyte-plugin
$ systemctl enable docker-quobyte-plugin
$ systemctl status docker-quobyte-plugin
```

* Start the plug-in as root (with above environment)
```
quobyte-docker-volume.py
## Examples

### Create a volume

```
$ docker volume create --driver quobyte --name <volumename>
# Set user and group of the volume
$ docker volume create --driver quobyte --name <volumename> --opt user=docker --opt group=docker
```

Examples:
### Delete a volume

```
# docker volume create --driver quobyte --name <volumename> --opt volume_config=MyConfig
# docker volume create --driver quobyte --name <volumename>
# docker volume rm <volumename>
# docker run --volume-driver=quobyte -v <quobyte volumename>:path
$ docker volume rm <volumename>
```

* Install systemd files
Set the variables in systemd/docker-quobyte.env.sample
### List all volumes

```
cp systemd/docker-quobyte.env.sample /etc/quobyte/docker-quobyte.env
cp quobyte-docker-volume.py /usr/libexec/docker/
cp systemd/* /lib/systemd/system
$ docker volume ls
```

### Attach volume to container

systemctl enable docker-quobyte-plugin
systemctl status docker-quobyte-plugin
```
$ docker run --volume-driver=quobyte -v <volumename>:/vol busybox sh -c 'echo "Hello World" > /vol/hello.txt'
```
38 changes: 38 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"
"os"

"github.com/docker/go-plugins-helpers/volume"
)

const quobyteID string = "quobyte"

// Mandatory configuration
var qmgmtUser string
var qmgmtPassword string
var quobyteAPIURL string
var quobyteRegistry string

// Optional configuration
var mountQuobytePath string
var mountQuobyteOptions string

func main() {
readMandatoryConfig()
readOptionalConfig()

if err := os.MkdirAll(mountQuobytePath, 0555); err != nil {
log.Println(err.Error())
}

if !isMounted(mountQuobytePath) {
log.Printf("Mounting Quobyte namespace in %s", mountQuobytePath)
mountAll()
}

qDriver := newQuobyteDriver(quobyteAPIURL, qmgmtUser, qmgmtPassword)
handler := volume.NewHandler(qDriver)
log.Println(handler.ServeUnix("root", quobyteID))
}
Loading

0 comments on commit 0eb0f04

Please sign in to comment.