mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move runtime.Commit to builder.Commit
This commit is contained in:
parent
6f2125386a
commit
f7c5e92a2e
3 changed files with 28 additions and 29 deletions
23
builder.go
23
builder.go
|
@ -13,11 +13,13 @@ import (
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
repositories *TagStore
|
repositories *TagStore
|
||||||
|
graph *Graph
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuilder(runtime *Runtime) *Builder {
|
func NewBuilder(runtime *Runtime) *Builder {
|
||||||
return &Builder{
|
return &Builder{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
|
graph: runtime.graph,
|
||||||
repositories: runtime.repositories,
|
repositories: runtime.repositories,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +85,27 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
||||||
return container, nil
|
return container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit creates a new filesystem image from the current state of a container.
|
||||||
|
// The image can optionally be tagged into a repository
|
||||||
func (builder *Builder) Commit(container *Container, repository, tag, comment, author string) (*Image, error) {
|
func (builder *Builder) Commit(container *Container, repository, tag, comment, author string) (*Image, error) {
|
||||||
return builder.runtime.Commit(container.Id, repository, tag, comment, author)
|
// 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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Create a new image from the container's base layers + a new layer from container changes
|
||||||
|
img, err := builder.graph.Create(rwTar, container, comment, author)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Register the image if needed
|
||||||
|
if repository != "" {
|
||||||
|
if err := builder.repositories.Set(repository, tag, img.Id, true); err != nil {
|
||||||
|
return img, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (builder *Builder) clearTmp(containers, images map[string]struct{}) {
|
func (builder *Builder) clearTmp(containers, images map[string]struct{}) {
|
||||||
|
|
|
@ -852,7 +852,12 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := srv.runtime.Commit(containerName, repository, tag, *flComment, *flAuthor, config)
|
container := srv.runtime.Get(containerName)
|
||||||
|
if container == nil {
|
||||||
|
return fmt.Errorf("No such container: %s", containerName)
|
||||||
|
}
|
||||||
|
|
||||||
|
img, err := NewBuilder(srv.runtime).Commit(container, repository, tag, *flComment, *flAuthor, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
27
runtime.go
27
runtime.go
|
@ -309,33 +309,6 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit creates a new filesystem image from the current state of a container.
|
|
||||||
// The image can optionally be tagged into a repository
|
|
||||||
func (runtime *Runtime) Commit(id, repository, tag, comment, author string, config *Config) (*Image, error) {
|
|
||||||
container := runtime.Get(id)
|
|
||||||
if container == nil {
|
|
||||||
return nil, fmt.Errorf("No such container: %s", id)
|
|
||||||
}
|
|
||||||
// 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 {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Create a new image from the container's base layers + a new layer from container changes
|
|
||||||
img, err := runtime.graph.Create(rwTar, container, comment, author, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Register the image if needed
|
|
||||||
if repository != "" {
|
|
||||||
if err := runtime.repositories.Set(repository, tag, img.Id, true); err != nil {
|
|
||||||
return img, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return img, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (runtime *Runtime) restore() error {
|
func (runtime *Runtime) restore() error {
|
||||||
dir, err := ioutil.ReadDir(runtime.repository)
|
dir, err := ioutil.ReadDir(runtime.repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue