move tag to job

This commit is contained in:
Victor Vieux 2013-12-11 17:52:41 -08:00
parent b722f809e7
commit e43ff2f6f2
5 changed files with 32 additions and 25 deletions

11
api.go
View file

@ -356,18 +356,13 @@ func postImagesTag(srv *Server, version float64, w http.ResponseWriter, r *http.
if err := parseForm(r); err != nil {
return err
}
repo := r.Form.Get("repo")
tag := r.Form.Get("tag")
if vars == nil {
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
force, err := getBoolParam(r.Form.Get("force"))
if err != nil {
return err
}
if err := srv.ContainerTag(name, repo, tag, force); err != nil {
job := srv.Eng.Job("tag", vars["name"], r.Form.Get("repo"), r.Form.Get("tag"))
job.Setenv("force", r.Form.Get("force"))
if err := job.Run(); err != nil {
return err
}
w.WriteHeader(http.StatusCreated)

View file

@ -1120,7 +1120,7 @@ func TestDeleteImages(t *testing.T) {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "test", "test", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "test", "test").Run(); err != nil {
t.Fatal(err)
}
images, err := srv.Images(false, "")

View file

@ -910,8 +910,7 @@ run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]
t.Fatal(err)
}
err = mkServerFromEngine(eng, t).ContainerTag(image.ID, "test", "latest", false)
if err != nil {
if err := eng.Job("tag", image.ID, "test").Run(); err != nil {
t.Fatal(err)
}

View file

@ -8,7 +8,7 @@ import (
"testing"
)
func TestContainerTagImageDelete(t *testing.T) {
func TestImageTagImageDelete(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
@ -18,14 +18,15 @@ func TestContainerTagImageDelete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "utest", "tag1", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "utest/docker", "tag2", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "utest:5000/docker", "tag3", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
t.Fatal(err)
}
@ -265,8 +266,7 @@ func TestRmi(t *testing.T) {
t.Fatal(err)
}
err = srv.ContainerTag(imageID, "test", "0.1", false)
if err != nil {
if err := eng.Job("tag", imageID, "test", "0.1").Run(); err != nil {
t.Fatal(err)
}
@ -329,14 +329,15 @@ func TestImagesFilter(t *testing.T) {
srv := mkServerFromEngine(eng, t)
if err := srv.ContainerTag(unitTestImageName, "utest", "tag1", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "utest/docker", "tag2", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
t.Fatal(err)
}
if err := srv.ContainerTag(unitTestImageName, "utest:5000/docker", "tag3", false); err != nil {
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
t.Fatal(err)
}

View file

@ -95,6 +95,10 @@ func jobInitApi(job *engine.Job) engine.Status {
job.Error(err)
return engine.StatusErr
}
if err := job.Eng.Register("tag", srv.ImageTag); err != nil {
job.Error(err)
return engine.StatusErr
}
return engine.StatusOK
}
@ -769,12 +773,20 @@ func (srv *Server) ContainerCommit(name, repo, tag, author, comment string, conf
return img.ID, err
}
// FIXME: this should be called ImageTag
func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
if err := srv.runtime.repositories.Set(repo, tag, name, force); err != nil {
return err
func (srv *Server) ImageTag(job *engine.Job) engine.Status {
if len(job.Args) != 2 && len(job.Args) != 3 {
job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
return engine.StatusErr
}
return nil
var tag string
if len(job.Args) == 3 {
tag = job.Args[2]
}
if err := srv.runtime.repositories.Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
job.Error(err)
return engine.StatusErr
}
return engine.StatusOK
}
func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoint string, token []string, sf *utils.StreamFormatter) error {