2017-02-25 04:18:35 +08:00
|
|
|
package buildah
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
is "github.com/containers/image/storage"
|
2017-05-17 23:53:28 +08:00
|
|
|
"github.com/containers/storage"
|
2017-02-25 04:18:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func importBuilder(store storage.Store, options ImportOptions) (*Builder, error) {
|
|
|
|
manifest := []byte{}
|
|
|
|
config := []byte{}
|
|
|
|
image := ""
|
2017-03-16 05:19:29 +08:00
|
|
|
imageName := ""
|
2017-02-25 04:18:35 +08:00
|
|
|
|
|
|
|
if options.Container == "" {
|
|
|
|
return nil, fmt.Errorf("container name must be specified")
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:53:28 +08:00
|
|
|
c, err := store.Container(options.Container)
|
2017-02-25 04:18:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
systemContext := getSystemContext(options.SignaturePolicyPath)
|
|
|
|
|
|
|
|
if c.ImageID != "" {
|
2017-04-04 05:44:23 +08:00
|
|
|
ref, err2 := is.Transport.ParseStoreReference(store, "@"+c.ImageID)
|
|
|
|
if err2 != nil {
|
|
|
|
return nil, fmt.Errorf("no such image %q: %v", "@"+c.ImageID, err2)
|
2017-02-25 04:18:35 +08:00
|
|
|
}
|
2017-04-04 05:44:23 +08:00
|
|
|
src, err3 := ref.NewImage(systemContext)
|
|
|
|
if err3 != nil {
|
|
|
|
return nil, fmt.Errorf("error instantiating image: %v", err3)
|
2017-02-25 04:18:35 +08:00
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
config, err = src.ConfigBlob()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading image configuration: %v", err)
|
|
|
|
}
|
|
|
|
manifest, _, err = src.Manifest()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading image manifest: %v", err)
|
|
|
|
}
|
2017-03-16 05:19:29 +08:00
|
|
|
image = c.ImageID
|
2017-05-17 23:53:28 +08:00
|
|
|
if img, err4 := store.Image(image); err4 == nil {
|
2017-03-16 05:19:29 +08:00
|
|
|
if len(img.Names) > 0 {
|
|
|
|
imageName = img.Names[0]
|
|
|
|
}
|
|
|
|
}
|
2017-02-25 04:18:35 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 05:44:23 +08:00
|
|
|
name := options.Container
|
2017-02-25 04:18:35 +08:00
|
|
|
|
|
|
|
builder := &Builder{
|
Maintain multiple working container configs
Maintain the container configuration in multiple formats in the Buildah
object, initializing one based on the other, depending on which format
the source image used for its configuration.
Replace directly manipulated fields in the Buildah object (Annotations,
CreatedBy, OS, Architecture, Maintainer, User, Workdir, Env, Cmd,
Entrypoint, Expose, Labels, and Volumes) with accessor functions which
update both configurations and which read from whichever one we consider
to be authoritative. Drop Args because we weren't using them.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Closes: #102
Approved by: rhatdan
2017-05-16 23:08:52 +08:00
|
|
|
store: store,
|
|
|
|
Type: containerType,
|
|
|
|
FromImage: imageName,
|
|
|
|
FromImageID: image,
|
|
|
|
Config: config,
|
|
|
|
Manifest: manifest,
|
|
|
|
Container: name,
|
|
|
|
ContainerID: c.ID,
|
|
|
|
Mounts: []string{},
|
|
|
|
ImageAnnotations: map[string]string{},
|
|
|
|
ImageCreatedBy: "",
|
2017-02-25 04:18:35 +08:00
|
|
|
}
|
|
|
|
|
Maintain multiple working container configs
Maintain the container configuration in multiple formats in the Buildah
object, initializing one based on the other, depending on which format
the source image used for its configuration.
Replace directly manipulated fields in the Buildah object (Annotations,
CreatedBy, OS, Architecture, Maintainer, User, Workdir, Env, Cmd,
Entrypoint, Expose, Labels, and Volumes) with accessor functions which
update both configurations and which read from whichever one we consider
to be authoritative. Drop Args because we weren't using them.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Closes: #102
Approved by: rhatdan
2017-05-16 23:08:52 +08:00
|
|
|
builder.initConfig()
|
2017-02-25 04:18:35 +08:00
|
|
|
err = builder.Save()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error saving builder state: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder, nil
|
|
|
|
}
|