2017-02-11 00:48:15 +08:00
|
|
|
package buildah
|
|
|
|
|
|
|
|
import (
|
2018-06-12 06:41:11 +08:00
|
|
|
"context"
|
2017-02-11 00:48:15 +08:00
|
|
|
"encoding/json"
|
2021-05-08 01:38:44 +08:00
|
|
|
"os"
|
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
|
|
|
|
2021-11-05 01:29:08 +08:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2021-03-02 02:07:58 +08:00
|
|
|
"github.com/containers/buildah/define"
|
2018-09-18 03:20:16 +08:00
|
|
|
"github.com/containers/buildah/docker"
|
2019-10-26 05:19:30 +08:00
|
|
|
"github.com/containers/image/v5/manifest"
|
2021-09-21 00:38:09 +08:00
|
|
|
"github.com/containers/image/v5/pkg/compression"
|
2019-10-26 05:19:30 +08:00
|
|
|
"github.com/containers/image/v5/transports"
|
|
|
|
"github.com/containers/image/v5/types"
|
2018-08-24 18:51:36 +08:00
|
|
|
"github.com/containers/storage/pkg/stringid"
|
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"
|
2018-08-24 00:55:16 +08:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-02-11 00:48:15 +08:00
|
|
|
)
|
|
|
|
|
2018-06-12 07:36:23 +08:00
|
|
|
// unmarshalConvertedConfig obtains the config blob of img valid for the wantedManifestMIMEType format
|
|
|
|
// (either as it exists, or converting the image if necessary), and unmarshals it into dest.
|
|
|
|
// NOTE: The MIME type is of the _manifest_, not of the _config_ that is returned.
|
|
|
|
func unmarshalConvertedConfig(ctx context.Context, dest interface{}, img types.Image, wantedManifestMIMEType string) error {
|
|
|
|
_, actualManifestMIMEType, err := img.Manifest(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error getting manifest MIME type for %q", transports.ImageName(img.Reference()))
|
|
|
|
}
|
|
|
|
if wantedManifestMIMEType != actualManifestMIMEType {
|
2021-09-21 00:38:09 +08:00
|
|
|
layerInfos := img.LayerInfos()
|
|
|
|
for i := range layerInfos { // force the "compression" to gzip, which is supported by all of the formats we care about
|
|
|
|
layerInfos[i].CompressionOperation = types.Compress
|
|
|
|
layerInfos[i].CompressionAlgorithm = &compression.Gzip
|
|
|
|
}
|
2019-11-01 03:16:38 +08:00
|
|
|
updatedImg, err := img.UpdatedImage(ctx, types.ManifestUpdateOptions{
|
2021-09-21 00:38:09 +08:00
|
|
|
LayerInfos: layerInfos,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "resetting recorded compression for %q", transports.ImageName(img.Reference()))
|
|
|
|
}
|
|
|
|
secondUpdatedImg, err := updatedImg.UpdatedImage(ctx, types.ManifestUpdateOptions{
|
2018-06-12 07:36:23 +08:00
|
|
|
ManifestMIMEType: wantedManifestMIMEType,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2019-11-01 03:16:38 +08:00
|
|
|
return errors.Wrapf(err, "error converting image %q from %q to %q", transports.ImageName(img.Reference()), actualManifestMIMEType, wantedManifestMIMEType)
|
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
|
|
|
}
|
2021-09-21 00:38:09 +08:00
|
|
|
img = secondUpdatedImg
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
2018-06-12 07:36:23 +08:00
|
|
|
config, err := img.ConfigBlob(ctx)
|
2017-05-17 05:26:02 +08:00
|
|
|
if err != nil {
|
2018-06-12 07:36:23 +08:00
|
|
|
return errors.Wrapf(err, "error reading %s config from %q", wantedManifestMIMEType, transports.ImageName(img.Reference()))
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
2018-06-12 07:36:23 +08:00
|
|
|
if err := json.Unmarshal(config, dest); err != nil {
|
2018-10-03 22:05:46 +08:00
|
|
|
return errors.Wrapf(err, "error parsing %s configuration %q from %q", wantedManifestMIMEType, string(config), transports.ImageName(img.Reference()))
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
2018-06-12 07:36:23 +08:00
|
|
|
return nil
|
2017-05-17 05:26:02 +08:00
|
|
|
}
|
|
|
|
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
func (b *Builder) initConfig(ctx context.Context, img types.Image, sys *types.SystemContext) error {
|
2018-06-12 06:41:11 +08:00
|
|
|
if img != nil { // A pre-existing image, as opposed to a "FROM scratch" new one.
|
2018-06-12 06:47:48 +08:00
|
|
|
rawManifest, manifestMIMEType, err := img.Manifest(ctx)
|
2018-06-12 06:41:11 +08:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error reading image manifest for %q", transports.ImageName(img.Reference()))
|
|
|
|
}
|
|
|
|
rawConfig, err := img.ConfigBlob(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error reading image configuration for %q", transports.ImageName(img.Reference()))
|
|
|
|
}
|
|
|
|
b.Manifest = rawManifest
|
|
|
|
b.Config = rawConfig
|
|
|
|
|
2018-06-12 07:36:23 +08:00
|
|
|
dimage := docker.V2Image{}
|
|
|
|
if err := unmarshalConvertedConfig(ctx, &dimage, img, manifest.DockerV2Schema2MediaType); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b.Docker = dimage
|
|
|
|
|
|
|
|
oimage := ociv1.Image{}
|
|
|
|
if err := unmarshalConvertedConfig(ctx, &oimage, img, ociv1.MediaTypeImageManifest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b.OCIv1 = oimage
|
2018-06-12 05:53:45 +08:00
|
|
|
|
2018-06-12 07:36:23 +08:00
|
|
|
if manifestMIMEType == ociv1.MediaTypeImageManifest {
|
2018-06-12 05:53:45 +08:00
|
|
|
// Attempt to recover format-specific data from the manifest.
|
|
|
|
v1Manifest := ociv1.Manifest{}
|
|
|
|
if err := json.Unmarshal(b.Manifest, &v1Manifest); err != nil {
|
2018-10-03 22:05:46 +08:00
|
|
|
return errors.Wrapf(err, "error parsing OCI manifest %q", string(b.Manifest))
|
2018-06-12 05:53:45 +08:00
|
|
|
}
|
2021-08-03 16:39:06 +08:00
|
|
|
for k, v := range v1Manifest.Annotations {
|
|
|
|
// NOTE: do not override annotations that are
|
|
|
|
// already set. Otherwise, we may erase
|
|
|
|
// annotations such as the digest of the base
|
|
|
|
// image.
|
|
|
|
if value := b.ImageAnnotations[k]; value == "" {
|
|
|
|
b.ImageAnnotations[k] = v
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 02:23:50 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-12 06:08:57 +08:00
|
|
|
|
2021-05-08 01:38:44 +08:00
|
|
|
b.setupLogger()
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
b.fixupConfig(sys)
|
2018-06-12 05:43:21 +08:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
func (b *Builder) fixupConfig(sys *types.SystemContext) {
|
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.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 = ""
|
2017-06-07 02:11:46 +08:00
|
|
|
now := time.Now().UTC()
|
|
|
|
if b.Docker.Created.IsZero() {
|
|
|
|
b.Docker.Created = now
|
|
|
|
}
|
2017-06-28 23:40:28 +08:00
|
|
|
if b.OCIv1.Created == nil || b.OCIv1.Created.IsZero() {
|
|
|
|
b.OCIv1.Created = &now
|
2017-06-07 02:11:46 +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() == "" {
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
if sys != nil && sys.OSChoice != "" {
|
|
|
|
b.SetOS(sys.OSChoice)
|
|
|
|
} else {
|
|
|
|
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() == "" {
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
if sys != nil && sys.ArchitectureChoice != "" {
|
|
|
|
b.SetArchitecture(sys.ArchitectureChoice)
|
|
|
|
} else {
|
|
|
|
b.SetArchitecture(runtime.GOARCH)
|
|
|
|
}
|
2021-11-05 01:29:08 +08:00
|
|
|
// in case the arch string we started with was shorthand for a known arch+variant pair, normalize it
|
|
|
|
ps := platforms.Normalize(ociv1.Platform{OS: b.OS(), Architecture: b.Architecture(), Variant: b.Variant()})
|
|
|
|
b.SetArchitecture(ps.Architecture)
|
|
|
|
b.SetVariant(ps.Variant)
|
2017-02-11 00:48:15 +08:00
|
|
|
}
|
2021-03-02 02:07:58 +08:00
|
|
|
if b.Format == define.Dockerv2ImageManifest && b.Hostname() == "" {
|
2018-08-24 18:51:36 +08:00
|
|
|
b.SetHostname(stringid.TruncateID(stringid.GenerateRandomID()))
|
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
|
|
|
}
|
|
|
|
|
2021-05-08 01:38:44 +08:00
|
|
|
func (b *Builder) setupLogger() {
|
|
|
|
if b.Logger == nil {
|
|
|
|
b.Logger = logrus.New()
|
|
|
|
b.Logger.SetOutput(os.Stderr)
|
|
|
|
b.Logger.SetLevel(logrus.GetLevel())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-11-05 01:29:08 +08:00
|
|
|
// Variant returns a name of the architecture variant on which the container,
|
|
|
|
// or a container built using an image built from this container, is intended
|
|
|
|
// to be run.
|
|
|
|
func (b *Builder) Variant() string {
|
|
|
|
return b.OCIv1.Variant
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVariant sets the name of the architecture variant on which the container,
|
|
|
|
// or a container built using an image built from this container, is intended
|
|
|
|
// to be run.
|
|
|
|
func (b *Builder) SetVariant(variant string) {
|
|
|
|
b.Docker.Variant = variant
|
|
|
|
b.OCIv1.Variant = variant
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-05-25 15:53:30 +08:00
|
|
|
// OnBuild returns the OnBuild value from the container.
|
|
|
|
func (b *Builder) OnBuild() []string {
|
|
|
|
return copyStringSlice(b.Docker.Config.OnBuild)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearOnBuild removes all values from the OnBuild structure
|
|
|
|
func (b *Builder) ClearOnBuild() {
|
|
|
|
b.Docker.Config.OnBuild = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOnBuild sets a trigger instruction to be executed when the image is used
|
|
|
|
// as the base of another image.
|
|
|
|
// Note: this setting is not present in the OCIv1 image format, so it is
|
|
|
|
// discarded when writing images using OCIv1 formats.
|
|
|
|
func (b *Builder) SetOnBuild(onBuild string) {
|
2021-03-02 02:07:58 +08:00
|
|
|
if onBuild != "" && b.Format != define.Dockerv2ImageManifest {
|
2021-09-25 03:06:08 +08:00
|
|
|
b.Logger.Warnf("ONBUILD is not supported for OCI image format, %s will be ignored. Must use `docker` format", onBuild)
|
2018-08-24 00:55:16 +08:00
|
|
|
}
|
2018-05-25 15:53:30 +08:00
|
|
|
b.Docker.Config.OnBuild = append(b.Docker.Config.OnBuild, onBuild)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-03-16 19:57:36 +08:00
|
|
|
// Shell returns the default shell for running commands in the
|
|
|
|
// container, or in a container built using an image built from this container.
|
|
|
|
func (b *Builder) Shell() []string {
|
2018-05-25 15:53:30 +08:00
|
|
|
return copyStringSlice(b.Docker.Config.Shell)
|
2018-03-16 19:57:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetShell sets the default shell for running
|
|
|
|
// commands in the container, or in a container built using an image built from
|
|
|
|
// this 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) SetShell(shell []string) {
|
2021-03-02 02:07:58 +08:00
|
|
|
if len(shell) > 0 && b.Format != define.Dockerv2ImageManifest {
|
2021-09-25 03:06:08 +08:00
|
|
|
b.Logger.Warnf("SHELL is not supported for OCI image format, %s will be ignored. Must use `docker` format", shell)
|
2018-08-24 00:55:16 +08:00
|
|
|
}
|
|
|
|
|
2018-05-25 15:53:30 +08:00
|
|
|
b.Docker.Config.Shell = copyStringSlice(shell)
|
2018-03-16 19:57:36 +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
|
|
|
// 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 {
|
2018-08-24 18:51:36 +08:00
|
|
|
if len(b.OCIv1.Config.Entrypoint) > 0 {
|
|
|
|
return copyStringSlice(b.OCIv1.Config.Entrypoint)
|
|
|
|
}
|
|
|
|
return 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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2018-08-24 18:51:36 +08:00
|
|
|
if len(v) > 0 {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
return 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
|
|
|
}
|
|
|
|
|
2019-08-06 22:41:50 +08:00
|
|
|
// CheckVolume returns True if the location exists in 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) CheckVolume(v string) bool {
|
|
|
|
_, OCIv1Volume := b.OCIv1.Config.Volumes[v]
|
|
|
|
_, DockerVolume := b.Docker.Config.Volumes[v]
|
|
|
|
return OCIv1Volume || DockerVolume
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// 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) {
|
2019-08-06 22:41:50 +08:00
|
|
|
delete(b.OCIv1.Config.Volumes, v)
|
|
|
|
delete(b.Docker.Config.Volumes, v)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2021-03-02 02:07:58 +08:00
|
|
|
if name != "" && b.Format != define.Dockerv2ImageManifest {
|
2021-09-25 03:06:08 +08:00
|
|
|
b.Logger.Warnf("DOMAINNAME is not supported for OCI image format, domainname %s will be ignored. Must use `docker` format", name)
|
2018-08-24 00:55:16 +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.Domainname = name
|
2017-03-28 15:06:13 +08:00
|
|
|
}
|
2017-11-08 06:44:24 +08:00
|
|
|
|
|
|
|
// SetDefaultMountsFilePath sets the mounts file path for testing purposes
|
|
|
|
func (b *Builder) SetDefaultMountsFilePath(path string) {
|
|
|
|
b.DefaultMountsFilePath = path
|
|
|
|
}
|
2018-04-06 23:22:13 +08:00
|
|
|
|
|
|
|
// Comment returns the comment which will be set in the container and in
|
|
|
|
// containers built using images built from the container
|
|
|
|
func (b *Builder) Comment() string {
|
|
|
|
return b.Docker.Comment
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:59:03 +08:00
|
|
|
// SetComment sets the comment which will be set in the container and in
|
2018-04-06 23:22:13 +08:00
|
|
|
// 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) SetComment(comment string) {
|
2021-03-02 02:07:58 +08:00
|
|
|
if comment != "" && b.Format != define.Dockerv2ImageManifest {
|
2020-09-15 21:18:25 +08:00
|
|
|
logrus.Warnf("COMMENT is not supported for OCI image format, comment %s will be ignored. Must use `docker` format", comment)
|
2018-08-24 00:55:16 +08:00
|
|
|
}
|
2018-04-06 23:22:13 +08:00
|
|
|
b.Docker.Comment = comment
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:59:03 +08:00
|
|
|
// HistoryComment returns the comment which will be used in the history item
|
|
|
|
// which will describe the latest layer when we commit an image.
|
|
|
|
func (b *Builder) HistoryComment() string {
|
|
|
|
return b.ImageHistoryComment
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHistoryComment sets the comment which will be used in the history item
|
|
|
|
// which will describe the latest layer when we commit an image.
|
|
|
|
func (b *Builder) SetHistoryComment(comment string) {
|
|
|
|
b.ImageHistoryComment = comment
|
|
|
|
}
|
|
|
|
|
2018-04-06 23:22:13 +08:00
|
|
|
// StopSignal returns the signal which will be set in the container and in
|
2020-12-22 00:19:56 +08:00
|
|
|
// containers built using images built from the container
|
2018-04-06 23:22:13 +08:00
|
|
|
func (b *Builder) StopSignal() string {
|
|
|
|
return b.Docker.Config.StopSignal
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStopSignal sets the signal which will be set in the container and in
|
|
|
|
// containers built using images built from the container.
|
|
|
|
func (b *Builder) SetStopSignal(stopSignal string) {
|
|
|
|
b.OCIv1.Config.StopSignal = stopSignal
|
|
|
|
b.Docker.Config.StopSignal = stopSignal
|
|
|
|
}
|
2018-08-21 03:25:10 +08:00
|
|
|
|
|
|
|
// Healthcheck returns information that recommends how a container engine
|
|
|
|
// should check if a running container is "healthy".
|
|
|
|
func (b *Builder) Healthcheck() *docker.HealthConfig {
|
|
|
|
if b.Docker.Config.Healthcheck == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &docker.HealthConfig{
|
|
|
|
Test: copyStringSlice(b.Docker.Config.Healthcheck.Test),
|
|
|
|
Interval: b.Docker.Config.Healthcheck.Interval,
|
|
|
|
Timeout: b.Docker.Config.Healthcheck.Timeout,
|
|
|
|
StartPeriod: b.Docker.Config.Healthcheck.StartPeriod,
|
|
|
|
Retries: b.Docker.Config.Healthcheck.Retries,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHealthcheck sets recommended commands to run in order to verify that a
|
|
|
|
// running container based on this image is "healthy", along with information
|
|
|
|
// specifying how often that test should be run, and how many times the test
|
|
|
|
// should fail before the container should be considered unhealthy.
|
|
|
|
// Note: this setting is not present in the OCIv1 image format, so it is
|
|
|
|
// discarded when writing images using OCIv1 formats.
|
|
|
|
func (b *Builder) SetHealthcheck(config *docker.HealthConfig) {
|
|
|
|
b.Docker.Config.Healthcheck = nil
|
|
|
|
if config != nil {
|
2021-03-02 02:07:58 +08:00
|
|
|
if b.Format != define.Dockerv2ImageManifest {
|
2021-09-25 03:06:08 +08:00
|
|
|
b.Logger.Warnf("HEALTHCHECK is not supported for OCI image format and will be ignored. Must use `docker` format")
|
2020-09-16 02:29:15 +08:00
|
|
|
}
|
2018-08-21 03:25:10 +08:00
|
|
|
b.Docker.Config.Healthcheck = &docker.HealthConfig{
|
|
|
|
Test: copyStringSlice(config.Test),
|
|
|
|
Interval: config.Interval,
|
|
|
|
Timeout: config.Timeout,
|
|
|
|
StartPeriod: config.StartPeriod,
|
|
|
|
Retries: config.Retries,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 04:39:58 +08:00
|
|
|
|
|
|
|
// AddPrependedEmptyLayer adds an item to the history that we'll create when
|
2019-07-18 16:45:52 +08:00
|
|
|
// committing the image, after any history we inherit from the base image, but
|
2019-01-19 04:39:58 +08:00
|
|
|
// before the history item that we'll use to describe the new layer that we're
|
|
|
|
// adding.
|
|
|
|
func (b *Builder) AddPrependedEmptyLayer(created *time.Time, createdBy, author, comment string) {
|
|
|
|
if created != nil {
|
|
|
|
copiedTimestamp := *created
|
|
|
|
created = &copiedTimestamp
|
|
|
|
}
|
|
|
|
b.PrependedEmptyLayers = append(b.PrependedEmptyLayers, ociv1.History{
|
|
|
|
Created: created,
|
|
|
|
CreatedBy: createdBy,
|
|
|
|
Author: author,
|
|
|
|
Comment: comment,
|
|
|
|
EmptyLayer: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearPrependedEmptyLayers clears the list of history entries that we'll add
|
|
|
|
// to the committed image before the entry for the layer that we're adding.
|
|
|
|
func (b *Builder) ClearPrependedEmptyLayers() {
|
|
|
|
b.PrependedEmptyLayers = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAppendedEmptyLayer adds an item to the history that we'll create when
|
2019-07-18 16:45:52 +08:00
|
|
|
// committing the image, after the history item that we'll use to describe the
|
2019-01-19 04:39:58 +08:00
|
|
|
// new layer that we're adding.
|
|
|
|
func (b *Builder) AddAppendedEmptyLayer(created *time.Time, createdBy, author, comment string) {
|
|
|
|
if created != nil {
|
|
|
|
copiedTimestamp := *created
|
|
|
|
created = &copiedTimestamp
|
|
|
|
}
|
|
|
|
b.AppendedEmptyLayers = append(b.AppendedEmptyLayers, ociv1.History{
|
|
|
|
Created: created,
|
|
|
|
CreatedBy: createdBy,
|
|
|
|
Author: author,
|
|
|
|
Comment: comment,
|
|
|
|
EmptyLayer: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearAppendedEmptyLayers clears the list of history entries that we'll add
|
|
|
|
// to the committed image after the entry for the layer that we're adding.
|
|
|
|
func (b *Builder) ClearAppendedEmptyLayers() {
|
|
|
|
b.AppendedEmptyLayers = nil
|
|
|
|
}
|