Skip to content

Commit

Permalink
Delete a bunch of dead code (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored Sep 15, 2024
1 parent 83e270e commit 78662f8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 107 deletions.
20 changes: 0 additions & 20 deletions internal/cli/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"golang.org/x/sync/errgroup"

"github.com/chainguard-dev/clog"

Expand Down Expand Up @@ -184,7 +183,6 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
var (
local = opts.local
tags = opts.tags
additionalTags []string
wantSBOM = len(sboms) > 0 // it only generates sboms if wantSbom was true
builtReferences = make([]string, 0)
)
Expand Down Expand Up @@ -230,24 +228,6 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
}
}

// TODO: Why does this happen separately from PublishIndex?
skipLocalCopy := strings.HasPrefix(finalDigest.Name(), fmt.Sprintf("%s/", oci.LocalDomain))
g, ctx := errgroup.WithContext(ctx)
for _, at := range additionalTags {
at := at
if skipLocalCopy {
// TODO: We probably don't need this now that we return early.
log.Warnf("skipping local domain tag %s", at)
continue
}
g.Go(func() error {
return oci.Copy(ctx, finalDigest.Name(), at, ropt...)
})
}
if err := g.Wait(); err != nil {
return err
}

// publish each arch-specific sbom
// publish the index sbom
if wantSBOM {
Expand Down
87 changes: 0 additions & 87 deletions pkg/build/oci/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,6 @@ import (
"github.com/chainguard-dev/clog"
)

// PublishImage publishes an image to a registry.
// `local` determines if it should push to the local docker daemon or to the actual registry.
// `shouldPushTags` determines whether to push the tags provided in the `tags` parameter, or whether
// to treat the first tag as a digest and push that instead.
func PublishImage(ctx context.Context, image oci.SignedImage, shouldPushTags bool, tags []string, remoteOpts ...remote.Option) (name.Digest, error) {
log := clog.FromContext(ctx)
ref, err := name.ParseReference(tags[0])
if err != nil {
return name.Digest{}, fmt.Errorf("parsing tag %q: %w", tags[0], err)
}

hash, err := image.Digest()
if err != nil {
return name.Digest{}, fmt.Errorf("failed to compute digest: %w", err)
}

dig := ref.Context().Digest(hash.String())

toPublish := tags
msg := "publish image tag"

if !shouldPushTags {
toPublish = []string{dig.String()}
msg = "publishing image without tag (digest only)"
}

g, ctx := errgroup.WithContext(ctx)
for _, tag := range toPublish {
tag := tag
g.Go(func() error {
log.Infof("%s %v", msg, tag)
ref, err := name.ParseReference(tag)
if err != nil {
return fmt.Errorf("unable to parse reference: %w", err)
}

// Write any attached SBOMs/signatures.
wp := writePeripherals(ctx, ref, remoteOpts...)
g.Go(func() error {
return wp(ctx, image)
})

g.Go(func() error {
return remote.Write(ref, image, remoteOpts...)
})

return nil
})
}

if err := g.Wait(); err != nil {
return name.Digest{}, fmt.Errorf("failed to publish: %w", err)
}

return dig, nil
}

func LoadImage(ctx context.Context, image oci.SignedImage, tags []string) (name.Reference, error) {
log := clog.FromContext(ctx)
hash, err := image.Digest()
Expand Down Expand Up @@ -322,33 +265,3 @@ func writePeripherals(ctx context.Context, tag name.Reference, opt ...remote.Opt
return nil
}
}

// Copt copies an image from one registry repository to another.
func Copy(ctx context.Context, src, dst string, remoteOpts ...remote.Option) error {
log := clog.FromContext(ctx)
ctx, span := otel.Tracer("apko").Start(ctx, "oci.Copy")
defer span.End()

log.Infof("Copying %s to %s", src, dst)
srcRef, err := name.ParseReference(src)
if err != nil {
return err
}
dstRef, err := name.ParseReference(dst)
if err != nil {
return err
}
desc, err := remote.Get(srcRef, remoteOpts...)
if err != nil {
return fmt.Errorf("fetching %s: %w", src, err)
}
pusher, err := remote.NewPusher(remoteOpts...)
if err != nil {
return err
}
if err := pusher.Push(ctx, dstRef, desc); err != nil {
return fmt.Errorf("tagging %s with tag %s: %w", src, dst, err)
}

return nil
}

0 comments on commit 78662f8

Please sign in to comment.