This commit is contained in:
Solomon Hykes 2013-02-26 17:26:46 -08:00
parent 4004e86fa9
commit aa12da6f50
12 changed files with 152 additions and 168 deletions

View File

@ -1,8 +1,8 @@
package client package client
import ( import (
"github.com/dotcloud/docker/rcli"
"github.com/dotcloud/docker/future" "github.com/dotcloud/docker/future"
"github.com/dotcloud/docker/rcli"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
@ -112,7 +112,7 @@ func InteractiveMode(scripts ...string) error {
return err return err
} }
io.WriteString(rcfile, "enable -n help\n") io.WriteString(rcfile, "enable -n help\n")
os.Setenv("PATH", tmp + ":" + os.Getenv("PATH")) os.Setenv("PATH", tmp+":"+os.Getenv("PATH"))
os.Setenv("PS1", "\\h docker> ") os.Setenv("PS1", "\\h docker> ")
shell := exec.Command("/bin/bash", append([]string{"--rcfile", rcfile.Name()}, scripts...)...) shell := exec.Command("/bin/bash", append([]string{"--rcfile", rcfile.Name()}, scripts...)...)
shell.Stdin = os.Stdin shell.Stdin = os.Stdin

View File

@ -15,7 +15,6 @@ type Termios struct {
Ospeed uintptr Ospeed uintptr
} }
const ( const (
// Input flags // Input flags
inpck = 0x010 inpck = 0x010
@ -74,7 +73,7 @@ const (
ONOCR = 0x20 ONOCR = 0x20
ONOEOT = 0x8 ONOEOT = 0x8
OPOST = 0x1 OPOST = 0x1
RENB = 0x1000 RENB = 0x1000
PARMRK = 0x8 PARMRK = 0x8
PARODD = 0x2000 PARODD = 0x2000
@ -136,12 +135,9 @@ func MakeRaw(fd int) (*State, error) {
return &oldState, nil return &oldState, nil
} }
// Restore restores the terminal connected to the given file descriptor to a // Restore restores the terminal connected to the given file descriptor to a
// previous state. // previous state.
func Restore(fd int, state *State) error { func Restore(fd int, state *State) error {
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0) _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
return err return err
} }

View File

@ -2,10 +2,10 @@ package main
import ( import (
"flag" "flag"
"github.com/dotcloud/docker/client"
"log" "log"
"os" "os"
"path" "path"
"github.com/dotcloud/docker/client"
) )
func main() { func main() {
@ -27,4 +27,3 @@ func main() {
} }
} }
} }

View File

@ -1,20 +1,19 @@
package fake package fake
import ( import (
"bytes"
"math/rand"
"io"
"archive/tar" "archive/tar"
"os/exec" "bytes"
"github.com/kr/pty" "github.com/kr/pty"
"io"
"math/rand"
"os/exec"
) )
func FakeTar() (io.Reader, error) { func FakeTar() (io.Reader, error) {
content := []byte("Hello world!\n") content := []byte("Hello world!\n")
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
tw := tar.NewWriter(buf) tw := tar.NewWriter(buf)
for _, name := range []string {"hello", "etc/postgres/postgres.conf", "etc/passwd", "var/log/postgres/postgres.conf"} { for _, name := range []string{"hello", "etc/postgres/postgres.conf", "etc/passwd", "var/log/postgres/postgres.conf"} {
hdr := new(tar.Header) hdr := new(tar.Header)
hdr.Size = int64(len(content)) hdr.Size = int64(len(content))
hdr.Name = name hdr.Name = name
@ -27,7 +26,6 @@ func FakeTar() (io.Reader, error) {
return buf, nil return buf, nil
} }
func WriteFakeTar(dst io.Writer) error { func WriteFakeTar(dst io.Writer) error {
if data, err := FakeTar(); err != nil { if data, err := FakeTar(); err != nil {
return err return err
@ -37,7 +35,6 @@ func WriteFakeTar(dst io.Writer) error {
return nil return nil
} }
func RandomBytesChanged() uint { func RandomBytesChanged() uint {
return uint(rand.Int31n(24 * 1024 * 1024)) return uint(rand.Int31n(24 * 1024 * 1024))
} }
@ -54,7 +51,6 @@ func ContainerRunning() bool {
return false return false
} }
func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadCloser, error) { func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadCloser, error) {
if interactive { if interactive {
term, err := pty.Start(cmd) term, err := pty.Start(cmd)
@ -76,5 +72,3 @@ func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadClose
} }
return stdin, stdout, nil return stdin, stdout, nil
} }

View File

@ -3,6 +3,7 @@ package docker
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/dotcloud/docker/image"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -10,7 +11,6 @@ import (
"strings" "strings"
"syscall" "syscall"
"time" "time"
"github.com/dotcloud/docker/image"
) )
type Filesystem struct { type Filesystem struct {

View File

@ -1,12 +1,12 @@
package future package future
import ( import (
"crypto/sha256"
"io"
"fmt"
"time"
"bytes" "bytes"
"crypto/sha256"
"fmt"
"io"
"math/rand" "math/rand"
"time"
) )
func Seed() { func Seed() {
@ -30,18 +30,18 @@ func HumanDuration(d time.Duration) string {
return "About a minute" return "About a minute"
} else if minutes < 60 { } else if minutes < 60 {
return fmt.Sprintf("%d minutes", minutes) return fmt.Sprintf("%d minutes", minutes)
} else if hours := int(d.Hours()); hours == 1{ } else if hours := int(d.Hours()); hours == 1 {
return "About an hour" return "About an hour"
} else if hours < 48 { } else if hours < 48 {
return fmt.Sprintf("%d hours", hours) return fmt.Sprintf("%d hours", hours)
} else if hours < 24 * 7 * 2 { } else if hours < 24*7*2 {
return fmt.Sprintf("%d days", hours / 24) return fmt.Sprintf("%d days", hours/24)
} else if hours < 24 * 30 * 3 { } else if hours < 24*30*3 {
return fmt.Sprintf("%d weeks", hours / 24 / 7) return fmt.Sprintf("%d weeks", hours/24/7)
} else if hours < 24 * 365 * 2 { } else if hours < 24*365*2 {
return fmt.Sprintf("%d months", hours / 24 / 30) return fmt.Sprintf("%d months", hours/24/30)
} }
return fmt.Sprintf("%d years", d.Hours() / 24 / 365) return fmt.Sprintf("%d years", d.Hours()/24/365)
} }
func randomBytes() io.Reader { func randomBytes() io.Reader {
@ -83,4 +83,3 @@ func Pv(src io.Reader, info io.Writer) io.Reader {
}() }()
return r return r
} }

View File

@ -1,10 +1,10 @@
package image package image
import ( import (
"errors"
"io" "io"
"io/ioutil" "io/ioutil"
"os/exec" "os/exec"
"errors"
) )
type Compression uint32 type Compression uint32
@ -17,14 +17,16 @@ const (
func (compression *Compression) Flag() string { func (compression *Compression) Flag() string {
switch *compression { switch *compression {
case Bzip2: return "j" case Bzip2:
case Gzip: return "z" return "j"
case Gzip:
return "z"
} }
return "" return ""
} }
func Tar(path string, compression Compression) (io.Reader, error) { func Tar(path string, compression Compression) (io.Reader, error) {
cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c" + compression.Flag(), ".") cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".")
return CmdStream(cmd) return CmdStream(cmd)
} }

View File

@ -1,10 +1,10 @@
package image package image
import ( import (
"testing" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"io/ioutil" "testing"
) )
func TestCmdStreamBad(t *testing.T) { func TestCmdStreamBad(t *testing.T) {

View File

@ -1,27 +1,25 @@
package image package image
import ( import (
"encoding/json"
"errors"
"github.com/dotcloud/docker/future"
"io" "io"
"io/ioutil" "io/ioutil"
"encoding/json" "os"
"time"
"path" "path"
"path/filepath" "path/filepath"
"errors"
"sort" "sort"
"os"
"github.com/dotcloud/docker/future"
"strings" "strings"
"time"
) )
type Store struct { type Store struct {
*Index *Index
Root string Root string
Layers *LayerStore Layers *LayerStore
} }
func New(root string) (*Store, error) { func New(root string) (*Store, error) {
abspath, err := filepath.Abs(root) abspath, err := filepath.Abs(root)
if err != nil { if err != nil {
@ -73,7 +71,6 @@ func (store *Store) Create(name string, source string, layers ...string) (*Image
return image, nil return image, nil
} }
// Index // Index
type Index struct { type Index struct {
@ -216,7 +213,7 @@ func (index *Index) Names() []string {
if err := index.load(); err != nil { if err := index.load(); err != nil {
return []string{} return []string{}
} }
var names[]string var names []string
for name := range index.ByName { for name := range index.ByName {
names = append(names, name) names = append(names, name)
} }
@ -279,7 +276,7 @@ func (history *History) Add(image *Image) {
func (history *History) Del(id string) { func (history *History) Del(id string) {
for idx, image := range *history { for idx, image := range *history {
if image.Id == id { if image.Id == id {
*history = append((*history)[:idx], (*history)[idx + 1:]...) *history = append((*history)[:idx], (*history)[idx+1:]...)
} }
} }
} }
@ -295,7 +292,7 @@ func (image *Image) IdParts() (string, string) {
if len(image.Id) < 8 { if len(image.Id) < 8 {
return "", image.Id return "", image.Id
} }
hash := image.Id[len(image.Id)-8:len(image.Id)] hash := image.Id[len(image.Id)-8 : len(image.Id)]
name := image.Id[:len(image.Id)-9] name := image.Id[:len(image.Id)-9]
return name, hash return name, hash
} }

View File

@ -2,12 +2,12 @@ package image
import ( import (
"errors" "errors"
"path" "github.com/dotcloud/docker/future"
"path/filepath"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/dotcloud/docker/future" "path"
"path/filepath"
) )
type LayerStore struct { type LayerStore struct {
@ -66,10 +66,9 @@ func (store *LayerStore) Init() error {
return os.Mkdir(store.Root, 0700) return os.Mkdir(store.Root, 0700)
} }
func (store *LayerStore) Mktemp() (string, error) { func (store *LayerStore) Mktemp() (string, error) {
tmpName := future.RandomId() tmpName := future.RandomId()
tmpPath := path.Join(store.Root, "tmp-" + tmpName) tmpPath := path.Join(store.Root, "tmp-"+tmpName)
if err := os.Mkdir(tmpPath, 0700); err != nil { if err := os.Mkdir(tmpPath, 0700); err != nil {
return "", err return "", err
} }
@ -80,7 +79,6 @@ func (store *LayerStore) layerPath(id string) string {
return path.Join(store.Root, id) return path.Join(store.Root, id)
} }
func (store *LayerStore) AddLayer(archive io.Reader) (string, error) { func (store *LayerStore) AddLayer(archive io.Reader) (string, error) {
errors := make(chan error) errors := make(chan error)
// Untar // Untar
@ -109,9 +107,10 @@ func (store *LayerStore) AddLayer(archive io.Reader) (string, error) {
return "", err return "", err
} }
// Wait for goroutines // Wait for goroutines
for i:=0; i<2; i+=1 { for i := 0; i < 2; i += 1 {
select { select {
case err := <-errors: { case err := <-errors:
{
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -1,12 +1,12 @@
package image package image
import ( import (
"bytes"
"github.com/dotcloud/docker/fake"
"github.com/dotcloud/docker/future"
"io/ioutil"
"os" "os"
"testing" "testing"
"io/ioutil"
"bytes"
"github.com/dotcloud/docker/future"
"github.com/dotcloud/docker/fake"
) )
func TestAddLayer(t *testing.T) { func TestAddLayer(t *testing.T) {
@ -45,4 +45,3 @@ func TestComputeId(t *testing.T) {
t.Fatalf("Identical checksums for difference content (%s == %s)", id1, id2) t.Fatalf("Identical checksums for difference content (%s == %s)", id1, id2)
} }
} }

View File

@ -2,7 +2,6 @@ package docker
import "syscall" import "syscall"
func mount(source string, target string, fstype string, flags uintptr, data string) (err error) { func mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
return syscall.Mount(source, target, fstype, flags, data) return syscall.Mount(source, target, fstype, flags, data)
} }