mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
added commit
This commit is contained in:
parent
1e357c6969
commit
79512b2a80
3 changed files with 53 additions and 11 deletions
26
api.go
26
api.go
|
@ -347,6 +347,32 @@ func ListenAndServe(addr string, rtime *Runtime) error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.Path("/containers/{name:.*}/commit").Methods("POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Println(r.Method, r.RequestURI)
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
name := vars["name"]
|
||||||
|
repo := r.Form.Get("repo")
|
||||||
|
tag := r.Form.Get("tag")
|
||||||
|
comment := r.Form.Get("comment")
|
||||||
|
|
||||||
|
img, err := rtime.Commit(name, repo, tag, comment)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(ApiCommit{img.ShortId()})
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
} else {
|
||||||
|
w.Write(b)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
r.Path("/images/{name:.*}/tag").Methods("POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.Path("/images/{name:.*}/tag").Methods("POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(r.Method, r.RequestURI)
|
log.Println(r.Method, r.RequestURI)
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
|
|
|
@ -30,6 +30,10 @@ type ApiContainers struct {
|
||||||
Status string `json:",omitempty"`
|
Status string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApiCommit struct {
|
||||||
|
Id string
|
||||||
|
}
|
||||||
|
|
||||||
type ApiLogs struct {
|
type ApiLogs struct {
|
||||||
Stdout string
|
Stdout string
|
||||||
Stderr string
|
Stderr string
|
||||||
|
|
34
commands.go
34
commands.go
|
@ -26,6 +26,7 @@ var (
|
||||||
func ParseCommands(args []string) error {
|
func ParseCommands(args []string) error {
|
||||||
|
|
||||||
cmds := map[string]func(args []string) error{
|
cmds := map[string]func(args []string) error{
|
||||||
|
"commit": CmdCommit,
|
||||||
"diff": CmdDiff,
|
"diff": CmdDiff,
|
||||||
"images": CmdImages,
|
"images": CmdImages,
|
||||||
"info": CmdInfo,
|
"info": CmdInfo,
|
||||||
|
@ -62,7 +63,7 @@ func cmdHelp(args []string) error {
|
||||||
help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
|
help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
|
||||||
for _, cmd := range [][]string{
|
for _, cmd := range [][]string{
|
||||||
// {"attach", "Attach to a running container"},
|
// {"attach", "Attach to a running container"},
|
||||||
// {"commit", "Create a new image from a container's changes"},
|
{"commit", "Create a new image from a container's changes"},
|
||||||
{"diff", "Inspect changes on a container's filesystem"},
|
{"diff", "Inspect changes on a container's filesystem"},
|
||||||
// {"export", "Stream the contents of a container as a tar archive"},
|
// {"export", "Stream the contents of a container as a tar archive"},
|
||||||
{"history", "Show the history of an image"},
|
{"history", "Show the history of an image"},
|
||||||
|
@ -727,28 +728,36 @@ func CmdPs(args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func CmdCommit(args []string) error {
|
||||||
func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
cmd := Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]", "Create a new image from a container's changes")
|
||||||
cmd := rcli.Subcmd(stdout,
|
|
||||||
"commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]",
|
|
||||||
"Create a new image from a container's changes")
|
|
||||||
flComment := cmd.String("m", "", "Commit message")
|
flComment := cmd.String("m", "", "Commit message")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
containerName, repository, tag := cmd.Arg(0), cmd.Arg(1), cmd.Arg(2)
|
name, repository, tag := cmd.Arg(0), cmd.Arg(1), cmd.Arg(2)
|
||||||
if containerName == "" {
|
if name == "" {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
img, err := srv.runtime.Commit(containerName, repository, tag, *flComment)
|
v := url.Values{}
|
||||||
|
v.Set("repo", repository)
|
||||||
|
v.Set("tag", tag)
|
||||||
|
v.Set("comment", *flComment)
|
||||||
|
|
||||||
|
body, err := call("POST", "/containers/"+name+"/commit?"+v.Encode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(stdout, img.ShortId())
|
|
||||||
|
var out ApiCommit
|
||||||
|
err = json.Unmarshal(body, &out)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(out.Id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func (srv *Server) CmdExport(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
func (srv *Server) CmdExport(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||||
|
@ -959,6 +968,9 @@ func call(method, path string) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if method == "POST" {
|
||||||
|
req.Header.Set("Content-Type", "plain/text")
|
||||||
|
}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue