Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
rchincha committed Jun 27, 2024
1 parent 5cf9fe0 commit 480d32c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@ require (
)

replace (
github.com/opencontainers/umoci => github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f
github.com/opencontainers/umoci => github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c
stackerbuild.io/stacker-bom => github.com/project-stacker/stacker-bom v0.0.0-20240509203427-4d685e046780
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f h1:kb6KNqJtAu7bF//luRE42U3ySX79bn0iO+5FVXuEnLo=
github.com/rchincha/umoci v0.0.0-20240626041051-8a70aa6ab09f/go.mod h1:XUXUpCpA/Y8aJWezK1i8o4WDR0Y/vhMcWg+FUNQkKMQ=
github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c h1:aqbiVMze/TB97xVPAbuu1ryhEK7bKhCU3LAQmT8Pnkw=
github.com/rchincha/umoci v0.0.0-20240626163940-d5817dc92d4c/go.mod h1:XUXUpCpA/Y8aJWezK1i8o4WDR0Y/vhMcWg+FUNQkKMQ=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
3 changes: 3 additions & 0 deletions pkg/overlay/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package overlay
import (
"bytes"
"encoding/json"
"fmt"
"io/fs"
"os"
"path"
Expand Down Expand Up @@ -91,6 +92,8 @@ func (ovl overlayMetadata) write(config types.StackerConfig, tag string) error {
return errors.Wrapf(err, "couldn't write overlay metadata %s", metadataFile)
}

fmt.Printf("OVL_WRITE:%s %s\n", tag, string(content))

return nil
}

Expand Down
35 changes: 28 additions & 7 deletions pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func ConvertAndOutput(config types.StackerConfig, tag, name string, layerType ty
newConfig := imageConfig
newConfig.RootFS.DiffIDs = []digest.Digest{}

fmt.Printf("MANIFEST LAYERS: %v\n", manifest.Layers)

for _, theLayer := range manifest.Layers {
bundlePath := overlayPath(config.RootFSDir, theLayer.Digest)
overlayDir := path.Join(bundlePath, "overlay")
Expand Down Expand Up @@ -283,13 +285,13 @@ func (o *overlay) initializeBasesInOutput(name string, layerTypes []types.LayerT
return nil
}

func (o *overlay) Repack(name string, layerTypes []types.LayerType, sfm types.StackerFiles) error {
func (o *overlay) Repack(name string, layer types.Layer, layerTypes []types.LayerType, sfm types.StackerFiles) error {
err := o.initializeBasesInOutput(name, layerTypes, sfm)
if err != nil {
return err
}

return repackOverlay(o.config, name, layerTypes)
return repackOverlay(o.config, name, layer, layerTypes)
}

// generateBlob generates either a tar blob or a squashfs blob based on layerType
Expand Down Expand Up @@ -382,7 +384,9 @@ func stripOverlayAttrsUnder(dirPath string) error {
})
}

func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mutate.Mutator, name string, layerTypes []types.LayerType) (bool, error) {
func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mutate.Mutator,
name string, layer types.Layer, layerTypes []types.LayerType,
) (bool, error) {
dir := path.Join(config.RootFSDir, name, "overlay")
ents, err := os.ReadDir(dir)
if err != nil {
Expand Down Expand Up @@ -430,7 +434,12 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu
return false, err
}

ovl, err := readOverlayMetadata(config.RootFSDir, name)
var ovl overlayMetadata
if layer.From.Type != types.BuiltLayer {
ovl, err = readOverlayMetadata(config.RootFSDir, name)
} else {
ovl, err = readOverlayMetadata(config.RootFSDir, layer.From.Tag)
}
if err != nil {
return false, err
}
Expand All @@ -441,10 +450,18 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu
var desc ispec.Descriptor

lowerDirs := []string{}
for i := len(ovl.OverlayDirLayers[layerType]) - 1; i >= 0; i-- {
fmt.Printf("OD:%s %v\n", name, lowerDirs)
lowerDirs = append(lowerDirs, overlayPath(config.RootFSDir, ovl.Manifests[layerType].Layers[i].Digest))
}

for i := len(ovl.Manifests[layerType].Layers) - 1; i >= 0; i-- {
fmt.Printf("LD:%s %v\n", name, lowerDirs)
lowerDirs = append(lowerDirs, overlayPath(config.RootFSDir, ovl.Manifests[layerType].Layers[i].Digest))
}

fmt.Printf("LAYER:%s %v %v\n", name, ovl, lowerDirs)

blob, mediaType, rootHash, err := generateBlob(layerType, dir, config.OCIDir, lowerDirs)
if err != nil {
return false, err
Expand Down Expand Up @@ -557,7 +574,7 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu
return true, nil
}

func repackOverlay(config types.StackerConfig, name string, layerTypes []types.LayerType) error {
func repackOverlay(config types.StackerConfig, name string, layer types.Layer, layerTypes []types.LayerType) error {
oci, err := umoci.OpenLayout(config.OCIDir)
if err != nil {
return err
Expand All @@ -569,6 +586,8 @@ func repackOverlay(config types.StackerConfig, name string, layerTypes []types.L
return err
}

fmt.Printf("REPACK:%s %v\n", name, ovl)

mutators := []*mutate.Mutator{}

for _, layerType := range layerTypes {
Expand Down Expand Up @@ -609,10 +628,12 @@ func repackOverlay(config types.StackerConfig, name string, layerTypes []types.L
}
}

fmt.Printf("OVL BUILTLAYERS:%s %v\n", name, ovl)

// generate blobs for each build layer
for _, buildLayer := range ovl.BuiltLayers {

didMutate, err := generateLayer(config, oci, mutators, buildLayer, layerTypes)
didMutate, err := generateLayer(config, oci, mutators, buildLayer, layer, layerTypes)
if err != nil {
return err
}
Expand Down Expand Up @@ -647,7 +668,7 @@ func repackOverlay(config types.StackerConfig, name string, layerTypes []types.L
return err
}

didMutate, err := generateLayer(config, oci, mutators, name, layerTypes)
didMutate, err := generateLayer(config, oci, mutators, name, layer, layerTypes)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (b *Builder) build(s types.Storage, file string) error {
continue
}

err = s.Repack(name, opts.LayerTypes, b.builtStackerfiles)
err = s.Repack(name, l, opts.LayerTypes, b.builtStackerfiles)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Storage interface {
Unpack(tag, name string) error

// Repack repacks the specified working dir into the specified OCI dir.
Repack(name string, layerTypes []LayerType, sfm StackerFiles) error
Repack(name string, layer Layer, layerTypes []LayerType, sfm StackerFiles) error

// GetLXCRootfsConfig returns the string that should be set as
// lxc.rootfs.path in the LXC container's config.
Expand Down

0 comments on commit 480d32c

Please sign in to comment.