Merge pull request #4039 from deitch/split-moby

move moby components that do not have runtime dependencies to own directory
This commit is contained in:
Avi Deitcher 2024-05-07 20:27:35 +03:00 committed by GitHub
commit 6d37353ca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 105 additions and 79 deletions

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby" "github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
mobybuild "github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby/build"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec" "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -52,7 +53,7 @@ func buildCmd() *cobra.Command {
arch string arch string
cacheDir flagOverEnvVarOverDefaultString cacheDir flagOverEnvVarOverDefaultString
buildFormats formatList buildFormats formatList
outputTypes = moby.OutputTypes() outputTypes = mobybuild.OutputTypes()
noSbom bool noSbom bool
sbomOutputFilename string sbomOutputFilename string
inputTar string inputTar string
@ -94,13 +95,13 @@ The generated image can be in one of multiple formats which can be run on variou
if len(buildFormats) > 1 { if len(buildFormats) > 1 {
for _, o := range buildFormats { for _, o := range buildFormats {
if moby.Streamable(o) { if mobybuild.Streamable(o) {
return fmt.Errorf("format type %s must be the only format specified", o) return fmt.Errorf("format type %s must be the only format specified", o)
} }
} }
} }
if len(buildFormats) == 1 && moby.Streamable(buildFormats[0]) { if len(buildFormats) == 1 && mobybuild.Streamable(buildFormats[0]) {
if outputFile == "" { if outputFile == "" {
outputFile = filepath.Join(dir, name+"."+buildFormats[0]) outputFile = filepath.Join(dir, name+"."+buildFormats[0])
// stop the errors in the validation below // stop the errors in the validation below
@ -108,7 +109,7 @@ The generated image can be in one of multiple formats which can be run on variou
dir = "" dir = ""
} }
} else { } else {
err := moby.ValidateFormats(buildFormats, cacheDir.String()) err := mobybuild.ValidateFormats(buildFormats, cacheDir.String())
if err != nil { if err != nil {
return fmt.Errorf("error parsing formats: %v", err) return fmt.Errorf("error parsing formats: %v", err)
} }
@ -129,7 +130,7 @@ The generated image can be in one of multiple formats which can be run on variou
if dir != "" { if dir != "" {
return fmt.Errorf("the -output option cannot be specified with -dir") return fmt.Errorf("the -output option cannot be specified with -dir")
} }
if !moby.Streamable(buildFormats[0]) { if !mobybuild.Streamable(buildFormats[0]) {
return fmt.Errorf("the -output option cannot be specified for build type %s as it cannot be streamed", buildFormats[0]) return fmt.Errorf("the -output option cannot be specified for build type %s as it cannot be streamed", buildFormats[0])
} }
if outputFile == "-" { if outputFile == "-" {
@ -225,17 +226,17 @@ The generated image can be in one of multiple formats which can be run on variou
// this is a weird interface, but currently only streamable types can have additional files // this is a weird interface, but currently only streamable types can have additional files
// need to split up the base tarball outputs from the secondary stages // need to split up the base tarball outputs from the secondary stages
var tp string var tp string
if moby.Streamable(buildFormats[0]) { if mobybuild.Streamable(buildFormats[0]) {
tp = buildFormats[0] tp = buildFormats[0]
} }
var sbomGenerator *moby.SbomGenerator var sbomGenerator *mobybuild.SbomGenerator
if !noSbom { if !noSbom {
sbomGenerator, err = moby.NewSbomGenerator(sbomOutputFilename, sbomCurrentTime) sbomGenerator, err = mobybuild.NewSbomGenerator(sbomOutputFilename, sbomCurrentTime)
if err != nil { if err != nil {
return fmt.Errorf("error creating sbom generator: %v", err) return fmt.Errorf("error creating sbom generator: %v", err)
} }
} }
err = moby.Build(m, w, moby.BuildOpts{Pull: pull, BuilderType: tp, DecompressKernel: decompressKernel, CacheDir: cacheDir.String(), DockerCache: docker, Arch: arch, SbomGenerator: sbomGenerator, InputTar: inputTar}) err = mobybuild.Build(m, w, mobybuild.BuildOpts{Pull: pull, BuilderType: tp, DecompressKernel: decompressKernel, CacheDir: cacheDir.String(), DockerCache: docker, Arch: arch, SbomGenerator: sbomGenerator, InputTar: inputTar})
if err != nil { if err != nil {
return fmt.Errorf("%v", err) return fmt.Errorf("%v", err)
} }
@ -247,7 +248,7 @@ The generated image can be in one of multiple formats which can be run on variou
} }
log.Infof("Create outputs:") log.Infof("Create outputs:")
err = moby.Formats(filepath.Join(dir, name), image, buildFormats, size, arch, cacheDir.String()) err = mobybuild.Formats(filepath.Join(dir, name), image, buildFormats, size, arch, cacheDir.String())
if err != nil { if err != nil {
return fmt.Errorf("error writing outputs: %v", err) return fmt.Errorf("error writing outputs: %v", err)
} }

View File

@ -19,7 +19,7 @@ type apkTarWriter struct {
location string location string
} }
func newAPKTarWriter(w *tar.Writer, location string) *apkTarWriter { func NewAPKTarWriter(w *tar.Writer, location string) *apkTarWriter {
return &apkTarWriter{ return &apkTarWriter{
Writer: w, Writer: w,
location: location, location: location,

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"archive/tar" "archive/tar"
@ -18,6 +18,7 @@ import (
"github.com/containerd/containerd/reference" "github.com/containerd/containerd/reference"
// drop-in 100% compatible replacement and 17% faster than compress/gzip. // drop-in 100% compatible replacement and 17% faster than compress/gzip.
gzip "github.com/klauspost/pgzip" gzip "github.com/klauspost/pgzip"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util" "github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -83,7 +84,7 @@ func OutputTypes() []string {
return ts return ts
} }
func outputImage(image *Image, section string, index int, prefix string, m Moby, idMap map[string]uint32, dupMap map[string]string, iw *tar.Writer, opts BuildOpts) error { func outputImage(image *moby.Image, section string, index int, prefix string, m moby.Moby, idMap map[string]uint32, dupMap map[string]string, iw *tar.Writer, opts BuildOpts) error {
log.Infof(" Create OCI config for %s", image.Image) log.Infof(" Create OCI config for %s", image.Image)
imageName := util.ReferenceExpand(image.Image) imageName := util.ReferenceExpand(image.Image)
ref, err := reference.Parse(imageName) ref, err := reference.Parse(imageName)
@ -98,7 +99,7 @@ func outputImage(image *Image, section string, index int, prefix string, m Moby,
if err != nil { if err != nil {
return fmt.Errorf("failed to retrieve config for %s: %v", image.Image, err) return fmt.Errorf("failed to retrieve config for %s: %v", image.Image, err)
} }
oci, runtime, err := ConfigToOCI(image, configRaw, idMap) oci, runtime, err := moby.ConfigToOCI(image, configRaw, idMap)
if err != nil { if err != nil {
return fmt.Errorf("failed to create OCI spec for %s: %v", image.Image, err) return fmt.Errorf("failed to create OCI spec for %s: %v", image.Image, err)
} }
@ -108,7 +109,7 @@ func outputImage(image *Image, section string, index int, prefix string, m Moby,
} }
path := path.Join("containers", section, prefix+image.Name) path := path.Join("containers", section, prefix+image.Name)
readonly := oci.Root.Readonly readonly := oci.Root.Readonly
err = ImageBundle(path, fmt.Sprintf("%s[%d]", section, index), image.ref, config, runtime, iw, readonly, dupMap, opts) err = ImageBundle(path, fmt.Sprintf("%s[%d]", section, index), image.Ref(), config, runtime, iw, readonly, dupMap, opts)
if err != nil { if err != nil {
return fmt.Errorf("failed to extract root filesystem for %s: %v", image.Image, err) return fmt.Errorf("failed to extract root filesystem for %s: %v", image.Image, err)
} }
@ -117,7 +118,7 @@ func outputImage(image *Image, section string, index int, prefix string, m Moby,
// Build performs the actual build process. The output is the filesystem // Build performs the actual build process. The output is the filesystem
// in a tar stream written to w. // in a tar stream written to w.
func Build(m Moby, w io.Writer, opts BuildOpts) error { func Build(m moby.Moby, w io.Writer, opts BuildOpts) error {
if MobyDir == "" { if MobyDir == "" {
MobyDir = defaultMobyConfigDir() MobyDir = defaultMobyConfigDir()
} }
@ -138,7 +139,7 @@ func Build(m Moby, w io.Writer, opts BuildOpts) error {
} }
} }
var ( var (
oldConfig *Moby oldConfig *moby.Moby
in *os.File in *os.File
err error err error
) )
@ -167,7 +168,7 @@ func Build(m Moby, w io.Writer, opts BuildOpts) error {
if _, err := buf.ReadFrom(inputTarReader); err != nil { if _, err := buf.ReadFrom(inputTarReader); err != nil {
return fmt.Errorf("failed to read metadata file from input tar: %w", err) return fmt.Errorf("failed to read metadata file from input tar: %w", err)
} }
config, err := NewConfig(buf.Bytes(), nil) config, err := moby.NewConfig(buf.Bytes(), nil)
if err != nil { if err != nil {
return fmt.Errorf("invalid config in existing tar file: %v", err) return fmt.Errorf("invalid config in existing tar file: %v", err)
} }
@ -202,18 +203,22 @@ func Build(m Moby, w io.Writer, opts BuildOpts) error {
// deduplicate containers with the same image // deduplicate containers with the same image
dupMap := map[string]string{} dupMap := map[string]string{}
if m.Kernel.ref != nil { kernelRef := m.Kernel.Ref()
var oldKernelRef *reference.Spec
if oldConfig != nil {
oldKernelRef = oldConfig.Kernel.Ref()
}
if kernelRef != nil {
// first check if the existing one had it // first check if the existing one had it
//if config != nil && len(oldConfig.initRefs) > index+1 && oldConfig.initRefs[index].String() == image { if oldKernelRef != nil && oldKernelRef.String() == kernelRef.String() {
if oldConfig != nil && oldConfig.Kernel.ref != nil && oldConfig.Kernel.ref.String() == m.Kernel.ref.String() { if err := extractPackageFilesFromTar(in, iw, kernelRef.String(), "kernel"); err != nil {
if err := extractPackageFilesFromTar(in, iw, m.Kernel.ref.String(), "kernel"); err != nil {
return err return err
} }
} else { } else {
// get kernel and initrd tarball and ucode cpio archive from container // get kernel and initrd tarball and ucode cpio archive from container
log.Infof("Extract kernel image: %s", m.Kernel.ref) log.Infof("Extract kernel image: %s", m.Kernel.Ref())
kf := newKernelFilter(m.Kernel.ref, iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode, opts.DecompressKernel) kf := newKernelFilter(kernelRef, iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode, opts.DecompressKernel)
err := ImageTar("kernel", m.Kernel.ref, "", kf, "", opts) err := ImageTar("kernel", kernelRef, "", kf, "", opts)
if err != nil { if err != nil {
return fmt.Errorf("failed to extract kernel image and tarball: %v", err) return fmt.Errorf("failed to extract kernel image and tarball: %v", err)
} }
@ -228,9 +233,14 @@ func Build(m Moby, w io.Writer, opts BuildOpts) error {
if len(m.Init) != 0 { if len(m.Init) != 0 {
log.Infof("Add init containers:") log.Infof("Add init containers:")
} }
apkTar := newAPKTarWriter(iw, "init") apkTar := moby.NewAPKTarWriter(iw, "init")
for i, ii := range m.initRefs { initRefs := m.InitRefs()
if oldConfig != nil && len(oldConfig.initRefs) > i && oldConfig.initRefs[i].String() == ii.String() { var oldInitRefs []*reference.Spec
if oldConfig != nil {
oldInitRefs = oldConfig.InitRefs()
}
for i, ii := range initRefs {
if len(oldInitRefs) > i && oldInitRefs[i].String() == ii.String() {
if err := extractPackageFilesFromTar(in, apkTar, ii.String(), fmt.Sprintf("init[%d]", i)); err != nil { if err := extractPackageFilesFromTar(in, apkTar, ii.String(), fmt.Sprintf("init[%d]", i)); err != nil {
return err return err
} }
@ -521,8 +531,8 @@ func tarAppend(ref *reference.Spec, iw *tar.Writer, tr *tar.Reader) error {
if hdr.PAXRecords == nil { if hdr.PAXRecords == nil {
hdr.PAXRecords = make(map[string]string) hdr.PAXRecords = make(map[string]string)
} }
hdr.PAXRecords[PaxRecordLinuxkitSource] = ref.String() hdr.PAXRecords[moby.PaxRecordLinuxkitSource] = ref.String()
hdr.PAXRecords[PaxRecordLinuxkitLocation] = "kernel" hdr.PAXRecords[moby.PaxRecordLinuxkitLocation] = "kernel"
err = iw.WriteHeader(hdr) err = iw.WriteHeader(hdr)
if err != nil { if err != nil {
return err return err
@ -615,9 +625,9 @@ func gunzip(src *bytes.Buffer) (*bytes.Buffer, error) {
} }
// this allows inserting metadata into a file in the image // this allows inserting metadata into a file in the image
func metadata(m Moby, md string) ([]byte, error) { func metadata(m moby.Moby, md string) ([]byte, error) {
// Make sure the Image strings are update to date with the refs // Make sure the Image strings are update to date with the refs
updateImages(&m) moby.UpdateImages(&m)
switch md { switch md {
case "json": case "json":
return json.MarshalIndent(m, "", " ") return json.MarshalIndent(m, "", " ")
@ -628,7 +638,7 @@ func metadata(m Moby, md string) ([]byte, error) {
} }
} }
func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error { func filesystem(m moby.Moby, tw *tar.Writer, idMap map[string]uint32) error {
// TODO also include the files added in other parts of the build // TODO also include the files added in other parts of the build
var addedFiles = map[string]bool{} var addedFiles = map[string]bool{}
@ -666,11 +676,11 @@ func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error {
dirMode |= 0001 dirMode |= 0001
} }
uid, err := idNumeric(f.UID, idMap) uid, err := moby.IDNumeric(f.UID, idMap)
if err != nil { if err != nil {
return err return err
} }
gid, err := idNumeric(f.GID, idMap) gid, err := moby.IDNumeric(f.GID, idMap)
if err != nil { if err != nil {
return err return err
} }
@ -740,8 +750,8 @@ func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error {
Gid: int(gid), Gid: int(gid),
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: "linuxkit.files", moby.PaxRecordLinuxkitSource: "linuxkit.files",
PaxRecordLinuxkitLocation: fmt.Sprintf("files[%d]", filecount), moby.PaxRecordLinuxkitLocation: fmt.Sprintf("files[%d]", filecount),
}, },
} }
err := tw.WriteHeader(hdr) err := tw.WriteHeader(hdr)
@ -760,8 +770,8 @@ func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error {
Gid: int(gid), Gid: int(gid),
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: "linuxkit.files", moby.PaxRecordLinuxkitSource: "linuxkit.files",
PaxRecordLinuxkitLocation: fmt.Sprintf("files[%d]", filecount), moby.PaxRecordLinuxkitLocation: fmt.Sprintf("files[%d]", filecount),
}, },
} }
if f.Directory { if f.Directory {
@ -815,7 +825,7 @@ func extractPackageFilesFromTar(inTar *os.File, tw tarWriter, image, section str
if hdr.PAXRecords == nil { if hdr.PAXRecords == nil {
continue continue
} }
if hdr.PAXRecords[PaxRecordLinuxkitSource] == image && hdr.PAXRecords[PaxRecordLinuxkitLocation] == section { if hdr.PAXRecords[moby.PaxRecordLinuxkitSource] == image && hdr.PAXRecords[moby.PaxRecordLinuxkitLocation] == section {
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
return fmt.Errorf("failed to write header: %w", err) return fmt.Errorf("failed to write header: %w", err)
} }

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"path/filepath" "path/filepath"

View File

@ -1,4 +1,4 @@
package moby package build
// We want to replace much of this with use of containerd tools // We want to replace much of this with use of containerd tools
// and also using the Docker API not shelling out // and also using the Docker API not shelling out

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"archive/tar" "archive/tar"
@ -10,18 +10,11 @@ import (
"strings" "strings"
"github.com/containerd/containerd/reference" "github.com/containerd/containerd/reference"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
const (
// PaxRecordLinuxkitSource report the package source for a specific file
PaxRecordLinuxkitSource = "LINUXKIT.source"
// PaxRecordLinuxkitLocation report the location of the file in the linuxkit.yaml
// that led to this file being in this location
PaxRecordLinuxkitLocation = "LINUXKIT.location"
)
type tarWriter interface { type tarWriter interface {
Close() error Close() error
Flush() error Flush() error
@ -170,8 +163,8 @@ func tarPrefix(path, location string, ref *reference.Spec, tw tarWriter) error {
Typeflag: tar.TypeDir, Typeflag: tar.TypeDir,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -232,8 +225,8 @@ func ImageTar(location string, ref *reference.Spec, prefix string, tw tarWriter,
if hdr.PAXRecords == nil { if hdr.PAXRecords == nil {
hdr.PAXRecords = make(map[string]string) hdr.PAXRecords = make(map[string]string)
} }
hdr.PAXRecords[PaxRecordLinuxkitSource] = ref.String() hdr.PAXRecords[moby.PaxRecordLinuxkitSource] = ref.String()
hdr.PAXRecords[PaxRecordLinuxkitLocation] = location hdr.PAXRecords[moby.PaxRecordLinuxkitLocation] = location
if exclude[hdr.Name] { if exclude[hdr.Name] {
log.Debugf("image tar: %s %s exclude %s", ref, prefix, hdr.Name) log.Debugf("image tar: %s %s exclude %s", ref, prefix, hdr.Name)
_, err = io.Copy(io.Discard, tr) _, err = io.Copy(io.Discard, tr)
@ -310,8 +303,8 @@ func ImageTar(location string, ref *reference.Spec, prefix string, tw tarWriter,
if hdr.PAXRecords == nil { if hdr.PAXRecords == nil {
hdr.PAXRecords = make(map[string]string) hdr.PAXRecords = make(map[string]string)
} }
hdr.PAXRecords[PaxRecordLinuxkitSource] = ref.String() hdr.PAXRecords[moby.PaxRecordLinuxkitSource] = ref.String()
hdr.PAXRecords[PaxRecordLinuxkitLocation] = location hdr.PAXRecords[moby.PaxRecordLinuxkitLocation] = location
origName := hdr.Name origName := hdr.Name
hdr.Name = prefix + origName hdr.Name = prefix + origName
hdr.Format = tar.FormatPAX hdr.Format = tar.FormatPAX
@ -355,7 +348,7 @@ func ImageTar(location string, ref *reference.Spec, prefix string, tw tarWriter,
} }
// ImageBundle produces an OCI bundle at the given path in a tarball, given an image and a config.json // ImageBundle produces an OCI bundle at the given path in a tarball, given an image and a config.json
func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, runtime Runtime, tw tarWriter, readonly bool, dupMap map[string]string, opts BuildOpts) error { // nolint: lll func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, runtime moby.Runtime, tw tarWriter, readonly bool, dupMap map[string]string, opts BuildOpts) error { // nolint: lll
// if read only, just unpack in rootfs/ but otherwise set up for overlay // if read only, just unpack in rootfs/ but otherwise set up for overlay
rootExtract := "rootfs" rootExtract := "rootfs"
if !readonly { if !readonly {
@ -384,8 +377,8 @@ func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, ru
ModTime: defaultModTime, ModTime: defaultModTime,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -406,8 +399,8 @@ func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, ru
ModTime: defaultModTime, ModTime: defaultModTime,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -421,8 +414,8 @@ func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, ru
ModTime: defaultModTime, ModTime: defaultModTime,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -445,8 +438,8 @@ func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, ru
ModTime: defaultModTime, ModTime: defaultModTime,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -476,8 +469,8 @@ func ImageBundle(prefix, location string, ref *reference.Spec, config []byte, ru
ModTime: defaultModTime, ModTime: defaultModTime,
Format: tar.FormatPAX, Format: tar.FormatPAX,
PAXRecords: map[string]string{ PAXRecords: map[string]string{
PaxRecordLinuxkitSource: ref.String(), moby.PaxRecordLinuxkitSource: ref.String(),
PaxRecordLinuxkitLocation: location, moby.PaxRecordLinuxkitLocation: location,
}, },
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"github.com/containerd/containerd/reference" "github.com/containerd/containerd/reference"

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"crypto/sha256" "crypto/sha256"
@ -13,6 +13,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -43,7 +44,7 @@ func ensureLinuxkitImage(name, cache string) error {
yaml := linuxkitYaml[name] yaml := linuxkitYaml[name]
m, err := NewConfig([]byte(yaml), nil) m, err := moby.NewConfig([]byte(yaml), nil)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,4 +1,4 @@
package moby package build
// BuildOpts options that control the linuxkit build process // BuildOpts options that control the linuxkit build process
type BuildOpts struct { type BuildOpts struct {

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"archive/tar" "archive/tar"

View File

@ -1,4 +1,4 @@
package moby package build
import ( import (
"archive/tar" "archive/tar"

View File

@ -31,6 +31,10 @@ type Moby struct {
initRefs []*reference.Spec initRefs []*reference.Spec
} }
func (m Moby) InitRefs() []*reference.Spec {
return m.initRefs
}
// KernelConfig is the type of the config for a kernel // KernelConfig is the type of the config for a kernel
type KernelConfig struct { type KernelConfig struct {
Image string `yaml:"image" json:"image"` Image string `yaml:"image" json:"image"`
@ -42,6 +46,10 @@ type KernelConfig struct {
ref *reference.Spec ref *reference.Spec
} }
func (k KernelConfig) Ref() *reference.Spec {
return k.ref
}
// File is the type of a file specification // File is the type of a file specification
type File struct { type File struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
@ -127,6 +135,10 @@ type ImageConfig struct {
ref *reference.Spec ref *reference.Spec
} }
func (i ImageConfig) Ref() *reference.Spec {
return i.ref
}
// Device specifies a device to be exposed to the container. // Device specifies a device to be exposed to the container.
type Device struct { type Device struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
@ -237,7 +249,7 @@ func extractReferences(m *Moby) error {
return nil return nil
} }
func updateImages(m *Moby) { func UpdateImages(m *Moby) {
if m.Kernel.ref != nil { if m.Kernel.ref != nil {
m.Kernel.Image = m.Kernel.ref.String() m.Kernel.Image = m.Kernel.ref.String()
} }
@ -689,7 +701,7 @@ func getAllCapabilities() []string {
var allCaps = getAllCapabilities() var allCaps = getAllCapabilities()
func idNumeric(v interface{}, idMap map[string]uint32) (uint32, error) { func IDNumeric(v interface{}, idMap map[string]uint32) (uint32, error) {
switch id := v.(type) { switch id := v.(type) {
case nil: case nil:
return uint32(0), nil return uint32(0), nil
@ -984,17 +996,17 @@ func ConfigToOCI(yaml *Image, config imagespec.ImageConfig, idMap map[string]uin
uidIf := assignInterface(label.UID, yaml.UID) uidIf := assignInterface(label.UID, yaml.UID)
gidIf := assignInterface(label.GID, yaml.GID) gidIf := assignInterface(label.GID, yaml.GID)
agIf := assignInterfaceArray(label.AdditionalGids, yaml.AdditionalGids) agIf := assignInterfaceArray(label.AdditionalGids, yaml.AdditionalGids)
uid, err := idNumeric(uidIf, idMap) uid, err := IDNumeric(uidIf, idMap)
if err != nil { if err != nil {
return oci, runtime, err return oci, runtime, err
} }
gid, err := idNumeric(gidIf, idMap) gid, err := IDNumeric(gidIf, idMap)
if err != nil { if err != nil {
return oci, runtime, err return oci, runtime, err
} }
var additionalGroups []uint32 var additionalGroups []uint32
for _, id := range agIf { for _, id := range agIf {
ag, err := idNumeric(id, idMap) ag, err := IDNumeric(id, idMap)
if err != nil { if err != nil {
return oci, runtime, err return oci, runtime, err
} }

View File

@ -0,0 +1,9 @@
package moby
const (
// PaxRecordLinuxkitSource report the package source for a specific file
PaxRecordLinuxkitSource = "LINUXKIT.source"
// PaxRecordLinuxkitLocation report the location of the file in the linuxkit.yaml
// that led to this file being in this location
PaxRecordLinuxkitLocation = "LINUXKIT.location"
)