├── Dockerfile ├── Makefile └── stub.go /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.1 2 | ENV GOPATH /go 3 | RUN apk -U add go git mercurial 4 | COPY . /go/src/github.com/progrium/docker-plugins-stub 5 | WORKDIR /go/src/github.com/progrium/docker-plugins-stub 6 | RUN go get 7 | CMD go get \ 8 | && go build -o /bin/stub \ 9 | && exec /bin/stub 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=docker-plugins-stub 2 | 3 | dev: 4 | @docker history $(NAME):dev &> /dev/null \ 5 | || docker build -f Dockerfile -t $(NAME):dev . 6 | @docker run --rm --plugin \ 7 | -v $(PWD):/go/src/github.com/progrium/docker-plugins-stub \ 8 | -p 8000:8000 \ 9 | $(NAME):dev 10 | -------------------------------------------------------------------------------- /stub.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "net" 7 | "net/http" 8 | ) 9 | 10 | type handshakeResp struct { 11 | InterestedIn []string 12 | Name string 13 | Author string 14 | Org string 15 | Website string 16 | } 17 | 18 | type VolumeExtensionReq struct { 19 | HostPath string 20 | ContainerID string 21 | } 22 | 23 | type VolumeExtensionResp struct { 24 | ModifiedHostPath string 25 | } 26 | 27 | func main() { 28 | http.HandleFunc("/v1/handshake", func(w http.ResponseWriter, r *http.Request) { 29 | err := json.NewEncoder(w).Encode(&handshakeResp{ 30 | InterestedIn: []string{"volume"}, 31 | Name: "stub", 32 | Author: "progrium", 33 | Org: "no, wut?", 34 | Website: "http://progrium.com", 35 | }) 36 | if err != nil { 37 | log.Println("handshake encode:", err) 38 | http.Error(w, "encode error", http.StatusInternalServerError) 39 | return 40 | } 41 | log.Println("handshake success") 42 | }) 43 | 44 | http.HandleFunc("/v1/volume/volumes", func(w http.ResponseWriter, r *http.Request) { 45 | defer r.Body.Close() 46 | var extReq VolumeExtensionReq 47 | err := json.NewDecoder(r.Body).Decode(&extReq) 48 | if err != nil { 49 | log.Println("bad request:", err) 50 | http.Error(w, "bad request", http.StatusBadRequest) 51 | return 52 | } 53 | 54 | log.Println("req:", extReq) 55 | 56 | err = json.NewEncoder(w).Encode(&VolumeExtensionResp{ 57 | ModifiedHostPath: extReq.HostPath, 58 | }) 59 | if err != nil { 60 | log.Println("resp encode:", err) 61 | } 62 | }) 63 | 64 | sock := "/var/run/docker-plugin/p.s" 65 | l, err := net.Listen("unix", sock) 66 | if err != nil { 67 | log.Fatal(err) 68 | } 69 | log.Printf("listening on %s ...\n", sock) 70 | log.Fatal(http.Serve(l, nil)) 71 | } 72 | --------------------------------------------------------------------------------