diff --git a/internal/cli/publish.go b/internal/cli/publish.go index 24017233e..3748b7769 100644 --- a/internal/cli/publish.go +++ b/internal/cli/publish.go @@ -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" @@ -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) ) @@ -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 { diff --git a/pkg/build/oci/publish.go b/pkg/build/oci/publish.go index 0f6f500ad..bfec28954 100644 --- a/pkg/build/oci/publish.go +++ b/pkg/build/oci/publish.go @@ -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() @@ -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 -}