Skip to content

Commit

Permalink
pass sourceDir down to tarball writer
Browse files Browse the repository at this point in the history
  • Loading branch information
decleaver committed Feb 16, 2024
1 parent 5d8dcdd commit 113bf8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/pkg/bundle/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (b *Bundle) Create() error {
Bundle: &b.bundle,
Output: b.cfg.CreateOpts.Output,
TmpDstDir: b.tmp,
SourceDir: b.cfg.CreateOpts.SourceDirectory,
}
bundlerClient := bundler.NewBundler(&opts)
return bundlerClient.Create()
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Bundler struct {
bundle *types.UDSBundle
output string
tmpDstDir string
sourceDir string
}

type Pusher interface {
Expand All @@ -21,20 +22,22 @@ type Options struct {
Bundle *types.UDSBundle
Output string
TmpDstDir string
SourceDir string
}

func NewBundler(opts *Options) *Bundler {
b := Bundler{
bundle: opts.Bundle,
output: opts.Output,
tmpDstDir: opts.TmpDstDir,
sourceDir: opts.SourceDir,
}
return &b
}

func (b *Bundler) Create() error {
if b.output == "" {
localBundle := NewLocalBundle(&LocalBundleOpts{Bundle: b.bundle, TmpDstDir: b.tmpDstDir})
localBundle := NewLocalBundle(&LocalBundleOpts{Bundle: b.bundle, TmpDstDir: b.tmpDstDir, SourceDir: b.sourceDir})
err := localBundle.create(nil)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions src/pkg/bundler/localbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ import (
type LocalBundleOpts struct {
Bundle *types.UDSBundle
TmpDstDir string
SourceDir string
}

type LocalBundle struct {
bundle *types.UDSBundle
tmpDstDir string
sourceDir string
}

func NewLocalBundle(opts *LocalBundleOpts) *LocalBundle {
return &LocalBundle{
bundle: opts.Bundle,
tmpDstDir: opts.TmpDstDir,
sourceDir: opts.SourceDir,
}
}

Expand Down Expand Up @@ -153,7 +156,7 @@ func (lo *LocalBundle) create(signature []byte) error {
}

// tarball the bundle
err = writeTarball(bundle, artifactPathMap)
err = writeTarball(bundle, artifactPathMap, lo.sourceDir)
if err != nil {
return err
}
Expand Down Expand Up @@ -199,17 +202,14 @@ func pushManifestConfig(store *ocistore.Store, metadata types.UDSMetadata, build
}

// writeTarball builds and writes a bundle tarball to disk based on a file map
func writeTarball(bundle *types.UDSBundle, artifactPathMap types.PathMap) error {
func writeTarball(bundle *types.UDSBundle, artifactPathMap types.PathMap, sourceDir string) error {
format := archiver.CompressedArchive{
Compression: archiver.Zstd{},
Archival: archiver.Tar{},
}
filename := fmt.Sprintf("%s%s-%s-%s.tar.zst", config.BundlePrefix, bundle.Metadata.Name, bundle.Metadata.Architecture, bundle.Metadata.Version)
cwd, err := os.Getwd()
if err != nil {
return err
}
dst := filepath.Join(cwd, filename)

dst := filepath.Join(sourceDir, filename)

_ = os.RemoveAll(dst)

Expand Down

0 comments on commit 113bf8b

Please sign in to comment.