1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Rebase master (autorun)

This commit is contained in:
Guillaume J. Charmes 2013-05-01 14:36:45 -07:00
parent f911ccc27b
commit 9959e2cd63

View file

@ -22,12 +22,57 @@ func NewBuilder(runtime *Runtime) *Builder {
} }
} }
func (builder *Builder) mergeConfig(userConf, imageConf *Config) {
if userConf.Hostname != "" {
userConf.Hostname = imageConf.Hostname
}
if userConf.User != "" {
userConf.User = imageConf.User
}
if userConf.Memory == 0 {
userConf.Memory = imageConf.Memory
}
if userConf.MemorySwap == 0 {
userConf.MemorySwap = imageConf.MemorySwap
}
if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 {
userConf.PortSpecs = imageConf.PortSpecs
}
if !userConf.Tty {
userConf.Tty = userConf.Tty
}
if !userConf.OpenStdin {
userConf.OpenStdin = imageConf.OpenStdin
}
if !userConf.StdinOnce {
userConf.StdinOnce = imageConf.StdinOnce
}
if userConf.Env == nil || len(userConf.Env) == 0 {
userConf.Env = imageConf.Env
}
if userConf.Cmd == nil || len(userConf.Cmd) == 0 {
userConf.Cmd = imageConf.Cmd
}
if userConf.Dns == nil || len(userConf.Dns) == 0 {
userConf.Dns = imageConf.Dns
}
}
func (builder *Builder) Create(config *Config) (*Container, error) { func (builder *Builder) Create(config *Config) (*Container, error) {
// Lookup image // Lookup image
img, err := builder.repositories.LookupImage(config.Image) img, err := builder.repositories.LookupImage(config.Image)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if img.Config != nil {
builder.mergeConfig(config, img.Config)
}
if config.Cmd == nil {
return nil, fmt.Errorf("No command specified")
}
// Generate id // Generate id
id := GenerateId() id := GenerateId()
// Generate default hostname // Generate default hostname
@ -83,15 +128,17 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
return container, nil return container, nil
} }
func (builder *Builder) runCommit(image *Image, cmd string) (*Image, error) { // Commit creates a new filesystem image from the current state of a container.
c, err := builder.run(image, cmd) // The image can optionally be tagged into a repository
func (builder *Builder) Commit(container *Container, repository, tag, comment, author string, config *Config) (*Image, error) {
// FIXME: freeze the container before copying it to avoid data corruption?
// FIXME: this shouldn't be in commands.
rwTar, err := container.ExportRw()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if result := c.Wait(); result != 0 { // Create a new image from the container's base layers + a new layer from container changes
return nil, fmt.Errorf("!!! '%s' return non-zero exit code '%d'. Aborting.", cmd, result) img, err := builder.graph.Create(rwTar, container, comment, author, config)
}
img, err := builder.runtime.Commit(c.Id, "", "", "", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -173,7 +220,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) error {
} }
// Commit the container // Commit the container
base, err = builder.Commit(c, "", "", "", "") base, err = builder.Commit(c, "", "", "", "", nil)
if err != nil { if err != nil {
return err return err
} }
@ -219,7 +266,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) error {
return err return err
} }
base, err = builder.Commit(c, "", "", "", "") base, err = builder.Commit(c, "", "", "", "", nil)
if err != nil { if err != nil {
return err return err
} }