Skip to content

Commit

Permalink
fixing ALLLL the bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed Sep 7, 2023
1 parent 17a1cf6 commit 28bb38b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
26 changes: 24 additions & 2 deletions src/pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,32 @@ func Create(b *Bundler, signature []byte) error {
if err := store.Push(ctx, manifestDesc, bytes.NewReader(manifestBytes)); err != nil {
return err
}

// build index.json
digest = manifestDesc.Digest.Encoded()
artifactPathMap[filepath.Join(b.tmp, config.BlobsDir, digest)] = filepath.Join(config.BlobsDir, digest)

// rebuild index.json
indexBytes, err := os.ReadFile(filepath.Join(b.tmp, "index.json"))
if err != nil {
return err
}
var index ocispec.Index
if err := json.Unmarshal(indexBytes, &index); err != nil {
return err
}
index.Manifests = []ocispec.Descriptor{manifestDesc} // use only the bundle-level manifest for index.json
bundleIndexBytes, err := json.Marshal(index)
if err != nil {
return err
}
indexFile, err := os.Create(filepath.Join(b.tmp, "index.json"))
if err != nil {
return err
}
defer indexFile.Close()
_, err = indexFile.Write(bundleIndexBytes)
if err != nil {
return err
}
artifactPathMap[filepath.Join(b.tmp, "index.json")] = "index.json"

// grab oci-layout
Expand Down
5 changes: 2 additions & 3 deletions src/pkg/bundle/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (b *Bundler) Publish() error {
}

// create new OCI artifact in remote
// localhost:888/init:v0.29.0-arm64 <- create this
ociURL := b.cfg.PublishOpts.Destination
bundleName := b.bundle.Metadata.Name
bundleTag := b.bundle.Metadata.Version
Expand All @@ -49,8 +48,8 @@ func (b *Bundler) Publish() error {
if err != nil {
return err
}

err = provider.PublishBundle(b.bundle, remote) // todo: use url string instead of remote, do the oci.NewOrasRemote inside this fn
// todo: add some pretty TUI progress bars for publish and some logging for when it's done
err = provider.PublishBundle(b.bundle, remote)
if err != nil {
return err
}
Expand Down
11 changes: 4 additions & 7 deletions src/pkg/bundler/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (b *LocalBundler) ToBundle(bundleStore *ocistore.Store, pkg zarfTypes.ZarfP
return ocispec.Descriptor{}, err
}
// push the manifest
rootManifest, err := generatePackManifest(bundleStore, descs, manifestConfigDesc, &pkg.Metadata)
rootManifest, err := generatePkgManifest(bundleStore, descs, manifestConfigDesc, &pkg.Metadata)

if err != nil {
return ocispec.Descriptor{}, err
Expand Down Expand Up @@ -198,7 +198,7 @@ func pushZarfManifestConfigFromMetadata(store *ocistore.Store, metadata *zarfTyp
return manifestConfigDesc, err
}

func generatePackManifest(store *ocistore.Store, descs []ocispec.Descriptor, configDesc ocispec.Descriptor, metadata *zarfTypes.ZarfMetadata) (ocispec.Descriptor, error) {
func generatePkgManifest(store *ocistore.Store, descs []ocispec.Descriptor, configDesc ocispec.Descriptor, metadata *zarfTypes.ZarfMetadata) (ocispec.Descriptor, error) {

Check warning on line 201 in src/pkg/bundler/tarball.go

View workflow job for this annotation

GitHub Actions / validate

parameter 'metadata' seems to be unused, consider removing or renaming it as _
ctx := context.TODO()

// adopted from oras.Pack fn
Expand All @@ -215,15 +215,12 @@ func generatePackManifest(store *ocistore.Store, descs []ocispec.Descriptor, con
if err != nil {
return ocispec.Descriptor{}, fmt.Errorf("failed to marshal manifest: %w", err)
}
manifestDesc := content.NewDescriptorFromBytes(oci.ZarfLayerMediaTypeBlob, manifestJSON)
//manifestDesc := content.NewDescriptorFromBytes(oci.ZarfLayerMediaTypeBlob, manifestJSON)
manifestDesc := content.NewDescriptorFromBytes(ocispec.MediaTypeImageManifest, manifestJSON)

// push manifest
if err := store.Push(ctx, manifestDesc, bytes.NewReader(manifestJSON)); err != nil {
return ocispec.Descriptor{}, err
}

// hack media type back to Zarf blob to put in bundle manifest
manifestDesc.MediaType = oci.ZarfLayerMediaTypeBlob

return manifestDesc, nil
}

0 comments on commit 28bb38b

Please sign in to comment.