GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: host builder can push to OCP internal registry (#3885) · knative/func@dfabe19

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkg/oci
    • pusher.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkg/oci/pusher.go‎

Copy file name to clipboardExpand all lines: pkg/oci/pusher.go
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package oci
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78
"os"
@@ -12,8 +13,10 @@ import (
1213
"github.com/google/go-containerregistry/pkg/authn"
1314
"github.com/google/go-containerregistry/pkg/name"
1415
v1 "github.com/google/go-containerregistry/pkg/v1"
16+
"github.com/google/go-containerregistry/pkg/v1/empty"
1517
"github.com/google/go-containerregistry/pkg/v1/layout"
1618
"github.com/google/go-containerregistry/pkg/v1/remote"
19+
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
1720
progress "github.com/schollz/progressbar/v3"
1821

1922
fn "knative.dev/func/pkg/functions"
@@ -181,13 +184,30 @@ func getBuildDir(f fn.Function) (string, error) {
181184
func (p *Pusher) writeIndex(ctx context.Context, ref name.Reference, ii v1.ImageIndex, creds Credentials) error {
182185
oo := []remote.Option{
183186
remote.WithContext(ctx),
184-
remote.WithProgress(p.updates),
185187
remote.WithTransport(p.transport),
186188
}
187189

188190
if !p.Anonymous {
189191
oo = append(oo, remote.WithAuth(creds))
190192
}
191193

192-
return remote.WriteIndex(ref, ii, oo...)
194+
// Ensure the repository exists. Some registries (notably
195+
// OpenShift's internal registry) return HTTP 500 for manifest
196+
// HEAD requests by digest when the repository doesn't exist yet.
197+
// WriteIndex checks child manifests by digest, so the repository
198+
// must exist beforehand. A HEAD by tag returns a proper 404, so
199+
// use that to detect the missing repository and create it by
200+
// pushing an empty image. The tag is overwritten by the index.
201+
if _, err := remote.Head(ref, oo...); err != nil {
202+
var terr *transport.Error
203+
if errors.As(err, &terr) && terr.StatusCode == http.StatusNotFound {
204+
if err := remote.Write(ref, empty.Image, oo...); err != nil {
205+
return fmt.Errorf("cannot create repo: %w", err)
206+
}
207+
} else {
208+
return fmt.Errorf("cannot check repo existence: %w", err)
209+
}
210+
}
211+
212+
return remote.WriteIndex(ref, ii, append(oo, remote.WithProgress(p.updates))...)
193213
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.