mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #4593 from crosbymichael/move-server
Move server and buildfile into server pkg
This commit is contained in:
commit
2c10fcc432
8 changed files with 48 additions and 47 deletions
|
@ -3,9 +3,9 @@ package builtins
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
|
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/api"
|
"github.com/dotcloud/docker/api"
|
||||||
"github.com/dotcloud/docker/networkdriver/lxc"
|
"github.com/dotcloud/docker/networkdriver/lxc"
|
||||||
|
"github.com/dotcloud/docker/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Register(eng *engine.Engine) {
|
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.
|
// These components should be broken off into plugins of their own.
|
||||||
//
|
//
|
||||||
func daemon(eng *engine.Engine) {
|
func daemon(eng *engine.Engine) {
|
||||||
eng.Register("initserver", docker.InitServer)
|
eng.Register("initserver", server.InitServer)
|
||||||
eng.Register("init_networkdriver", lxc.InitDriver)
|
eng.Register("init_networkdriver", lxc.InitDriver)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/image"
|
"github.com/dotcloud/docker/image"
|
||||||
"github.com/dotcloud/docker/nat"
|
"github.com/dotcloud/docker/nat"
|
||||||
|
"github.com/dotcloud/docker/server"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
@ -384,7 +384,7 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
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))
|
id, err := buildfile.Build(context.Archive(dockerfile, t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -799,7 +799,7 @@ func TestForbiddenContextPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
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))
|
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -845,7 +845,7 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
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))
|
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -917,8 +917,8 @@ func TestBuildFails(t *testing.T) {
|
||||||
func TestBuildFailsDockerfileEmpty(t *testing.T) {
|
func TestBuildFailsDockerfileEmpty(t *testing.T) {
|
||||||
_, err := buildImage(testContextTemplate{``, nil, nil}, t, nil, true)
|
_, err := buildImage(testContextTemplate{``, nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if err != docker.ErrDockerfileEmpty {
|
if err != server.ErrDockerfileEmpty {
|
||||||
t.Fatal("Expected: %v, got: %v", docker.ErrDockerfileEmpty, err)
|
t.Fatal("Expected: %v, got: %v", server.ErrDockerfileEmpty, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/runconfig"
|
"github.com/dotcloud/docker/runconfig"
|
||||||
|
"github.com/dotcloud/docker/server"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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 := srv.Eng.Job("containers")
|
||||||
job.SetenvBool("all", all)
|
job.SetenvBool("all", all)
|
||||||
job.SetenvInt("limit", limit)
|
job.SetenvInt("limit", limit)
|
||||||
|
|
|
@ -14,11 +14,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/builtins"
|
"github.com/dotcloud/docker/builtins"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/runconfig"
|
"github.com/dotcloud/docker/runconfig"
|
||||||
"github.com/dotcloud/docker/runtime"
|
"github.com/dotcloud/docker/runtime"
|
||||||
|
"github.com/dotcloud/docker/server"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -149,14 +149,14 @@ func getContainer(eng *engine.Engine, id string, t utils.Fataler) *runtime.Conta
|
||||||
return c
|
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")
|
iSrv := eng.Hack_GetGlobalVar("httpapi.server")
|
||||||
if iSrv == nil {
|
if iSrv == nil {
|
||||||
panic("Legacy server field not set in engine")
|
panic("Legacy server field not set in engine")
|
||||||
}
|
}
|
||||||
srv, ok := iSrv.(*docker.Server)
|
srv, ok := iSrv.(*server.Server)
|
||||||
if !ok {
|
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
|
return srv
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package docker
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
@ -591,34 +591,6 @@ func (b *buildFile) CmdAdd(args string) error {
|
||||||
return nil
|
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) {
|
func (b *buildFile) create() (*runtime.Container, error) {
|
||||||
if b.image == "" {
|
if b.image == "" {
|
||||||
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
|
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
|
|
@ -1,4 +1,4 @@
|
||||||
package docker
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -456,11 +456,11 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
||||||
|
|
||||||
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
||||||
b := NewBuildFile(srv,
|
b := NewBuildFile(srv,
|
||||||
&StdoutFormater{
|
&utils.StdoutFormater{
|
||||||
Writer: job.Stdout,
|
Writer: job.Stdout,
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
},
|
},
|
||||||
&StderrFormater{
|
&utils.StderrFormater{
|
||||||
Writer: job.Stdout,
|
Writer: job.Stdout,
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
},
|
},
|
|
@ -1,4 +1,4 @@
|
||||||
package docker
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
|
@ -3,6 +3,7 @@ package utils
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StreamFormatter struct {
|
type StreamFormatter struct {
|
||||||
|
@ -90,3 +91,31 @@ func (sf *StreamFormatter) Used() bool {
|
||||||
func (sf *StreamFormatter) Json() bool {
|
func (sf *StreamFormatter) Json() bool {
|
||||||
return sf.json
|
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 a new issue