Merge pull request #4593 from crosbymichael/move-server
Move server and buildfile into server pkg
This commit is contained in:
commit
2c10fcc432
|
@ -3,9 +3,9 @@ package builtins
|
|||
import (
|
||||
"github.com/dotcloud/docker/engine"
|
||||
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/api"
|
||||
"github.com/dotcloud/docker/networkdriver/lxc"
|
||||
"github.com/dotcloud/docker/server"
|
||||
)
|
||||
|
||||
func Register(eng *engine.Engine) {
|
||||
|
@ -34,6 +34,6 @@ func remote(eng *engine.Engine) {
|
|||
// These components should be broken off into plugins of their own.
|
||||
//
|
||||
func daemon(eng *engine.Engine) {
|
||||
eng.Register("initserver", docker.InitServer)
|
||||
eng.Register("initserver", server.InitServer)
|
||||
eng.Register("init_networkdriver", lxc.InitDriver)
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package docker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/archive"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/image"
|
||||
"github.com/dotcloud/docker/nat"
|
||||
"github.com/dotcloud/docker/server"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
|
@ -384,7 +384,7 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u
|
|||
}
|
||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||
|
||||
buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
id, err := buildfile.Build(context.Archive(dockerfile, t))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -799,7 +799,7 @@ func TestForbiddenContextPath(t *testing.T) {
|
|||
}
|
||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||
|
||||
buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||
|
||||
if err == nil {
|
||||
|
@ -845,7 +845,7 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
|||
}
|
||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||
|
||||
buildfile := docker.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
buildfile := server.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
||||
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||
|
||||
if err == nil {
|
||||
|
@ -917,8 +917,8 @@ func TestBuildFails(t *testing.T) {
|
|||
func TestBuildFailsDockerfileEmpty(t *testing.T) {
|
||||
_, err := buildImage(testContextTemplate{``, nil, nil}, t, nil, true)
|
||||
|
||||
if err != docker.ErrDockerfileEmpty {
|
||||
t.Fatal("Expected: %v, got: %v", docker.ErrDockerfileEmpty, err)
|
||||
if err != server.ErrDockerfileEmpty {
|
||||
t.Fatal("Expected: %v, got: %v", server.ErrDockerfileEmpty, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/server"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -739,7 +739,7 @@ func TestListContainers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func assertContainerList(srv *docker.Server, all bool, limit int, since, before string, expected []string) bool {
|
||||
func assertContainerList(srv *server.Server, all bool, limit int, since, before string, expected []string) bool {
|
||||
job := srv.Eng.Job("containers")
|
||||
job.SetenvBool("all", all)
|
||||
job.SetenvInt("limit", limit)
|
||||
|
|
|
@ -14,11 +14,11 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/builtins"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/runtime"
|
||||
"github.com/dotcloud/docker/server"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
)
|
||||
|
||||
|
@ -149,14 +149,14 @@ func getContainer(eng *engine.Engine, id string, t utils.Fataler) *runtime.Conta
|
|||
return c
|
||||
}
|
||||
|
||||
func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Server {
|
||||
func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *server.Server {
|
||||
iSrv := eng.Hack_GetGlobalVar("httpapi.server")
|
||||
if iSrv == nil {
|
||||
panic("Legacy server field not set in engine")
|
||||
}
|
||||
srv, ok := iSrv.(*docker.Server)
|
||||
srv, ok := iSrv.(*server.Server)
|
||||
if !ok {
|
||||
panic("Legacy server field in engine does not cast to *docker.Server")
|
||||
panic("Legacy server field in engine does not cast to *server.Server")
|
||||
}
|
||||
return srv
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package docker
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
|
@ -591,34 +591,6 @@ func (b *buildFile) CmdAdd(args string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type StdoutFormater struct {
|
||||
io.Writer
|
||||
*utils.StreamFormatter
|
||||
}
|
||||
|
||||
func (sf *StdoutFormater) Write(buf []byte) (int, error) {
|
||||
formattedBuf := sf.StreamFormatter.FormatStream(string(buf))
|
||||
n, err := sf.Writer.Write(formattedBuf)
|
||||
if n != len(formattedBuf) {
|
||||
return n, io.ErrShortWrite
|
||||
}
|
||||
return len(buf), err
|
||||
}
|
||||
|
||||
type StderrFormater struct {
|
||||
io.Writer
|
||||
*utils.StreamFormatter
|
||||
}
|
||||
|
||||
func (sf *StderrFormater) Write(buf []byte) (int, error) {
|
||||
formattedBuf := sf.StreamFormatter.FormatStream("\033[91m" + string(buf) + "\033[0m")
|
||||
n, err := sf.Writer.Write(formattedBuf)
|
||||
if n != len(formattedBuf) {
|
||||
return n, io.ErrShortWrite
|
||||
}
|
||||
return len(buf), err
|
||||
}
|
||||
|
||||
func (b *buildFile) create() (*runtime.Container, error) {
|
||||
if b.image == "" {
|
||||
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
|
|
@ -1,4 +1,4 @@
|
|||
package docker
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -456,11 +456,11 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
|||
|
||||
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
||||
b := NewBuildFile(srv,
|
||||
&StdoutFormater{
|
||||
&utils.StdoutFormater{
|
||||
Writer: job.Stdout,
|
||||
StreamFormatter: sf,
|
||||
},
|
||||
&StderrFormater{
|
||||
&utils.StderrFormater{
|
||||
Writer: job.Stdout,
|
||||
StreamFormatter: sf,
|
||||
},
|
|
@ -1,4 +1,4 @@
|
|||
package docker
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/utils"
|
|
@ -3,6 +3,7 @@ package utils
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type StreamFormatter struct {
|
||||
|
@ -90,3 +91,31 @@ func (sf *StreamFormatter) Used() bool {
|
|||
func (sf *StreamFormatter) Json() bool {
|
||||
return sf.json
|
||||
}
|
||||
|
||||
type StdoutFormater struct {
|
||||
io.Writer
|
||||
*StreamFormatter
|
||||
}
|
||||
|
||||
func (sf *StdoutFormater) Write(buf []byte) (int, error) {
|
||||
formattedBuf := sf.StreamFormatter.FormatStream(string(buf))
|
||||
n, err := sf.Writer.Write(formattedBuf)
|
||||
if n != len(formattedBuf) {
|
||||
return n, io.ErrShortWrite
|
||||
}
|
||||
return len(buf), err
|
||||
}
|
||||
|
||||
type StderrFormater struct {
|
||||
io.Writer
|
||||
*StreamFormatter
|
||||
}
|
||||
|
||||
func (sf *StderrFormater) Write(buf []byte) (int, error) {
|
||||
formattedBuf := sf.StreamFormatter.FormatStream("\033[91m" + string(buf) + "\033[0m")
|
||||
n, err := sf.Writer.Write(formattedBuf)
|
||||
if n != len(formattedBuf) {
|
||||
return n, io.ErrShortWrite
|
||||
}
|
||||
return len(buf), err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue