mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
move commit to job
This commit is contained in:
parent
aaa1c48d24
commit
930ec9f52c
5 changed files with 71 additions and 25 deletions
19
api.go
19
api.go
|
@ -377,13 +377,18 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
|
|||
if err := json.NewDecoder(r.Body).Decode(config); err != nil && err != io.EOF {
|
||||
utils.Errorf("%s", err)
|
||||
}
|
||||
repo := r.Form.Get("repo")
|
||||
tag := r.Form.Get("tag")
|
||||
container := r.Form.Get("container")
|
||||
author := r.Form.Get("author")
|
||||
comment := r.Form.Get("comment")
|
||||
id, err := srv.ContainerCommit(container, repo, tag, author, comment, config)
|
||||
if err != nil {
|
||||
|
||||
job := srv.Eng.Job("commit")
|
||||
job.Setenv("repo", r.Form.Get("repo"))
|
||||
job.Setenv("tag", r.Form.Get("tag"))
|
||||
job.Setenv("container", r.Form.Get("container"))
|
||||
job.Setenv("author", r.Form.Get("author"))
|
||||
job.Setenv("comment", r.Form.Get("comment"))
|
||||
job.SetenvJson("config", config)
|
||||
|
||||
var id string
|
||||
job.Stdout.AddString(&id)
|
||||
if err := job.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"io"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Env []string
|
||||
|
||||
|
||||
func (env *Env) Get(key string) (value string) {
|
||||
// FIXME: use Map()
|
||||
for _, kv := range *env {
|
||||
|
@ -44,7 +43,6 @@ func (env *Env) GetBool(key string) (value bool) {
|
|||
return true
|
||||
}
|
||||
|
||||
|
||||
func (env *Env) SetBool(key string, value bool) {
|
||||
if value {
|
||||
env.Set(key, "1")
|
||||
|
@ -79,6 +77,17 @@ func (env *Env) GetList(key string) []string {
|
|||
return l
|
||||
}
|
||||
|
||||
func (env *Env) GetJson(key string) interface{} {
|
||||
sval := env.Get(key)
|
||||
if sval == "" {
|
||||
return nil
|
||||
}
|
||||
var m interface{}
|
||||
//Discard error on purpose
|
||||
json.Unmarshal([]byte(sval), &m)
|
||||
return m
|
||||
}
|
||||
|
||||
func (env *Env) SetJson(key string, value interface{}) error {
|
||||
sval, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
|
@ -218,4 +227,3 @@ func (env *Env) Map() map[string]string {
|
|||
}
|
||||
return m
|
||||
}
|
||||
|
||||
|
|
|
@ -126,6 +126,10 @@ func (job *Job) GetenvList(key string) []string {
|
|||
return job.env.GetList(key)
|
||||
}
|
||||
|
||||
func (job *Job) GetenvJson(key string) interface{} {
|
||||
return job.env.GetJson(key)
|
||||
}
|
||||
|
||||
func (job *Job) SetenvJson(key string, value interface{}) error {
|
||||
return job.env.SetJson(key, value)
|
||||
}
|
||||
|
|
|
@ -146,7 +146,6 @@ func TestCreateRmVolumes(t *testing.T) {
|
|||
|
||||
func TestCommit(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
srv := mkServerFromEngine(eng, t)
|
||||
defer mkRuntimeFromEngine(eng, t).Nuke()
|
||||
|
||||
config, _, _, err := docker.ParseRun([]string{unitTestImageID, "/bin/cat"}, nil)
|
||||
|
@ -156,7 +155,12 @@ func TestCommit(t *testing.T) {
|
|||
|
||||
id := createTestContainer(eng, config, t)
|
||||
|
||||
if _, err := srv.ContainerCommit(id, "testrepo", "testtag", "", "", config); err != nil {
|
||||
job := eng.Job("commit")
|
||||
job.Setenv("container", id)
|
||||
job.Setenv("repo", "testrepo")
|
||||
job.Setenv("tag", "testtag")
|
||||
job.SetenvJson("config", config)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -264,8 +268,12 @@ func TestRmi(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
imageID, err := srv.ContainerCommit(containerID, "test", "", "", "", nil)
|
||||
if err != nil {
|
||||
job = eng.Job("commit")
|
||||
job.Setenv("container", containerID)
|
||||
job.Setenv("repo", "test")
|
||||
var imageID string
|
||||
job.Stdout.AddString(&imageID)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -288,8 +296,10 @@ func TestRmi(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = srv.ContainerCommit(containerID, "test", "", "", "", nil)
|
||||
if err != nil {
|
||||
job = eng.Job("commit")
|
||||
job.Setenv("container", containerID)
|
||||
job.Setenv("repo", "test")
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
29
server.go
29
server.go
|
@ -107,6 +107,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("commit", srv.ContainerCommit); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
@ -769,16 +773,31 @@ func createAPIContainer(names []string, container *Container, size bool, runtime
|
|||
}
|
||||
return c
|
||||
}
|
||||
func (srv *Server) ContainerCommit(name, repo, tag, author, comment string, config *Config) (string, error) {
|
||||
func (srv *Server) ContainerCommit(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 0 {
|
||||
job.Errorf("Usage: %s\n", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
name := job.Getenv("container")
|
||||
|
||||
container := srv.runtime.Get(name)
|
||||
if container == nil {
|
||||
return "", fmt.Errorf("No such container: %s", name)
|
||||
job.Errorf("No such container: %s", name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
img, err := srv.runtime.Commit(container, repo, tag, comment, author, config)
|
||||
var config *Config
|
||||
iConfig, ok := job.GetenvJson("config").(Config)
|
||||
if ok {
|
||||
config = &iConfig
|
||||
}
|
||||
|
||||
img, err := srv.runtime.Commit(container, job.Getenv("repo"), job.Getenv("tag"), job.Getenv("comment"), job.Getenv("author"), config)
|
||||
if err != nil {
|
||||
return "", err
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return img.ID, err
|
||||
job.Printf("%s\n", img.ID)
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) ImageTag(job *engine.Job) engine.Status {
|
||||
|
|
Loading…
Reference in a new issue