mirror of https://github.com/docker/docs.git
Merge remote-tracking branch 'origin/65-autodownload_unittest_image'
This commit is contained in:
commit
c65c1738b5
|
@ -1,4 +1,4 @@
|
||||||
package commands
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/fs"
|
"github.com/dotcloud/docker/fs"
|
||||||
"github.com/dotcloud/docker/future"
|
"github.com/dotcloud/docker/future"
|
||||||
"github.com/dotcloud/docker/rcli"
|
"github.com/dotcloud/docker/rcli"
|
||||||
|
@ -550,7 +549,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
||||||
if !*fl_full {
|
if !*fl_full {
|
||||||
command = docker.Trunc(command, 20)
|
command = Trunc(command, 20)
|
||||||
}
|
}
|
||||||
for idx, field := range []string{
|
for idx, field := range []string{
|
||||||
/* ID */ container.Id,
|
/* ID */ container.Id,
|
||||||
|
@ -741,10 +740,10 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
|
||||||
return errors.New("No such container: " + cmd.Arg(0))
|
return errors.New("No such container: " + cmd.Arg(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) CreateContainer(img *fs.Image, ports []int, user string, tty bool, openStdin bool, memory int64, comment string, cmd string, args ...string) (*docker.Container, error) {
|
func (srv *Server) CreateContainer(img *fs.Image, ports []int, user string, tty bool, openStdin bool, memory int64, comment string, cmd string, args ...string) (*Container, error) {
|
||||||
id := future.RandomId()[:8]
|
id := future.RandomId()[:8]
|
||||||
container, err := srv.containers.Create(id, cmd, args, img,
|
container, err := srv.containers.Create(id, cmd, args, img,
|
||||||
&docker.Config{
|
&Config{
|
||||||
Hostname: id,
|
Hostname: id,
|
||||||
Ports: ports,
|
Ports: ports,
|
||||||
User: user,
|
User: user,
|
||||||
|
@ -945,12 +944,12 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Server, error) {
|
func NewServer() (*Server, error) {
|
||||||
future.Seed()
|
future.Seed()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
containers, err := docker.New()
|
containers, err := New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1001,6 +1000,6 @@ func (srv *Server) CmdWeb(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
containers *docker.Docker
|
containers *Docker
|
||||||
images *fs.Store
|
images *fs.Store
|
||||||
}
|
}
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/dotcloud/docker"
|
"github.com/dotcloud/docker"
|
||||||
"github.com/dotcloud/docker/commands"
|
|
||||||
"github.com/dotcloud/docker/future"
|
"github.com/dotcloud/docker/future"
|
||||||
"github.com/dotcloud/docker/rcli"
|
"github.com/dotcloud/docker/rcli"
|
||||||
"github.com/dotcloud/docker/term"
|
"github.com/dotcloud/docker/term"
|
||||||
|
@ -36,7 +35,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func daemon() error {
|
func daemon() error {
|
||||||
service, err := commands.New()
|
service, err := docker.NewServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -78,7 +77,7 @@ func runCommand(args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
service, err := commands.New()
|
service, err := docker.NewServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,28 @@ import (
|
||||||
"github.com/dotcloud/docker/fs"
|
"github.com/dotcloud/docker/fs"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testLayerPath string = "/var/lib/docker/docker-ut.tar"
|
const testLayerPath string = "/var/lib/docker/docker-ut.tar"
|
||||||
|
const unitTestImageName string = "busybox"
|
||||||
|
|
||||||
|
var unitTestStoreBase string
|
||||||
|
var srv *Server
|
||||||
|
|
||||||
func nuke(docker *Docker) error {
|
func nuke(docker *Docker) error {
|
||||||
return os.RemoveAll(docker.root)
|
return os.RemoveAll(docker.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyDirectory(source, dest string) error {
|
||||||
|
if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func layerArchive(tarfile string) (io.Reader, error) {
|
func layerArchive(tarfile string) (io.Reader, error) {
|
||||||
// FIXME: need to close f somewhere
|
// FIXME: need to close f somewhere
|
||||||
f, err := os.Open(tarfile)
|
f, err := os.Open(tarfile)
|
||||||
|
@ -28,15 +39,29 @@ func init() {
|
||||||
// Hack to run sys init during unit testing
|
// Hack to run sys init during unit testing
|
||||||
if SelfPath() == "/sbin/init" {
|
if SelfPath() == "/sbin/init" {
|
||||||
SysInit()
|
SysInit()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the unit test image is there
|
// Create a temp directory
|
||||||
if _, err := os.Stat(testLayerPath); err != nil {
|
root, err := ioutil.TempDir("", "docker-test")
|
||||||
if !os.IsNotExist(err) {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Fatalf("Unit test base image not found. Please fix the problem by running \"debootstrap --arch=amd64 quantal %v\"", testLayerPath)
|
unitTestStoreBase = root
|
||||||
return
|
|
||||||
|
// Make it our Store root
|
||||||
|
docker, err := NewFromDirectory(root)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
// Create the "Server"
|
||||||
|
srv := &Server{
|
||||||
|
images: docker.Store,
|
||||||
|
containers: docker,
|
||||||
|
}
|
||||||
|
// Retrieve the Image
|
||||||
|
if err := srv.CmdImport(os.Stdin, os.Stdout, unitTestImageName); err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,19 +70,19 @@ func newTestDocker() (*Docker, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := os.Remove(root); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := CopyDirectory(unitTestStoreBase, root); err != nil {
|
||||||
|
panic(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
docker, err := NewFromDirectory(root)
|
docker, err := NewFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if layer, err := layerArchive(testLayerPath); err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else {
|
|
||||||
_, err = docker.Store.Create(layer, nil, "docker-ut", "unit tests")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return docker, nil
|
return docker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,25 +256,22 @@ func TestGet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestore(t *testing.T) {
|
func TestRestore(t *testing.T) {
|
||||||
|
|
||||||
root, err := ioutil.TempDir("", "docker-test")
|
root, err := ioutil.TempDir("", "docker-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err := os.Remove(root); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := CopyDirectory(unitTestStoreBase, root); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
docker1, err := NewFromDirectory(root)
|
docker1, err := NewFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer nuke(docker1)
|
|
||||||
|
|
||||||
if layer, err := layerArchive(testLayerPath); err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else {
|
|
||||||
_, err = docker1.Store.Create(layer, nil, "docker-ut", "unit tests")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a container with one instance of docker
|
// Create a container with one instance of docker
|
||||||
container1, err := docker1.Create(
|
container1, err := docker1.Create(
|
||||||
|
|
Loading…
Reference in New Issue