Skip to content

Commit 3eebd35

Browse files
committed
Merge pull request #2 from gondor/master
update from original repo
2 parents 1867f03 + 124fec9 commit 3eebd35

33 files changed

+1509
-285
lines changed

.goxc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"ArtifactsDest": "build",
33
"ConfigVersion": "0.9",
4-
"PackageVersion": "0.11",
54
"TaskSettings": {
65
"bintray": {
76
"user": "gondor",
87
"package": "docker-volume-netshare",
98
"repository": "docker",
109
"subject": "pacesys"
10+
},
11+
"publish-github": {
12+
"owner": "gondor",
13+
"repository": "docker-volume-netshare"
1114
},
1215
"debs": {
1316
"metadata": {

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
language: go
22
go:
3-
- 1.4.2
43
- 1.5.1
54
- tip
65
script:
76
- go test ./...
87
- go build
98
install:
109
- go get github.com/stretchr/testify
11-
- go get -v ./...
10+
- go get -v ./...
11+
env:
12+
- GO15VENDOREXPERIMENT=1

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ FROM golang:1.5
55

66
COPY . /go/src/app
77
WORKDIR /go/src/app
8-
RUN go-wrapper download && go-wrapper install && go build -o docker-volume-netshare
8+
RUN go-wrapper download && go-wrapper install && go build -o docker-volume-netshare && cp docker-volume-netshare /bin

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
VERSION = 0.16
12
GO_FMT = gofmt -s -w -l .
2-
GO_XC = goxc -os="linux freebsd openbsd netbsd"
3+
GO_XC = goxc -os="linux" -tasks-="rmbin"
34

45
GOXC_FILE = .goxc.local.json
56

@@ -8,11 +9,17 @@ all: deps compile
89
compile: goxc
910

1011
goxc:
11-
$(shell echo '{\n "ConfigVersion": "0.9",' > $(GOXC_FILE))
12+
$(shell echo '{\n "ConfigVersion": "0.9",\n "PackageVersion": "$(VERSION)",' > $(GOXC_FILE))
1213
$(shell echo ' "TaskSettings": {' >> $(GOXC_FILE))
1314
$(shell echo ' "bintray": {\n "apikey": "$(BINTRAY_APIKEY)"' >> $(GOXC_FILE))
15+
$(shell echo ' },' >> $(GOXC_FILE))
16+
$(shell echo ' "publish-github": {' >> $(GOXC_FILE))
17+
$(shell echo ' "apikey": "$(GITHUB_APIKEY)",' >> $(GOXC_FILE))
18+
$(shell echo ' "body": "",' >> $(GOXC_FILE))
19+
$(shell echo ' "include": "*.zip,*.tar.gz,*.deb,docker-volume-netshare_$(VERSION)_linux_amd64-bin"' >> $(GOXC_FILE))
1420
$(shell echo ' }\n } \n}' >> $(GOXC_FILE))
1521
$(GO_XC)
22+
cp build/$(VERSION)/linux_amd64/docker-volume-netshare build/$(VERSION)/docker-volume-netshare_$(VERSION)_linux_amd64-bin
1623

1724
deps:
1825
go get
@@ -22,3 +29,6 @@ format:
2229

2330
bintray:
2431
$(GO_XC) bintray
32+
33+
github:
34+
$(GO_XC) publish-github

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Docker NFS, AWS EFS & Samba/CIFS Volume Plugin
22

3-
[![Build Status](https://travis-ci.org/gondor/docker-volume-netshare.svg)](https://travis-ci.org/gondor/docker-volume-netshare)
3+
[![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)
44

55
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.
66

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

1919
## Installation
2020

21-
**Latest Version:** 0.10
22-
2321
#### From Source
2422

2523
```
@@ -29,9 +27,7 @@ $ go build
2927

3028
#### From Binaries
3129

32-
* 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) ]
33-
* 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) ]
34-
* 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) ] ]
30+
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
3531

3632
#### On Ubuntu / Debian
3733

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

4238
```
43-
$ wget https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_i386.deb
44-
$ sudo dpkg -i docker-volume-netshare_0.11_i386.deb
39+
$ wget https://github.com/gondor/docker-volume-netshare/releases/download/v0.16/docker-volume-netshare_0.16_amd64.deb
40+
$ sudo dpkg -i docker-volume-netshare_0.16_amd64.deb
4541
```
4642

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

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

168-
Copyright 2015 Jeremy Unruh
164+
Copyright 2016 Jeremy Unruh
169165

170166
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
171167

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import (
44
"github.com/gondor/docker-volume-netshare/netshare"
55
)
66

7+
var VERSION string = ""
8+
var BUILD_DATE string = ""
9+
710
func main() {
11+
netshare.Version = VERSION
12+
netshare.BuildDate = BUILD_DATE
813
netshare.Execute()
914
}

netshare/drivers/cifs.go

Lines changed: 51 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"path/filepath"
1111
"strings"
12-
"sync"
1312
)
1413

1514
const (
@@ -20,11 +19,9 @@ const (
2019
)
2120

2221
type cifsDriver struct {
23-
root string
24-
creds *cifsCreds
25-
netrc *netrc.Netrc
26-
mountm *mountManager
27-
m *sync.Mutex
22+
volumeDriver
23+
creds *cifsCreds
24+
netrc *netrc.Netrc
2825
}
2926

3027
type cifsCreds struct {
@@ -36,11 +33,9 @@ type cifsCreds struct {
3633

3734
func NewCIFSDriver(root, user, pass, domain, security, netrc string) cifsDriver {
3835
d := cifsDriver{
39-
root: root,
40-
creds: &cifsCreds{user: user, pass: pass, domain: domain, security: security},
41-
netrc: parseNetRC(netrc),
42-
mountm: NewVolumeManager(),
43-
m: &sync.Mutex{},
36+
volumeDriver: newVolumeDriver(root),
37+
creds: &cifsCreds{user: user, pass: pass, domain: domain, security: security},
38+
netrc: parseNetRC(netrc),
4439
}
4540
return d
4641
}
@@ -54,104 +49,85 @@ func parseNetRC(path string) *netrc.Netrc {
5449
return nil
5550
}
5651

57-
func (s cifsDriver) Create(r volume.Request) volume.Response {
58-
log.Debugf("Create: %s, %v", r.Name, r.Options)
59-
dest := mountpoint(s.root, r.Name)
60-
if err := createDest(dest); err != nil {
61-
return volume.Response{Err: err.Error()}
62-
}
63-
s.mountm.Create(dest, r.Name, r.Options)
64-
return volume.Response{}
65-
}
66-
67-
func (s cifsDriver) Remove(r volume.Request) volume.Response {
68-
log.Debugf("Removing volume %s", r.Name)
69-
return volume.Response{}
70-
}
71-
72-
func (s cifsDriver) Path(r volume.Request) volume.Response {
73-
log.Debugf("Path for %s is at %s", r.Name, mountpoint(s.root, r.Name))
74-
return volume.Response{Mountpoint: mountpoint(s.root, r.Name)}
75-
}
52+
func (c cifsDriver) Mount(r volume.Request) volume.Response {
53+
c.m.Lock()
54+
defer c.m.Unlock()
55+
hostdir := mountpoint(c.root, r.Name)
56+
source := c.fixSource(r)
57+
host := c.parseHost(r)
7658

77-
func (s cifsDriver) Get(r volume.Request) volume.Response {
78-
log.Debugf("Get for %s is at %s", r.Name, mountpoint(s.root, r.Name))
79-
return volume.Response{ Volume: &volume.Volume{Name: r.Name, Mountpoint: mountpoint(s.root, r.Name)}}
80-
}
81-
82-
func (s cifsDriver) List(r volume.Request) volume.Response {
83-
log.Debugf("List Volumes")
84-
return volume.Response{ Volumes: s.mountm.GetVolumes(s.root) }
85-
}
86-
87-
func (s cifsDriver) Mount(r volume.Request) volume.Response {
88-
s.m.Lock()
89-
defer s.m.Unlock()
90-
dest := mountpoint(s.root, r.Name)
91-
source := s.fixSource(r.Name)
92-
host := parseHost(r.Name)
9359
log.Infof("Mount: %s, %v", r.Name, r.Options)
9460

95-
if s.mountm.HasMount(dest) && s.mountm.Count(dest) > 0 {
96-
log.Infof("Using existing CIFS volume mount: %s", dest)
97-
s.mountm.Increment(dest)
98-
return volume.Response{Mountpoint: dest}
61+
if c.mountm.HasMount(r.Name) && c.mountm.Count(r.Name) > 0 {
62+
log.Infof("Using existing CIFS volume mount: %s", hostdir)
63+
c.mountm.Increment(r.Name)
64+
return volume.Response{Mountpoint: hostdir}
9965
}
10066

101-
log.Infof("Mounting CIFS volume %s on %s", source, dest)
67+
log.Infof("Mounting CIFS volume %s on %s", source, hostdir)
10268

103-
if err := createDest(dest); err != nil {
69+
if err := createDest(hostdir); err != nil {
10470
return volume.Response{Err: err.Error()}
10571
}
10672

107-
if err := s.mountVolume(source, dest, s.getCreds(host)); err != nil {
73+
if err := c.mountVolume(r.Name, source, hostdir, c.getCreds(host)); err != nil {
10874
return volume.Response{Err: err.Error()}
10975
}
110-
s.mountm.Add(dest, r.Name)
111-
return volume.Response{Mountpoint: dest}
76+
c.mountm.Add(r.Name, hostdir)
77+
return volume.Response{Mountpoint: hostdir}
11278
}
11379

114-
func (s cifsDriver) Unmount(r volume.Request) volume.Response {
115-
s.m.Lock()
116-
defer s.m.Unlock()
117-
dest := mountpoint(s.root, r.Name)
118-
source := s.fixSource(r.Name)
80+
func (c cifsDriver) Unmount(r volume.Request) volume.Response {
81+
c.m.Lock()
82+
defer c.m.Unlock()
83+
hostdir := mountpoint(c.root, r.Name)
84+
source := c.fixSource(r)
11985

120-
if s.mountm.HasMount(dest) {
121-
if s.mountm.Count(dest) > 1 {
122-
log.Infof("Skipping unmount for %s - in use by other containers", dest)
123-
s.mountm.Decrement(dest)
86+
if c.mountm.HasMount(r.Name) {
87+
if c.mountm.Count(r.Name) > 1 {
88+
log.Infof("Skipping unmount for %s - in use by other containers", r.Name)
89+
c.mountm.Decrement(r.Name)
12490
return volume.Response{}
12591
}
126-
s.mountm.Decrement(dest)
92+
c.mountm.Decrement(r.Name)
12793
}
12894

129-
log.Infof("Unmounting volume %s from %s", source, dest)
95+
log.Infof("Unmounting volume %s from %s", source, hostdir)
13096

131-
if err := run(fmt.Sprintf("umount %s", dest)); err != nil {
97+
if err := run(fmt.Sprintf("umount %s", hostdir)); err != nil {
13298
return volume.Response{Err: err.Error()}
13399
}
134100

135-
if err := os.RemoveAll(dest); err != nil {
101+
c.mountm.DeleteIfNotManaged(r.Name)
102+
103+
if err := os.RemoveAll(hostdir); err != nil {
136104
return volume.Response{Err: err.Error()}
137105
}
138106

139107
return volume.Response{}
140108
}
141109

142-
func (s cifsDriver) fixSource(name string) string {
143-
return "//" + name
110+
func (c cifsDriver) fixSource(r volume.Request) string {
111+
if c.mountm.HasOption(r.Name, ShareOpt) {
112+
return "//" + c.mountm.GetOption(r.Name, ShareOpt)
113+
}
114+
return "//" + r.Name
144115
}
145116

146-
func parseHost(name string) string {
117+
func (c cifsDriver) parseHost(r volume.Request) string {
118+
name := r.Name
119+
if c.mountm.HasOption(r.Name, ShareOpt) {
120+
name = c.mountm.GetOption(r.Name, ShareOpt)
121+
}
122+
147123
if strings.ContainsAny(name, "/") {
148124
s := strings.Split(name, "/")
149125
return s[0]
150126
}
151127
return name
152128
}
153129

154-
func (s cifsDriver) mountVolume(source, dest string, creds *cifsCreds) error {
130+
func (s cifsDriver) mountVolume(name, source, dest string, creds *cifsCreds) error {
155131
var opts bytes.Buffer
156132

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

163-
if s.mountm.HasOptions(dest) {
164-
mopts := s.mountm.GetOptions(dest)
139+
if s.mountm.HasOptions(name) {
140+
mopts := s.mountm.GetOptions(name)
165141
if v, found := mopts[UsernameOpt]; found {
166142
user = v
167143
}
@@ -197,7 +173,7 @@ func (s cifsDriver) mountVolume(source, dest string, creds *cifsCreds) error {
197173

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

0 commit comments

Comments
 (0)