2017-04-11 22:27:05 +08:00
|
|
|
package buildah
|
|
|
|
|
|
|
|
import (
|
2017-10-10 03:05:56 +08:00
|
|
|
"github.com/containers/storage/pkg/chrootarchive"
|
2018-03-08 07:11:43 +08:00
|
|
|
"github.com/containers/storage/pkg/idtools"
|
2017-04-11 22:27:05 +08:00
|
|
|
"github.com/containers/storage/pkg/reexec"
|
2018-03-08 07:11:43 +08:00
|
|
|
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
2017-04-11 22:27:05 +08:00
|
|
|
)
|
|
|
|
|
2017-10-10 03:05:56 +08:00
|
|
|
var (
|
|
|
|
// CopyWithTar defines the copy method to use.
|
|
|
|
copyWithTar = chrootarchive.NewArchiver(nil).CopyWithTar
|
|
|
|
copyFileWithTar = chrootarchive.NewArchiver(nil).CopyFileWithTar
|
|
|
|
untarPath = chrootarchive.NewArchiver(nil).UntarPath
|
|
|
|
)
|
|
|
|
|
2017-04-11 22:27:05 +08:00
|
|
|
// InitReexec is a wrapper for reexec.Init(). It should be called at
|
|
|
|
// the start of main(), and if it returns true, main() should return
|
|
|
|
// immediately.
|
|
|
|
func InitReexec() bool {
|
|
|
|
return reexec.Init()
|
|
|
|
}
|
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 copyStringStringMap(m map[string]string) map[string]string {
|
|
|
|
n := map[string]string{}
|
|
|
|
for k, v := range m {
|
|
|
|
n[k] = v
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func copyStringSlice(s []string) []string {
|
|
|
|
t := make([]string, len(s))
|
|
|
|
copy(t, s)
|
|
|
|
return t
|
|
|
|
}
|
2018-03-08 07:11:43 +08:00
|
|
|
|
|
|
|
func convertStorageIDMaps(UIDMap, GIDMap []idtools.IDMap) ([]rspec.LinuxIDMapping, []rspec.LinuxIDMapping) {
|
|
|
|
uidmap := make([]rspec.LinuxIDMapping, 0, len(UIDMap))
|
|
|
|
gidmap := make([]rspec.LinuxIDMapping, 0, len(GIDMap))
|
|
|
|
for _, m := range UIDMap {
|
|
|
|
uidmap = append(uidmap, rspec.LinuxIDMapping{
|
|
|
|
HostID: uint32(m.HostID),
|
|
|
|
ContainerID: uint32(m.ContainerID),
|
|
|
|
Size: uint32(m.Size),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for _, m := range GIDMap {
|
|
|
|
gidmap = append(gidmap, rspec.LinuxIDMapping{
|
|
|
|
HostID: uint32(m.HostID),
|
|
|
|
ContainerID: uint32(m.ContainerID),
|
|
|
|
Size: uint32(m.Size),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return uidmap, gidmap
|
|
|
|
}
|