зеркало из https://github.com/microsoft/docker.git
Add a Debugf() helper and a -D (debug) flag to docker
This commit is contained in:
Родитель
c57727fd65
Коммит
6e507b9460
|
@ -16,8 +16,11 @@ func main() {
|
||||||
docker.SysInit()
|
docker.SysInit()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// FIXME: Switch d and D ? (to be more sshd like)
|
||||||
fl_daemon := flag.Bool("d", false, "Daemon mode")
|
fl_daemon := flag.Bool("d", false, "Daemon mode")
|
||||||
|
fl_debug := flag.Bool("D", false, "Debug mode")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
rcli.DEBUG_FLAG = *fl_debug
|
||||||
if *fl_daemon {
|
if *fl_daemon {
|
||||||
if flag.NArg() != 0 {
|
if flag.NArg() != 0 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
|
|
|
@ -10,6 +10,11 @@ import (
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Note: the globals are here to avoid import cycle
|
||||||
|
// FIXME: Handle debug levels mode?
|
||||||
|
var DEBUG_FLAG bool = false
|
||||||
|
var CLIENT_SOCKET io.Writer = nil
|
||||||
|
|
||||||
// Connect to a remote endpoint using protocol `proto` and address `addr`,
|
// Connect to a remote endpoint using protocol `proto` and address `addr`,
|
||||||
// issue a single call, and return the result.
|
// issue a single call, and return the result.
|
||||||
// `proto` may be "tcp", "unix", etc. See the `net` package for available protocols.
|
// `proto` may be "tcp", "unix", etc. See the `net` package for available protocols.
|
||||||
|
@ -42,6 +47,9 @@ func ListenAndServe(proto, addr string, service Service) error {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
go func() {
|
go func() {
|
||||||
|
if DEBUG_FLAG {
|
||||||
|
CLIENT_SOCKET = conn
|
||||||
|
}
|
||||||
if err := Serve(conn, service); err != nil {
|
if err := Serve(conn, service); err != nil {
|
||||||
log.Printf("Error: " + err.Error() + "\n")
|
log.Printf("Error: " + err.Error() + "\n")
|
||||||
fmt.Fprintf(conn, "Error: "+err.Error()+"\n")
|
fmt.Fprintf(conn, "Error: "+err.Error()+"\n")
|
||||||
|
|
|
@ -213,6 +213,9 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error while retreiving the path for {%s}: %s", img.Id, err)
|
return fmt.Errorf("Error while retreiving the path for {%s}: %s", img.Id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debugf("Pushing image [%s] on {%s}\n", img.Id, REGISTRY_ENDPOINT+"/images/"+img.Id+"/json")
|
||||||
|
|
||||||
// FIXME: try json with UTF8
|
// FIXME: try json with UTF8
|
||||||
jsonData := strings.NewReader(string(jsonRaw))
|
jsonData := strings.NewReader(string(jsonRaw))
|
||||||
req, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/images/"+img.Id+"/json", jsonData)
|
req, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/images/"+img.Id+"/json", jsonData)
|
||||||
|
@ -257,6 +260,7 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
|
||||||
"Fail to retrieve layer storage URL for image {%s}: %s\n",
|
"Fail to retrieve layer storage URL for image {%s}: %s\n",
|
||||||
img.Id, err)
|
img.Id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Don't do this :D. Check the S3 requierement and implement chunks of 5MB
|
// FIXME: Don't do this :D. Check the S3 requierement and implement chunks of 5MB
|
||||||
// FIXME2: I won't stress it enough, DON'T DO THIS! very high priority
|
// FIXME2: I won't stress it enough, DON'T DO THIS! very high priority
|
||||||
layerData2, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip)
|
layerData2, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip)
|
||||||
|
@ -307,6 +311,8 @@ func (graph *Graph) pushTag(remote, revision, tag string, authConfig *auth.AuthC
|
||||||
// "jsonify" the string
|
// "jsonify" the string
|
||||||
revision = "\"" + revision + "\""
|
revision = "\"" + revision + "\""
|
||||||
|
|
||||||
|
Debugf("Pushing tags for rev [%s] on {%s}\n", revision, REGISTRY_ENDPOINT+"/users/"+remote+"/"+tag)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/users/"+remote+"/"+tag, strings.NewReader(revision))
|
req, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/users/"+remote+"/"+tag, strings.NewReader(revision))
|
||||||
req.Header.Add("Content-type", "application/json")
|
req.Header.Add("Content-type", "application/json")
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/dotcloud/docker/auth"
|
"github.com/dotcloud/docker/auth"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -216,10 +215,10 @@ func (runtime *Runtime) restore() error {
|
||||||
id := v.Name()
|
id := v.Name()
|
||||||
container, err := runtime.Load(id)
|
container, err := runtime.Load(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to load container %v: %v", id, err)
|
Debugf("Failed to load container %v: %v", id, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Loaded container %v", container.Id)
|
Debugf("Loaded container %v", container.Id)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
13
utils.go
13
utils.go
|
@ -5,7 +5,9 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/rcli"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -37,6 +39,17 @@ func Download(url string, stderr io.Writer) (*http.Response, error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug function, if the debug flag is set, then display. Do nothing otherwise
|
||||||
|
// If Docker is in damon mode, also send the debug info on the socket
|
||||||
|
func Debugf(format string, a ...interface{}) {
|
||||||
|
if rcli.DEBUG_FLAG {
|
||||||
|
log.Printf(format, a...)
|
||||||
|
if rcli.CLIENT_SOCKET != nil {
|
||||||
|
fmt.Fprintf(rcli.CLIENT_SOCKET, log.Prefix()+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reader with progress bar
|
// Reader with progress bar
|
||||||
type progressReader struct {
|
type progressReader struct {
|
||||||
reader io.ReadCloser // Stream to read from
|
reader io.ReadCloser // Stream to read from
|
||||||
|
|
Загрузка…
Ссылка в новой задаче