зеркало из https://github.com/microsoft/docker.git
Merge branch store_register_refactor
This commit is contained in:
Коммит
68e173ad50
|
@ -34,7 +34,7 @@ Vagrant::Config.run do |config|
|
|||
# Share an additional folder to the guest VM. The first argument is
|
||||
# an identifier, the second is the path on the guest to mount the
|
||||
# folder, and the third is the path on the host to the actual folder.
|
||||
# config.vm.share_folder "v-data", "/vagrant_data", "../data"
|
||||
config.vm.share_folder "v-data", "~/docker", "~/docker"
|
||||
|
||||
# Enable provisioning with Puppet stand alone. Puppet manifests
|
||||
# are contained in a directory path relative to this Vagrantfile.
|
||||
|
|
35
fs/store.go
35
fs/store.go
|
@ -172,42 +172,35 @@ func (store *Store) Create(layerData Archive, parent *Image, pth, comment string
|
|||
if parent != nil {
|
||||
img.Parent = parent.Id
|
||||
}
|
||||
// FIXME: we shouldn't have to pass os.Stderr to AddLayer()...
|
||||
// FIXME: Archive should contain compression info. For now we only support uncompressed.
|
||||
err := store.Register(layerData, img, pth)
|
||||
return img, err
|
||||
}
|
||||
|
||||
func (store *Store) Register(layerData Archive, img *Image, pth string) error {
|
||||
img.store = store
|
||||
_, err := store.layers.AddLayer(img.Id, layerData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not add layer: %s", err)
|
||||
return fmt.Errorf("Could not add layer: %s", err)
|
||||
}
|
||||
path := &Path{
|
||||
pathObj := &Path{
|
||||
Path: path.Clean(pth),
|
||||
Image: img.Id,
|
||||
}
|
||||
trans, err := store.orm.Begin()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not begin transaction: %s", err)
|
||||
return fmt.Errorf("Could not begin transaction: %s", err)
|
||||
}
|
||||
if err := trans.Insert(img); err != nil {
|
||||
return nil, fmt.Errorf("Could not insert image info: %s", err)
|
||||
return fmt.Errorf("Could not insert image info: %s", err)
|
||||
}
|
||||
if err := trans.Insert(path); err != nil {
|
||||
return nil, fmt.Errorf("Could not insert path info: %s", err)
|
||||
if err := trans.Insert(pathObj); err != nil {
|
||||
return fmt.Errorf("Could not insert path info: %s", err)
|
||||
}
|
||||
if err := trans.Commit(); err != nil {
|
||||
return nil, fmt.Errorf("Could not commit transaction: %s", err)
|
||||
return fmt.Errorf("Could not commit transaction: %s", err)
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func (store *Store) Register(image *Image, pth string) error {
|
||||
image.store = store
|
||||
// FIXME: import layer
|
||||
trans, err := store.orm.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
trans.Insert(image)
|
||||
trans.Insert(&Path{Path: pth, Image: image.Id})
|
||||
return trans.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *Store) Layers() []string {
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/fake"
|
||||
"github.com/dotcloud/docker/future"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
|
@ -52,6 +54,40 @@ func TestCreate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
store, err := TempStore("testregister")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(store)
|
||||
archive, err := fake.FakeTar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
image := &Image{
|
||||
Id: future.RandomId(),
|
||||
Comment: "testing",
|
||||
Created: time.Now().Unix(),
|
||||
store: store,
|
||||
}
|
||||
err = store.Register(archive, image, "foo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if images, err := store.Images(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if l := len(images); l != 1 {
|
||||
t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l)
|
||||
}
|
||||
if images, err := store.List("foo"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if l := len(images); l != 1 {
|
||||
t.Fatalf("Path foo has wrong number of images (should be %d, not %d)", 1, l)
|
||||
} else if images[0].Id != image.Id {
|
||||
t.Fatalf("Imported image should be listed at path foo (%s != %s)", images[0], image)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTag(t *testing.T) {
|
||||
store, err := TempStore("testtag")
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ class docker {
|
|||
Package { ensure => "installed" }
|
||||
|
||||
package { ["lxc", "debootstrap", "wget", "bsdtar", "git",
|
||||
"pkg-config", "libsqlite3-dev",
|
||||
"linux-image-3.5.0-25-generic",
|
||||
"linux-image-extra-3.5.0-25-generic",
|
||||
"virtualbox-guest-utils",
|
||||
|
@ -42,18 +43,19 @@ class docker {
|
|||
require => [Exec["fetch-docker"], Exec["debootstrap"]]
|
||||
}
|
||||
|
||||
file { "/home/vagrant/.profile":
|
||||
mode => 644,
|
||||
owner => "vagrant",
|
||||
group => "vagrant",
|
||||
content => template("docker/profile"),
|
||||
}
|
||||
|
||||
exec { "copy-docker-bin" :
|
||||
require => Exec["fetch-docker"],
|
||||
command => "/bin/cp /home/vagrant/docker-master/docker /usr/local/bin",
|
||||
creates => "/usr/local/bin/docker"
|
||||
}
|
||||
|
||||
exec { "copy-dockerd-bin" :
|
||||
require => Exec["fetch-docker"],
|
||||
command => "/bin/cp /home/vagrant/docker-master/dockerd /usr/local/bin",
|
||||
creates => "/usr/local/bin/dockerd"
|
||||
}
|
||||
|
||||
exec { "vbox-add" :
|
||||
require => Package["linux-headers-3.5.0-25-generic"],
|
||||
command => "/etc/init.d/vboxadd setup",
|
||||
|
|
|
@ -8,5 +8,5 @@ respawn
|
|||
|
||||
script
|
||||
test -f /etc/default/locale && . /etc/default/locale || true
|
||||
LANG=$LANG LC_ALL=$LANG /usr/local/bin/dockerd
|
||||
LANG=$LANG LC_ALL=$LANG /usr/local/bin/docker -d
|
||||
end script
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
# ~/.profile: executed by the command interpreter for login shells.
|
||||
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
|
||||
# exists.
|
||||
# see /usr/share/doc/bash/examples/startup-files for examples.
|
||||
# the files are located in the bash-doc package.
|
||||
|
||||
# the default umask is set in /etc/profile; for setting the umask
|
||||
# for ssh logins, install and configure the libpam-umask package.
|
||||
#umask 022
|
||||
|
||||
# if running bash
|
||||
if [ -n "$BASH_VERSION" ]; then
|
||||
# include .bashrc if it exists
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
fi
|
||||
|
||||
# set PATH so it includes user's private bin if it exists
|
||||
if [ -d "$HOME/bin" ] ; then
|
||||
PATH="$HOME/bin:$PATH"
|
||||
fi
|
||||
|
||||
# set ~/docker as the go path
|
||||
export GOPATH=~/docker
|
||||
# add go to the PATH
|
||||
export PATH=$PATH:/usr/local/go/bin
|
Загрузка…
Ссылка в новой задаче