Skip to content

Commit

Permalink
Merge pull request #2 from gondor/master
Browse files Browse the repository at this point in the history
update from original repo
  • Loading branch information
holgerreif committed Apr 21, 2016
2 parents 1867f03 + 124fec9 commit 3eebd35
Show file tree
Hide file tree
Showing 33 changed files with 1,509 additions and 285 deletions.
5 changes: 4 additions & 1 deletion .goxc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"ArtifactsDest": "build",
"ConfigVersion": "0.9",
"PackageVersion": "0.11",
"TaskSettings": {
"bintray": {
"user": "gondor",
"package": "docker-volume-netshare",
"repository": "docker",
"subject": "pacesys"
},
"publish-github": {
"owner": "gondor",
"repository": "docker-volume-netshare"
},
"debs": {
"metadata": {
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: go
go:
- 1.4.2
- 1.5.1
- tip
script:
- go test ./...
- go build
install:
- go get github.com/stretchr/testify
- go get -v ./...
- go get -v ./...
env:
- GO15VENDOREXPERIMENT=1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ FROM golang:1.5

COPY . /go/src/app
WORKDIR /go/src/app
RUN go-wrapper download && go-wrapper install && go build -o docker-volume-netshare
RUN go-wrapper download && go-wrapper install && go build -o docker-volume-netshare && cp docker-volume-netshare /bin
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERSION = 0.16
GO_FMT = gofmt -s -w -l .
GO_XC = goxc -os="linux freebsd openbsd netbsd"
GO_XC = goxc -os="linux" -tasks-="rmbin"

GOXC_FILE = .goxc.local.json

Expand All @@ -8,11 +9,17 @@ all: deps compile
compile: goxc

goxc:
$(shell echo '{\n "ConfigVersion": "0.9",' > $(GOXC_FILE))
$(shell echo '{\n "ConfigVersion": "0.9",\n "PackageVersion": "$(VERSION)",' > $(GOXC_FILE))
$(shell echo ' "TaskSettings": {' >> $(GOXC_FILE))
$(shell echo ' "bintray": {\n "apikey": "$(BINTRAY_APIKEY)"' >> $(GOXC_FILE))
$(shell echo ' },' >> $(GOXC_FILE))
$(shell echo ' "publish-github": {' >> $(GOXC_FILE))
$(shell echo ' "apikey": "$(GITHUB_APIKEY)",' >> $(GOXC_FILE))
$(shell echo ' "body": "",' >> $(GOXC_FILE))
$(shell echo ' "include": "*.zip,*.tar.gz,*.deb,docker-volume-netshare_$(VERSION)_linux_amd64-bin"' >> $(GOXC_FILE))
$(shell echo ' }\n } \n}' >> $(GOXC_FILE))
$(GO_XC)
cp build/$(VERSION)/linux_amd64/docker-volume-netshare build/$(VERSION)/docker-volume-netshare_$(VERSION)_linux_amd64-bin

deps:
go get
Expand All @@ -22,3 +29,6 @@ format:

bintray:
$(GO_XC) bintray

github:
$(GO_XC) publish-github
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Docker NFS, AWS EFS & Samba/CIFS Volume Plugin

[![Build Status](https://travis-ci.org/gondor/docker-volume-netshare.svg)](https://travis-ci.org/gondor/docker-volume-netshare)
[![Build Status](https://travis-ci.org/gondor/docker-volume-netshare.svg)](https://travis-ci.org/gondor/docker-volume-netshare) [![release](http://github-release-version.herokuapp.com/github/gondor/docker-volume-netshare/release.svg?style=flat)](https://github.com/gondor/docker-volume-netshare/releases/latest)

Mount NFS v3/4, AWS EFS or CIFS inside your docker containers. This is a docker plugin which enables these volume types to be directly mounted within a container.

Expand All @@ -18,8 +18,6 @@ sudo mount -t nfs4 1.1.1.1:/mountpoint /target/mount

## Installation

**Latest Version:** 0.10

#### From Source

```
Expand All @@ -29,9 +27,7 @@ $ go build

#### From Binaries

* Architecture i386 [ [linux](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_linux_386.tar.gz?direct) / [netbsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_netbsd_386.zip?direct) / [freebsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_freebsd_386.zip?direct) / [openbsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_openbsd_386.zip?direct) ]
* Architecture amd64 [ [linux](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_linux_amd64.tar.gz?direct) / [netbsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_netbsd_amd64.zip?direct) / [freebsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_freebsd_amd64.zip?direct) / [openbsd](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_openbsd_amd64.zip?direct) ]
* Debian Package [ [i386](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_i386.deb?direct) ] / [amd64](https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_amd64.deb?direct) ] ]
Binaries are available through GitHub releases. You can download the appropriate binary, package and version from the [Releases](https://github.com/gondor/docker-volume-netshare/releases) page

#### On Ubuntu / Debian

Expand All @@ -40,8 +36,8 @@ The method below will install the sysvinit and /etc/default options that can be
1. Install the Package

```
$ wget https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_i386.deb
$ sudo dpkg -i docker-volume-netshare_0.11_i386.deb
$ wget https://github.com/gondor/docker-volume-netshare/releases/download/v0.16/docker-volume-netshare_0.16_amd64.deb
$ sudo dpkg -i docker-volume-netshare_0.16_amd64.deb
```

2. Modify the startup options in `/etc/default/docker-volume-netshare`
Expand Down Expand Up @@ -165,7 +161,7 @@ e.g.: Apple Time Capsule's require the security mode ``ntlm``.

This software is licensed under the Apache 2 license, quoted below.

Copyright 2015 Jeremy Unruh
Copyright 2016 Jeremy Unruh

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"github.com/gondor/docker-volume-netshare/netshare"
)

var VERSION string = ""
var BUILD_DATE string = ""

func main() {
netshare.Version = VERSION
netshare.BuildDate = BUILD_DATE
netshare.Execute()
}
126 changes: 51 additions & 75 deletions netshare/drivers/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
)

const (
Expand All @@ -20,11 +19,9 @@ const (
)

type cifsDriver struct {
root string
creds *cifsCreds
netrc *netrc.Netrc
mountm *mountManager
m *sync.Mutex
volumeDriver
creds *cifsCreds
netrc *netrc.Netrc
}

type cifsCreds struct {
Expand All @@ -36,11 +33,9 @@ type cifsCreds struct {

func NewCIFSDriver(root, user, pass, domain, security, netrc string) cifsDriver {
d := cifsDriver{
root: root,
creds: &cifsCreds{user: user, pass: pass, domain: domain, security: security},
netrc: parseNetRC(netrc),
mountm: NewVolumeManager(),
m: &sync.Mutex{},
volumeDriver: newVolumeDriver(root),
creds: &cifsCreds{user: user, pass: pass, domain: domain, security: security},
netrc: parseNetRC(netrc),
}
return d
}
Expand All @@ -54,104 +49,85 @@ func parseNetRC(path string) *netrc.Netrc {
return nil
}

func (s cifsDriver) Create(r volume.Request) volume.Response {
log.Debugf("Create: %s, %v", r.Name, r.Options)
dest := mountpoint(s.root, r.Name)
if err := createDest(dest); err != nil {
return volume.Response{Err: err.Error()}
}
s.mountm.Create(dest, r.Name, r.Options)
return volume.Response{}
}

func (s cifsDriver) Remove(r volume.Request) volume.Response {
log.Debugf("Removing volume %s", r.Name)
return volume.Response{}
}

func (s cifsDriver) Path(r volume.Request) volume.Response {
log.Debugf("Path for %s is at %s", r.Name, mountpoint(s.root, r.Name))
return volume.Response{Mountpoint: mountpoint(s.root, r.Name)}
}
func (c cifsDriver) Mount(r volume.Request) volume.Response {
c.m.Lock()
defer c.m.Unlock()
hostdir := mountpoint(c.root, r.Name)
source := c.fixSource(r)
host := c.parseHost(r)

func (s cifsDriver) Get(r volume.Request) volume.Response {
log.Debugf("Get for %s is at %s", r.Name, mountpoint(s.root, r.Name))
return volume.Response{ Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
}

func (s cifsDriver) List(r volume.Request) volume.Response {
log.Debugf("List Volumes")
return volume.Response{ Volumes: s.mountm.GetVolumes(s.root) }
}

func (s cifsDriver) Mount(r volume.Request) volume.Response {
s.m.Lock()
defer s.m.Unlock()
dest := mountpoint(s.root, r.Name)
source := s.fixSource(r.Name)
host := parseHost(r.Name)
log.Infof("Mount: %s, %v", r.Name, r.Options)

if s.mountm.HasMount(dest) && s.mountm.Count(dest) > 0 {
log.Infof("Using existing CIFS volume mount: %s", dest)
s.mountm.Increment(dest)
return volume.Response{Mountpoint: dest}
if c.mountm.HasMount(r.Name) && c.mountm.Count(r.Name) > 0 {
log.Infof("Using existing CIFS volume mount: %s", hostdir)
c.mountm.Increment(r.Name)
return volume.Response{Mountpoint: hostdir}
}

log.Infof("Mounting CIFS volume %s on %s", source, dest)
log.Infof("Mounting CIFS volume %s on %s", source, hostdir)

if err := createDest(dest); err != nil {
if err := createDest(hostdir); err != nil {
return volume.Response{Err: err.Error()}
}

if err := s.mountVolume(source, dest, s.getCreds(host)); err != nil {
if err := c.mountVolume(r.Name, source, hostdir, c.getCreds(host)); err != nil {
return volume.Response{Err: err.Error()}
}
s.mountm.Add(dest, r.Name)
return volume.Response{Mountpoint: dest}
c.mountm.Add(r.Name, hostdir)
return volume.Response{Mountpoint: hostdir}
}

func (s cifsDriver) Unmount(r volume.Request) volume.Response {
s.m.Lock()
defer s.m.Unlock()
dest := mountpoint(s.root, r.Name)
source := s.fixSource(r.Name)
func (c cifsDriver) Unmount(r volume.Request) volume.Response {
c.m.Lock()
defer c.m.Unlock()
hostdir := mountpoint(c.root, r.Name)
source := c.fixSource(r)

if s.mountm.HasMount(dest) {
if s.mountm.Count(dest) > 1 {
log.Infof("Skipping unmount for %s - in use by other containers", dest)
s.mountm.Decrement(dest)
if c.mountm.HasMount(r.Name) {
if c.mountm.Count(r.Name) > 1 {
log.Infof("Skipping unmount for %s - in use by other containers", r.Name)
c.mountm.Decrement(r.Name)
return volume.Response{}
}
s.mountm.Decrement(dest)
c.mountm.Decrement(r.Name)
}

log.Infof("Unmounting volume %s from %s", source, dest)
log.Infof("Unmounting volume %s from %s", source, hostdir)

if err := run(fmt.Sprintf("umount %s", dest)); err != nil {
if err := run(fmt.Sprintf("umount %s", hostdir)); err != nil {
return volume.Response{Err: err.Error()}
}

if err := os.RemoveAll(dest); err != nil {
c.mountm.DeleteIfNotManaged(r.Name)

if err := os.RemoveAll(hostdir); err != nil {
return volume.Response{Err: err.Error()}
}

return volume.Response{}
}

func (s cifsDriver) fixSource(name string) string {
return "//" + name
func (c cifsDriver) fixSource(r volume.Request) string {
if c.mountm.HasOption(r.Name, ShareOpt) {
return "//" + c.mountm.GetOption(r.Name, ShareOpt)
}
return "//" + r.Name
}

func parseHost(name string) string {
func (c cifsDriver) parseHost(r volume.Request) string {
name := r.Name
if c.mountm.HasOption(r.Name, ShareOpt) {
name = c.mountm.GetOption(r.Name, ShareOpt)
}

if strings.ContainsAny(name, "/") {
s := strings.Split(name, "/")
return s[0]
}
return name
}

func (s cifsDriver) mountVolume(source, dest string, creds *cifsCreds) error {
func (s cifsDriver) mountVolume(name, source, dest string, creds *cifsCreds) error {
var opts bytes.Buffer

opts.WriteString("-o ")
Expand All @@ -160,8 +136,8 @@ func (s cifsDriver) mountVolume(source, dest string, creds *cifsCreds) error {
var domain = creds.domain
var security = creds.security

if s.mountm.HasOptions(dest) {
mopts := s.mountm.GetOptions(dest)
if s.mountm.HasOptions(name) {
mopts := s.mountm.GetOptions(name)
if v, found := mopts[UsernameOpt]; found {
user = v
}
Expand Down Expand Up @@ -197,7 +173,7 @@ func (s cifsDriver) mountVolume(source, dest string, creds *cifsCreds) error {

opts.WriteString(fmt.Sprintf("%s %s", source, dest))
cmd := fmt.Sprintf("mount -t cifs %s", opts.String())
log.Debugf("Executing: %s\n", strings.Replace(cmd, pass, "", 1))
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password="+pass, "password=****", 1))
return run(cmd)
}

Expand Down
Loading

0 comments on commit 3eebd35

Please sign in to comment.