Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Sep 15, 2023
1 parent ac736f6 commit 4181d17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
37 changes: 28 additions & 9 deletions oci/artefact.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func newArtifcatInfoFromLayerDescriptor(image v1.Image, layerDecriptor v1.Descri
}

func (c *Client) getArtefactLayers(ctx context.Context, ref string) (v1.Image, []v1.Descriptor, error) {
// tag, err := name.ParseReference(ref)
// if err != nil {
// return nil, nil, fmt.Errorf("invalid URL: %w", err)
// }

// index, err := remote.Index(tag, crane.GetOptions(c.artefactPushAndPullOptions(ctx)...).Remote...)
// if err != nil {
// return nil, nil, fmt.Errorf("failed to get index of %q: %w", ref, err)
// }

image, err := c.Pull(ctx, ref)
if err != nil {
return nil, nil, fmt.Errorf("failed to pull %q: %w", ref, err)
Expand Down Expand Up @@ -207,7 +217,12 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
}

index = mutate.AppendManifests(index,
mutate.IndexAddendum{Add: config},
mutate.IndexAddendum{
Descriptor: v1.Descriptor{
Platform: platform(),
},
Add: config,
},
)

if attestLayer != nil {
Expand All @@ -233,7 +248,12 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
}

index = mutate.AppendManifests(index,
mutate.IndexAddendum{Add: attest},
mutate.IndexAddendum{
Descriptor: v1.Descriptor{
Platform: platform(),
},
Add: attest,
},
)
}

Expand All @@ -242,19 +262,18 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
return "", fmt.Errorf("parsing index digest failed: %w", err)
}

if err := remote.WriteIndex(tag, index, crane.GetOptions(c.artefactPushOptions(ctx)...).Remote...); err != nil {
if err := remote.WriteIndex(tag, index, crane.GetOptions(c.withContext(ctx)...).Remote...); err != nil {
return "", fmt.Errorf("pushing index failed: %w", err)
}

return ref + "@" + digest.String(), err
}

func (c *Client) artefactPushOptions(ctx context.Context) []crane.Option {
return append(c.withContext(ctx),
crane.WithPlatform(&v1.Platform{
Architecture: "unknown",
OS: "unknown",
}))
func platform() *v1.Platform {
return &v1.Platform{
Architecture: "unknown",
OS: "unknown",
}
}

// based on https://github.com/fluxcd/pkg/blob/2a323d771e17af02dee2ccbbb9b445b78ab048e5/oci/client/build.go
Expand Down
10 changes: 9 additions & 1 deletion tape/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ func Run() int {
},
{
name: "package",
short: "Create a package",
short: "Package an artefact",
long: []string{
"This command process manifests from the given dir and packages them as an artefact",
},
options: &TapePackageCommand{
tape: tape,
InputManifestDirOptions: InputManifestDirOptions{}},
},
{
name: "pull",
short: "Pull an artefact",
options: &TapePullCommand{
tape: tape,
OutputManifestDirOptions: OutputManifestDirOptions{},
},
},
}

for _, c := range commands {
Expand Down

0 comments on commit 4181d17

Please sign in to comment.