mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
Merge pull request #3753 from deitch/rationalize-args
replace Build many args with opts struct
This commit is contained in:
commit
1df038e1b0
@ -204,7 +204,7 @@ func build(args []string) {
|
||||
if moby.Streamable(buildFormats[0]) {
|
||||
tp = buildFormats[0]
|
||||
}
|
||||
err = moby.Build(m, w, *buildPull, tp, *buildDecompressKernel, cacheDir, *buildDocker, *buildArch)
|
||||
err = moby.Build(m, w, moby.BuildOpts{Pull: *buildPull, BuilderType: tp, DecompressKernel: *buildDecompressKernel, CacheDir: cacheDir, DockerCache: *buildDocker, Arch: *buildArch})
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
|
@ -83,14 +83,14 @@ func OutputTypes() []string {
|
||||
return ts
|
||||
}
|
||||
|
||||
func outputImage(image *Image, section string, prefix string, m Moby, idMap map[string]uint32, dupMap map[string]string, pull bool, iw *tar.Writer, cacheDir string, dockerCache bool, arch string) error {
|
||||
func outputImage(image *Image, section string, prefix string, m Moby, idMap map[string]uint32, dupMap map[string]string, iw *tar.Writer, opts BuildOpts) error {
|
||||
log.Infof(" Create OCI config for %s", image.Image)
|
||||
imageName := util.ReferenceExpand(image.Image)
|
||||
ref, err := reference.Parse(imageName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not resolve references for image %s: %v", image.Image, err)
|
||||
}
|
||||
src, err := imagePull(&ref, pull, cacheDir, dockerCache, arch)
|
||||
src, err := imagePull(&ref, opts.Pull, opts.CacheDir, opts.DockerCache, opts.Arch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not pull image %s: %v", image.Image, err)
|
||||
}
|
||||
@ -108,7 +108,7 @@ func outputImage(image *Image, section string, prefix string, m Moby, idMap map[
|
||||
}
|
||||
path := path.Join("containers", section, prefix+image.Name)
|
||||
readonly := oci.Root.Readonly
|
||||
err = ImageBundle(path, image.ref, config, runtime, iw, pull, readonly, dupMap, cacheDir, dockerCache, arch)
|
||||
err = ImageBundle(path, image.ref, config, runtime, iw, readonly, dupMap, opts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to extract root filesystem for %s: %v", image.Image, err)
|
||||
}
|
||||
@ -116,7 +116,7 @@ func outputImage(image *Image, section string, prefix string, m Moby, idMap map[
|
||||
}
|
||||
|
||||
// Build performs the actual build process
|
||||
func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cacheDir string, dockerCache bool, arch string) error {
|
||||
func Build(m Moby, w io.Writer, opts BuildOpts) error {
|
||||
if MobyDir == "" {
|
||||
MobyDir = defaultMobyConfigDir()
|
||||
}
|
||||
@ -129,7 +129,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
iw := tar.NewWriter(w)
|
||||
|
||||
// add additions
|
||||
addition := additions[tp]
|
||||
addition := additions[opts.BuilderType]
|
||||
|
||||
// allocate each container a uid, gid that can be referenced by name
|
||||
idMap := map[string]uint32{}
|
||||
@ -153,8 +153,8 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
if m.Kernel.ref != nil {
|
||||
// get kernel and initrd tarball and ucode cpio archive from container
|
||||
log.Infof("Extract kernel image: %s", m.Kernel.ref)
|
||||
kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode, decompressKernel)
|
||||
err := ImageTar(m.Kernel.ref, "", kf, pull, "", cacheDir, dockerCache, arch)
|
||||
kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode, opts.DecompressKernel)
|
||||
err := ImageTar(m.Kernel.ref, "", kf, "", opts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to extract kernel image and tarball: %v", err)
|
||||
}
|
||||
@ -170,7 +170,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
}
|
||||
for _, ii := range m.initRefs {
|
||||
log.Infof("Process init image: %s", ii)
|
||||
err := ImageTar(ii, "", iw, pull, resolvconfSymlink, cacheDir, dockerCache, arch)
|
||||
err := ImageTar(ii, "", iw, resolvconfSymlink, opts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to build init tarball from %s: %v", ii, err)
|
||||
}
|
||||
@ -181,7 +181,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
}
|
||||
for i, image := range m.Onboot {
|
||||
so := fmt.Sprintf("%03d", i)
|
||||
if err := outputImage(image, "onboot", so+"-", m, idMap, dupMap, pull, iw, cacheDir, dockerCache, arch); err != nil {
|
||||
if err := outputImage(image, "onboot", so+"-", m, idMap, dupMap, iw, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
}
|
||||
for i, image := range m.Onshutdown {
|
||||
so := fmt.Sprintf("%03d", i)
|
||||
if err := outputImage(image, "onshutdown", so+"-", m, idMap, dupMap, pull, iw, cacheDir, dockerCache, arch); err != nil {
|
||||
if err := outputImage(image, "onshutdown", so+"-", m, idMap, dupMap, iw, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -200,7 +200,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool, cac
|
||||
log.Infof("Add service containers:")
|
||||
}
|
||||
for _, image := range m.Services {
|
||||
if err := outputImage(image, "services", "", m, idMap, dupMap, pull, iw, cacheDir, dockerCache, arch); err != nil {
|
||||
if err := outputImage(image, "services", "", m, idMap, dupMap, iw, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ func tarPrefix(path string, tw tarWriter) error {
|
||||
}
|
||||
|
||||
// ImageTar takes a Docker image and outputs it to a tar stream
|
||||
func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, pull bool, resolv, cacheDir string, dockerCache bool, architecture string) (e error) {
|
||||
func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, resolv string, opts BuildOpts) (e error) {
|
||||
log.Debugf("image tar: %s %s", ref, prefix)
|
||||
if prefix != "" && prefix[len(prefix)-1] != '/' {
|
||||
return fmt.Errorf("prefix does not end with /: %s", prefix)
|
||||
@ -185,7 +185,7 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, pull bool, resol
|
||||
|
||||
// pullImage first checks in the cache, then pulls the image.
|
||||
// If pull==true, then it always tries to pull from registry.
|
||||
src, err := imagePull(ref, pull, cacheDir, dockerCache, architecture)
|
||||
src, err := imagePull(ref, opts.Pull, opts.CacheDir, opts.DockerCache, opts.Arch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not pull image %s: %v", ref, err)
|
||||
}
|
||||
@ -318,7 +318,7 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, pull bool, resol
|
||||
}
|
||||
|
||||
// ImageBundle produces an OCI bundle at the given path in a tarball, given an image and a config.json
|
||||
func ImageBundle(prefix string, ref *reference.Spec, config []byte, runtime Runtime, tw tarWriter, pull bool, readonly bool, dupMap map[string]string, cacheDir string, dockerCache bool, architecture string) error { // nolint: lll
|
||||
func ImageBundle(prefix string, ref *reference.Spec, config []byte, runtime 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
|
||||
rootExtract := "rootfs"
|
||||
if !readonly {
|
||||
@ -329,7 +329,7 @@ func ImageBundle(prefix string, ref *reference.Spec, config []byte, runtime Runt
|
||||
root := path.Join(prefix, rootExtract)
|
||||
var foundElsewhere = dupMap[ref.String()] != ""
|
||||
if !foundElsewhere {
|
||||
if err := ImageTar(ref, root+"/", tw, pull, "", cacheDir, dockerCache, architecture); err != nil {
|
||||
if err := ImageTar(ref, root+"/", tw, "", opts); err != nil {
|
||||
return err
|
||||
}
|
||||
dupMap[ref.String()] = root
|
||||
|
@ -57,7 +57,7 @@ func ensureLinuxkitImage(name, cache string) error {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
if err := Build(m, tf, false, "", false, cache, true, arch); err != nil {
|
||||
if err := Build(m, tf, BuildOpts{Pull: false, BuilderType: "", DecompressKernel: false, CacheDir: cache, DockerCache: true, Arch: arch}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tf.Close(); err != nil {
|
||||
|
11
src/cmd/linuxkit/moby/opts.go
Normal file
11
src/cmd/linuxkit/moby/opts.go
Normal file
@ -0,0 +1,11 @@
|
||||
package moby
|
||||
|
||||
// BuildOpts options that control the linuxkit build process
|
||||
type BuildOpts struct {
|
||||
Pull bool
|
||||
BuilderType string
|
||||
DecompressKernel bool
|
||||
CacheDir string
|
||||
DockerCache bool
|
||||
Arch string
|
||||
}
|
Loading…
Reference in New Issue
Block a user