Update go-dockerclient godep.

Adds support for new Docker remote API.
This commit is contained in:
Victor Marmol
2015-05-18 18:02:34 -07:00
parent 2c81050e6f
commit eb4d90f109
118 changed files with 13076 additions and 454 deletions

View File

@@ -9,7 +9,7 @@ main() {
check_fmt() {
eval "set -e"
for file in $(git ls-files '*.go') ; do
for file in $(_list_go_files) ; do
gofmt $file | diff -u $file -
done
eval "set +e"
@@ -18,7 +18,7 @@ check_fmt() {
check_lint() {
_install_linter
for file in $(git ls-files '*.go') ; do
for file in $(_list_go_files) ; do
if [[ ! "$(${GOPATH}/bin/golint $file)" =~ ^[[:blank:]]*$ ]] ; then
_lint_verbose && exit 1
fi
@@ -26,7 +26,7 @@ check_lint() {
}
_lint_verbose() {
for file in $(git ls-files '*.go') ; do $GOPATH/bin/golint $file ; done
for file in $(_list_go_files) ; do $GOPATH/bin/golint $file ; done
}
_install_linter() {
@@ -35,4 +35,8 @@ _install_linter() {
fi
}
_list_go_files() {
git ls-files '*.go' | grep -v '^vendor/'
}
main "$@"

View File

@@ -22,7 +22,7 @@ import (
"time"
"github.com/fsouza/go-dockerclient"
"github.com/gorilla/mux"
"github.com/fsouza/go-dockerclient/vendor/github.com/gorilla/mux"
)
var nameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]+$`)
@@ -533,8 +533,19 @@ func (s *DockerServer) attachContainer(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
outStream := newStdWriter(w, stdout)
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
hijacker, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "cannot hijack connection", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/vnd.docker.raw-stream")
w.WriteHeader(http.StatusOK)
conn, _, err := hijacker.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
outStream := newStdWriter(conn, stdout)
if container.State.Running {
fmt.Fprintf(outStream, "Container %q is running\n", container.ID)
} else {
@@ -542,6 +553,7 @@ func (s *DockerServer) attachContainer(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprintln(outStream, "What happened?")
fmt.Fprintln(outStream, "Something happened")
conn.Close()
}
func (s *DockerServer) waitContainer(w http.ResponseWriter, r *http.Request) {
@@ -566,12 +578,13 @@ func (s *DockerServer) waitContainer(w http.ResponseWriter, r *http.Request) {
func (s *DockerServer) removeContainer(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
force := r.URL.Query().Get("force")
_, index, err := s.findContainer(id)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if s.containers[index].State.Running {
if s.containers[index].State.Running && force != "1" {
msg := "Error: API error (406): Impossible to remove a running container, please stop it first"
http.Error(w, msg, http.StatusInternalServerError)
return

View File

@@ -850,6 +850,23 @@ func TestRemoveContainerRunning(t *testing.T) {
}
}
func TestRemoveContainerRunningForce(t *testing.T) {
server := DockerServer{}
addContainers(&server, 1)
server.containers[0].State.Running = true
server.buildMuxer()
recorder := httptest.NewRecorder()
path := fmt.Sprintf("/containers/%s?%s", server.containers[0].ID, "force=1")
request, _ := http.NewRequest("DELETE", path, nil)
server.ServeHTTP(recorder, request)
if recorder.Code != http.StatusNoContent {
t.Errorf("RemoveContainer: wrong status. Want %d. Got %d.", http.StatusNoContent, recorder.Code)
}
if len(server.containers) > 0 {
t.Error("RemoveContainer: did not remove the container.")
}
}
func TestPullImage(t *testing.T) {
server := DockerServer{imgIDs: make(map[string]string)}
server.buildMuxer()