2017-02-11 00:48:15 +08:00
|
|
|
package buildah
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2017-05-17 05:26:02 +08:00
|
|
|
"fmt"
|
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
|
|
|
"path/filepath"
|
2017-02-11 00:48:15 +08:00
|
|
|
"runtime"
|
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
|
|
|
"strings"
|
2017-05-17 05:26:02 +08:00
|
|
|
"time"
|
2017-02-11 00:48:15 +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
|
|
|
digest "github.com/opencontainers/go-digest"
|
2017-02-11 00:48:15 +08:00
|
|
|
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
2017-06-03 00:17:27 +08:00
|
|
|
"github.com/pkg/errors"
|
2017-04-12 04:25:13 +08:00
|
|
|
"github.com/projectatomic/buildah/docker"
|
2017-02-11 00:48:15 +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
|
|
|
// makeOCIv1Image builds the best OCIv1 image structure we can from the
|
|
|
|
// contents of the docker image structure.
|
2017-05-17 05:07:31 +08:00
|
|
|
func makeOCIv1Image(dimage *docker.V2Image) (ociv1.Image, error) {
|
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
|
|
|
config := dimage.Config
|
|
|
|
if config == nil {
|
|
|
|
config = &dimage.ContainerConfig
|
|
|
|
}
|
2017-02-11 00:48:15 +08:00
|
|
|
image := ociv1.Image{
|
2017-02-14 00:44:47 +08:00
|
|
|
Created: dimage.Created.UTC(),
|
2017-02-11 00:48:15 +08:00
|
|
|
Author: dimage.Author,
|
|
|
|
Architecture: dimage.Architecture,
|
|
|
|
OS: dimage.OS,
|
|
|
|
Config: ociv1.ImageConfig{
|
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
|
|
|
User: config.User,
|
2017-02-11 00:48:15 +08:00
|
|
|
ExposedPorts: map[string]struct{}{},
|
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
|
|
|
Env: config.Env,
|
|
|
|
Entrypoint: config.Entrypoint,
|
|
|
|
Cmd: config.Cmd,
|
|
|
|
Volumes: config.Volumes,
|
|
|
|
WorkingDir: config.WorkingDir,
|
|
|
|
Labels: config.Labels,
|
2017-02-11 00:48:15 +08:00
|
|
|
},
|
|
|
|
RootFS: ociv1.RootFS{
|
|
|
|
Type: "",
|
|
|
|
DiffIDs: []string{},
|
|
|
|
},
|
|
|
|
History: []ociv1.History{},
|
|
|
|
}
|
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
|
|
|
for port, what := range config.ExposedPorts {
|
2017-02-11 00:48:15 +08:00
|
|
|
image.Config.ExposedPorts[string(port)] = what
|
|
|
|
}
|
2017-05-17 05:07:31 +08:00
|
|
|
RootFS := docker.V2S2RootFS{}
|
2017-02-11 00:48:15 +08:00
|
|
|
if dimage.RootFS != nil {
|
|
|
|
RootFS = *dimage.RootFS
|
|
|
|
}
|
|
|
|
if RootFS.Type == docker.TypeLayers {
|
|
|
|
image.RootFS.Type = docker.TypeLayers
|
|
|
|
for _, id := range RootFS.DiffIDs {
|
|
|
|
image.RootFS.DiffIDs = append(image.RootFS.DiffIDs, id.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, history := range dimage.History {
|
|
|
|
ohistory := ociv1.History{
|
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
|
|
|
Created: history.Created.UTC(),
|
2017-02-11 00:48:15 +08:00
|
|
|
CreatedBy: history.CreatedBy,
|
|
|
|
Author: history.Author,
|
|
|
|
Comment: history.Comment,
|
|
|
|
EmptyLayer: history.EmptyLayer,
|
|
|
|
}
|
|
|
|
image.History = append(image.History, ohistory)
|
|
|
|
}
|
|
|
|
return image, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// makeDockerV2S2Image builds the best docker image structure we can from the
|
|
|
|
// contents of the OCI image structure.
|
2017-05-17 05:07:31 +08:00
|
|
|
func makeDockerV2S2Image(oimage *ociv1.Image) (docker.V2Image, error) {
|
|
|
|
image := docker.V2Image{
|
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
|
|
|
V1Image: docker.V1Image{Created: oimage.Created.UTC(),
|
|
|
|
Author: oimage.Author,
|
|
|
|
Architecture: oimage.Architecture,
|
|
|
|
OS: oimage.OS,
|
|
|
|
ContainerConfig: docker.Config{
|
|
|
|
User: oimage.Config.User,
|
|
|
|
ExposedPorts: docker.PortSet{},
|
|
|
|
Env: oimage.Config.Env,
|
|
|
|
Entrypoint: oimage.Config.Entrypoint,
|
|
|
|
Cmd: oimage.Config.Cmd,
|
|
|
|
Volumes: oimage.Config.Volumes,
|
|
|
|
WorkingDir: oimage.Config.WorkingDir,
|
|
|
|
Labels: oimage.Config.Labels,
|
|
|
|
},
|
|
|
|
},
|
2017-05-17 05:07:31 +08:00
|
|
|
RootFS: &docker.V2S2RootFS{
|
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
|
|
|
Type: "",
|
|
|
|
DiffIDs: []digest.Digest{},
|
|
|
|
},
|
2017-05-17 05:07:31 +08:00
|
|
|
History: []docker.V2S2History{},
|
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
|
|
|
}
|
|
|
|
for port, what := range oimage.Config.ExposedPorts {
|
|
|
|
image.ContainerConfig.ExposedPorts[docker.Port(port)] = what
|
|
|
|
}
|
|
|
|
if oimage.RootFS.Type == docker.TypeLayers {
|
|
|
|
image.RootFS.Type = docker.TypeLayers
|
|
|
|
for _, id := range oimage.RootFS.DiffIDs {
|
|
|
|
d, err := digest.Parse(id)
|
|
|
|
if err != nil {
|
2017-05-17 05:07:31 +08:00
|
|
|
return docker.V2Image{}, err
|
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
|
|
|
}
|
|
|
|
image.RootFS.DiffIDs = append(image.RootFS.DiffIDs, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, history := range oimage.History {
|
2017-05-17 05:07:31 +08:00
|
|
|
dhistory := docker.V2S2History{
|
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
|
|
|
Created: history.Created.UTC(),
|
|
|
|
CreatedBy: history.CreatedBy,
|
|
|
|
Author: history.Author,
|
|
|
|
Comment: history.Comment,
|
|
|
|
EmptyLayer: history.EmptyLayer,
|
|
|
|
}
|
|
|
|
image.History = append(image.History, dhistory)
|
|
|
|
}
|
|
|
|
image.Config = &image.ContainerConfig
|
|
|
|
return image, nil
|
|
|
|
}
|
|
|
|
|
2017-05-17 05:26:02 +08:00
|
|
|
// makeDockerV2S1Image builds the best docker image structure we can from the
|
|
|
|
// contents of the V2S1 image structure.
|
|
|
|
func makeDockerV2S1Image(manifest docker.V2S1Manifest) (docker.V2Image, error) {
|
|
|
|
// Treat the most recent (first) item in the history as a description of the image.
|
|
|
|
if len(manifest.History) == 0 {
|
2017-06-03 00:17:27 +08:00
|
|
|
return docker.V2Image{}, errors.Errorf("error parsing image configuration from manifest")
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
|
|
|
dimage := docker.V2Image{}
|
|
|
|
err := json.Unmarshal([]byte(manifest.History[0].V1Compatibility), &dimage)
|
|
|
|
if err != nil {
|
|
|
|
return docker.V2Image{}, err
|
|
|
|
}
|
|
|
|
if dimage.DockerVersion == "" {
|
2017-06-03 00:17:27 +08:00
|
|
|
return docker.V2Image{}, errors.Errorf("error parsing image configuration from history")
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
|
|
|
// The DiffID list is intended to contain the sums of _uncompressed_ blobs, and these are most
|
|
|
|
// likely compressed, so leave the list empty to avoid potential confusion later on. We can
|
|
|
|
// construct a list with the correct values when we prep layers for pushing, so we don't lose.
|
|
|
|
// information by leaving this part undone.
|
|
|
|
rootFS := &docker.V2S2RootFS{
|
|
|
|
Type: docker.TypeLayers,
|
|
|
|
DiffIDs: []digest.Digest{},
|
|
|
|
}
|
|
|
|
// Build a filesystem history.
|
|
|
|
history := []docker.V2S2History{}
|
|
|
|
for i := range manifest.History {
|
|
|
|
h := docker.V2S2History{
|
|
|
|
Created: time.Now().UTC(),
|
|
|
|
Author: "",
|
|
|
|
CreatedBy: "",
|
|
|
|
Comment: "",
|
|
|
|
EmptyLayer: false,
|
|
|
|
}
|
|
|
|
dcompat := docker.V1Compatibility{}
|
|
|
|
if err2 := json.Unmarshal([]byte(manifest.History[i].V1Compatibility), &dcompat); err2 == nil {
|
|
|
|
h.Created = dcompat.Created.UTC()
|
|
|
|
h.Author = dcompat.Author
|
|
|
|
h.Comment = dcompat.Comment
|
|
|
|
if len(dcompat.ContainerConfig.Cmd) > 0 {
|
|
|
|
h.CreatedBy = fmt.Sprintf("%v", dcompat.ContainerConfig.Cmd)
|
|
|
|
}
|
|
|
|
h.EmptyLayer = dcompat.ThrowAway
|
|
|
|
}
|
|
|
|
// Prepend this layer to the list, because a v2s1 format manifest's list is in reverse order
|
|
|
|
// compared to v2s2, which lists earlier layers before later ones.
|
|
|
|
history = append([]docker.V2S2History{h}, history...)
|
|
|
|
}
|
|
|
|
dimage.RootFS = rootFS
|
|
|
|
dimage.History = history
|
|
|
|
return dimage, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (b *Builder) initConfig() {
|
2017-02-11 00:48:15 +08:00
|
|
|
image := ociv1.Image{}
|
2017-05-17 05:07:31 +08:00
|
|
|
dimage := docker.V2Image{}
|
2017-02-11 00:48:15 +08:00
|
|
|
if len(b.Config) > 0 {
|
|
|
|
// Try to parse the image configuration. If we fail start over from scratch.
|
|
|
|
if err := json.Unmarshal(b.Config, &dimage); err == nil && dimage.DockerVersion != "" {
|
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
|
|
|
if image, err = makeOCIv1Image(&dimage); err != nil {
|
2017-02-11 00:48:15 +08:00
|
|
|
image = ociv1.Image{}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := json.Unmarshal(b.Config, &image); err != nil {
|
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
|
|
|
if dimage, err = makeDockerV2S2Image(&image); err != nil {
|
2017-05-17 05:07:31 +08:00
|
|
|
dimage = docker.V2Image{}
|
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
|
|
|
}
|
2017-02-11 00:48:15 +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
|
|
|
b.OCIv1 = image
|
|
|
|
b.Docker = dimage
|
2017-05-17 05:26:02 +08:00
|
|
|
} else {
|
|
|
|
// Try to dig out the image configuration from the manifest.
|
|
|
|
manifest := docker.V2S1Manifest{}
|
|
|
|
if err := json.Unmarshal(b.Manifest, &manifest); err == nil && manifest.SchemaVersion == 1 {
|
|
|
|
if dimage, err = makeDockerV2S1Image(manifest); err == nil {
|
|
|
|
if image, err = makeOCIv1Image(&dimage); err != nil {
|
|
|
|
image = ociv1.Image{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.OCIv1 = image
|
|
|
|
b.Docker = dimage
|
2017-02-11 00:48:15 +08:00
|
|
|
}
|
2017-05-23 02:23:50 +08:00
|
|
|
if len(b.Manifest) > 0 {
|
|
|
|
// Attempt to recover format-specific data from the manifest.
|
|
|
|
v1Manifest := ociv1.Manifest{}
|
|
|
|
if json.Unmarshal(b.Manifest, &v1Manifest) == nil {
|
|
|
|
b.ImageAnnotations = v1Manifest.Annotations
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
b.fixupConfig()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Builder) fixupConfig() {
|
|
|
|
if b.Docker.Config != nil {
|
|
|
|
// Prefer image-level settings over those from the container it was built from.
|
|
|
|
b.Docker.ContainerConfig = *b.Docker.Config
|
2017-02-11 00:48:15 +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
|
|
|
b.Docker.Config = &b.Docker.ContainerConfig
|
2017-05-17 05:26:02 +08:00
|
|
|
b.Docker.DockerVersion = ""
|
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
|
|
|
if b.FromImageID != "" {
|
|
|
|
if d, err := digest.Parse(b.FromImageID); err == nil {
|
|
|
|
b.Docker.Parent = docker.ID(d)
|
|
|
|
} else {
|
|
|
|
b.Docker.Parent = docker.ID(digest.NewDigestFromHex(digest.Canonical.String(), b.FromImageID))
|
2017-02-14 00:44:47 +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
|
|
|
if b.FromImage != "" {
|
|
|
|
b.Docker.Config.Image = b.FromImage
|
2017-02-11 00:48:15 +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
|
|
|
if b.OS() == "" {
|
|
|
|
b.SetOS(runtime.GOOS)
|
2017-02-11 00:48:15 +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
|
|
|
if b.Architecture() == "" {
|
|
|
|
b.SetArchitecture(runtime.GOARCH)
|
2017-02-11 00:48:15 +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
|
|
|
if b.WorkDir() == "" {
|
|
|
|
b.SetWorkDir(string(filepath.Separator))
|
2017-02-11 00:48:15 +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
|
|
|
}
|
|
|
|
|
|
|
|
// Annotations returns a set of key-value pairs from the image's manifest.
|
|
|
|
func (b *Builder) Annotations() map[string]string {
|
|
|
|
return copyStringStringMap(b.ImageAnnotations)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAnnotation adds or overwrites a key's value from the image's manifest.
|
2017-05-23 02:23:50 +08:00
|
|
|
// Note: this setting is not present in the Docker v2 image format, so it is
|
|
|
|
// discarded when writing images using Docker v2 formats.
|
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
|
|
|
func (b *Builder) SetAnnotation(key, value string) {
|
2017-05-23 02:23:50 +08:00
|
|
|
if b.ImageAnnotations == nil {
|
|
|
|
b.ImageAnnotations = map[string]string{}
|
|
|
|
}
|
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
|
|
|
b.ImageAnnotations[key] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnsetAnnotation removes a key and its value from the image's manifest, if
|
|
|
|
// it's present.
|
|
|
|
func (b *Builder) UnsetAnnotation(key string) {
|
|
|
|
delete(b.ImageAnnotations, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearAnnotations removes all keys and their values from the image's
|
|
|
|
// manifest.
|
|
|
|
func (b *Builder) ClearAnnotations() {
|
|
|
|
b.ImageAnnotations = map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreatedBy returns a description of how this image was built.
|
|
|
|
func (b *Builder) CreatedBy() string {
|
|
|
|
return b.ImageCreatedBy
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCreatedBy sets the description of how this image was built.
|
|
|
|
func (b *Builder) SetCreatedBy(how string) {
|
|
|
|
b.ImageCreatedBy = how
|
|
|
|
}
|
|
|
|
|
|
|
|
// OS returns a name of the OS on which the container, or a container built
|
|
|
|
// using an image built from this container, is intended to be run.
|
|
|
|
func (b *Builder) OS() string {
|
|
|
|
return b.OCIv1.OS
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOS sets the name of the OS on which the container, or a container built
|
|
|
|
// using an image built from this container, is intended to be run.
|
|
|
|
func (b *Builder) SetOS(os string) {
|
|
|
|
b.OCIv1.OS = os
|
|
|
|
b.Docker.OS = os
|
|
|
|
}
|
|
|
|
|
|
|
|
// Architecture returns a name of the architecture on which the container, or a
|
|
|
|
// container built using an image built from this container, is intended to be
|
|
|
|
// run.
|
|
|
|
func (b *Builder) Architecture() string {
|
|
|
|
return b.OCIv1.Architecture
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetArchitecture sets the name of the architecture on which the container, or
|
|
|
|
// a container built using an image built from this container, is intended to
|
|
|
|
// be run.
|
|
|
|
func (b *Builder) SetArchitecture(arch string) {
|
|
|
|
b.OCIv1.Architecture = arch
|
|
|
|
b.Docker.Architecture = arch
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maintainer returns contact information for the person who built the image.
|
|
|
|
func (b *Builder) Maintainer() string {
|
|
|
|
return b.OCIv1.Author
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMaintainer sets contact information for the person who built the image.
|
|
|
|
func (b *Builder) SetMaintainer(who string) {
|
|
|
|
b.OCIv1.Author = who
|
|
|
|
b.Docker.Author = who
|
|
|
|
}
|
|
|
|
|
|
|
|
// User returns information about the user as whom the container, or a
|
|
|
|
// container built using an image built from this container, should be run.
|
|
|
|
func (b *Builder) User() string {
|
|
|
|
return b.OCIv1.Config.User
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUser sets information about the user as whom the container, or a
|
|
|
|
// container built using an image built from this container, should be run.
|
|
|
|
// Acceptable forms are a user name or ID, optionally followed by a colon and a
|
|
|
|
// group name or ID.
|
|
|
|
func (b *Builder) SetUser(spec string) {
|
|
|
|
b.OCIv1.Config.User = spec
|
|
|
|
b.Docker.Config.User = spec
|
|
|
|
}
|
|
|
|
|
|
|
|
// WorkDir returns the default working directory for running commands in the
|
|
|
|
// container, or in a container built using an image built from this container.
|
|
|
|
func (b *Builder) WorkDir() string {
|
|
|
|
return b.OCIv1.Config.WorkingDir
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWorkDir sets the location of the default working directory for running
|
|
|
|
// commands in the container, or in a container built using an image built from
|
|
|
|
// this container.
|
|
|
|
func (b *Builder) SetWorkDir(there string) {
|
|
|
|
b.OCIv1.Config.WorkingDir = there
|
|
|
|
b.Docker.Config.WorkingDir = there
|
|
|
|
}
|
|
|
|
|
|
|
|
// Env returns a list of key-value pairs to be set when running commands in the
|
|
|
|
// container, or in a container built using an image built from this container.
|
|
|
|
func (b *Builder) Env() []string {
|
|
|
|
return copyStringSlice(b.OCIv1.Config.Env)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEnv adds or overwrites a value to the set of environment strings which
|
|
|
|
// should be set when running commands in the container, or in a container
|
|
|
|
// built using an image built from this container.
|
|
|
|
func (b *Builder) SetEnv(k string, v string) {
|
|
|
|
reset := func(s *[]string) {
|
|
|
|
n := []string{}
|
|
|
|
for i := range *s {
|
|
|
|
if !strings.HasPrefix((*s)[i], k+"=") {
|
|
|
|
n = append(n, (*s)[i])
|
|
|
|
}
|
2017-02-11 00:48:15 +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
|
|
|
n = append(n, k+"="+v)
|
|
|
|
*s = n
|
2017-02-11 00:48:15 +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
|
|
|
reset(&b.OCIv1.Config.Env)
|
|
|
|
reset(&b.Docker.Config.Env)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnsetEnv removes a value from the set of environment strings which should be
|
|
|
|
// set when running commands in this container, or in a container built using
|
|
|
|
// an image built from this container.
|
|
|
|
func (b *Builder) UnsetEnv(k string) {
|
|
|
|
unset := func(s *[]string) {
|
|
|
|
n := []string{}
|
|
|
|
for i := range *s {
|
|
|
|
if !strings.HasPrefix((*s)[i], k+"=") {
|
|
|
|
n = append(n, (*s)[i])
|
|
|
|
}
|
2017-02-11 00:48:15 +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
|
|
|
*s = n
|
2017-02-11 00:48:15 +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
|
|
|
unset(&b.OCIv1.Config.Env)
|
|
|
|
unset(&b.Docker.Config.Env)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearEnv removes all values from the set of environment strings which should
|
|
|
|
// be set when running commands in this container, or in a container built
|
|
|
|
// using an image built from this container.
|
|
|
|
func (b *Builder) ClearEnv() {
|
|
|
|
b.OCIv1.Config.Env = []string{}
|
|
|
|
b.Docker.Config.Env = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cmd returns the default command, or command parameters if an Entrypoint is
|
|
|
|
// set, to use when running a container built from an image built from this
|
|
|
|
// container.
|
|
|
|
func (b *Builder) Cmd() []string {
|
|
|
|
return copyStringSlice(b.OCIv1.Config.Cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCmd sets the default command, or command parameters if an Entrypoint is
|
|
|
|
// set, to use when running a container built from an image built from this
|
|
|
|
// container.
|
|
|
|
func (b *Builder) SetCmd(cmd []string) {
|
|
|
|
b.OCIv1.Config.Cmd = copyStringSlice(cmd)
|
|
|
|
b.Docker.Config.Cmd = copyStringSlice(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entrypoint returns the command to be run for containers built from images
|
|
|
|
// built from this container.
|
|
|
|
func (b *Builder) Entrypoint() []string {
|
|
|
|
return copyStringSlice(b.OCIv1.Config.Entrypoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEntrypoint sets the command to be run for in containers built from images
|
|
|
|
// built from this container.
|
|
|
|
func (b *Builder) SetEntrypoint(ep []string) {
|
|
|
|
b.OCIv1.Config.Entrypoint = copyStringSlice(ep)
|
|
|
|
b.Docker.Config.Entrypoint = copyStringSlice(ep)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Labels returns a set of key-value pairs from the image's runtime
|
|
|
|
// configuration.
|
|
|
|
func (b *Builder) Labels() map[string]string {
|
|
|
|
return copyStringStringMap(b.OCIv1.Config.Labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLabel adds or overwrites a key's value from the image's runtime
|
|
|
|
// configuration.
|
|
|
|
func (b *Builder) SetLabel(k string, v string) {
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.OCIv1.Config.Labels == nil {
|
|
|
|
b.OCIv1.Config.Labels = map[string]string{}
|
|
|
|
}
|
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
|
|
|
b.OCIv1.Config.Labels[k] = v
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.Docker.Config.Labels == nil {
|
|
|
|
b.Docker.Config.Labels = map[string]string{}
|
|
|
|
}
|
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
|
|
|
b.Docker.Config.Labels[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnsetLabel removes a key and its value from the image's runtime
|
|
|
|
// configuration, if it's present.
|
|
|
|
func (b *Builder) UnsetLabel(k string) {
|
|
|
|
delete(b.OCIv1.Config.Labels, k)
|
|
|
|
delete(b.Docker.Config.Labels, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearLabels removes all keys and their values from the image's runtime
|
|
|
|
// configuration.
|
|
|
|
func (b *Builder) ClearLabels() {
|
|
|
|
b.OCIv1.Config.Labels = map[string]string{}
|
|
|
|
b.Docker.Config.Labels = map[string]string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ports returns the set of ports which should be exposed when a container
|
|
|
|
// based on an image built from this container is run.
|
|
|
|
func (b *Builder) Ports() []string {
|
|
|
|
p := []string{}
|
|
|
|
for k := range b.OCIv1.Config.ExposedPorts {
|
|
|
|
p = append(p, k)
|
2017-02-11 00:48:15 +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
|
|
|
return p
|
2017-02-11 00:48:15 +08:00
|
|
|
}
|
2017-03-28 15:06:13 +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
|
|
|
// SetPort adds or overwrites an exported port in the set of ports which should
|
|
|
|
// be exposed when a container based on an image built from this container is
|
|
|
|
// run.
|
|
|
|
func (b *Builder) SetPort(p string) {
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.OCIv1.Config.ExposedPorts == nil {
|
|
|
|
b.OCIv1.Config.ExposedPorts = map[string]struct{}{}
|
|
|
|
}
|
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
|
|
|
b.OCIv1.Config.ExposedPorts[p] = struct{}{}
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.Docker.Config.ExposedPorts == nil {
|
|
|
|
b.Docker.Config.ExposedPorts = make(docker.PortSet)
|
|
|
|
}
|
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
|
|
|
b.Docker.Config.ExposedPorts[docker.Port(p)] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnsetPort removes an exposed port from the set of ports which should be
|
|
|
|
// exposed when a container based on an image built from this container is run.
|
|
|
|
func (b *Builder) UnsetPort(p string) {
|
|
|
|
delete(b.OCIv1.Config.ExposedPorts, p)
|
|
|
|
delete(b.Docker.Config.ExposedPorts, docker.Port(p))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearPorts empties the set of ports which should be exposed when a container
|
|
|
|
// based on an image built from this container is run.
|
|
|
|
func (b *Builder) ClearPorts() {
|
|
|
|
b.OCIv1.Config.ExposedPorts = map[string]struct{}{}
|
|
|
|
b.Docker.Config.ExposedPorts = docker.PortSet{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Volumes returns a list of filesystem locations which should be mounted from
|
|
|
|
// outside of the container when a container built from an image built from
|
|
|
|
// this container is run.
|
|
|
|
func (b *Builder) Volumes() []string {
|
|
|
|
v := []string{}
|
|
|
|
for k := range b.OCIv1.Config.Volumes {
|
|
|
|
v = append(v, k)
|
2017-03-28 15:06:13 +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
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddVolume adds a location to the image's list of locations which should be
|
|
|
|
// mounted from outside of the container when a container based on an image
|
|
|
|
// built from this container is run.
|
|
|
|
func (b *Builder) AddVolume(v string) {
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.OCIv1.Config.Volumes == nil {
|
|
|
|
b.OCIv1.Config.Volumes = map[string]struct{}{}
|
|
|
|
}
|
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
|
|
|
b.OCIv1.Config.Volumes[v] = struct{}{}
|
2017-05-23 02:23:36 +08:00
|
|
|
if b.Docker.Config.Volumes == nil {
|
|
|
|
b.Docker.Config.Volumes = map[string]struct{}{}
|
|
|
|
}
|
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
|
|
|
b.Docker.Config.Volumes[v] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveVolume removes a location from the list of locations which should be
|
|
|
|
// mounted from outside of the container when a container based on an image
|
|
|
|
// built from this container is run.
|
|
|
|
func (b *Builder) RemoveVolume(v string) {
|
|
|
|
delete(b.OCIv1.Config.Volumes, v)
|
|
|
|
delete(b.Docker.Config.Volumes, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearVolumes removes all locations from the image's list of locations which
|
|
|
|
// should be mounted from outside of the container when a container based on an
|
|
|
|
// image built from this container is run.
|
|
|
|
func (b *Builder) ClearVolumes() {
|
|
|
|
b.OCIv1.Config.Volumes = map[string]struct{}{}
|
|
|
|
b.Docker.Config.Volumes = map[string]struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hostname returns the hostname which will be set in the container and in
|
|
|
|
// containers built using images built from the container.
|
|
|
|
func (b *Builder) Hostname() string {
|
|
|
|
return b.Docker.Config.Hostname
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHostname sets the hostname which will be set in the container and in
|
|
|
|
// containers built using images built from the container.
|
|
|
|
// Note: this setting is not present in the OCIv1 image format, so it is
|
|
|
|
// discarded when writing images using OCIv1 formats.
|
|
|
|
func (b *Builder) SetHostname(name string) {
|
|
|
|
b.Docker.Config.Hostname = name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Domainname returns the domainname which will be set in the container and in
|
|
|
|
// containers built using images built from the container.
|
|
|
|
func (b *Builder) Domainname() string {
|
|
|
|
return b.Docker.Config.Domainname
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDomainname sets the domainname which will be set in the container and in
|
|
|
|
// containers built using images built from the container.
|
|
|
|
// Note: this setting is not present in the OCIv1 image format, so it is
|
|
|
|
// discarded when writing images using OCIv1 formats.
|
|
|
|
func (b *Builder) SetDomainname(name string) {
|
|
|
|
b.Docker.Config.Domainname = name
|
2017-03-28 15:06:13 +08:00
|
|
|
}
|