Skip to content

Commit

Permalink
Restore blind-write to remote.Put (#1970)
Browse files Browse the repository at this point in the history
* Restore blind-write to remote.Put

This used to do a blind write, but I "simplified" that when introducing
remote.Pusher, which actually broke some things downstream of ggcr, so
this restores that behavior.

Signed-off-by: Jon Johnson <[email protected]>

* Make it woke

Signed-off-by: Jon Johnson <[email protected]>

---------

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr authored Jul 8, 2024
1 parent 9915a85 commit d36047a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/crane/rebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ some compiler expected by the uppermost app layers, the resulting rebased image
might be invalid.

In general, it's a good practice to tag rebased images to some other tag than
the `original` tag, perform some sanity checks, then tag the image to the
the `original` tag, perform some confidence checks, then tag the image to the
`original` tag once it's determined the image is valid.

There is ongoing work to standardize and advertise base image contract
Expand Down
14 changes: 14 additions & 0 deletions pkg/v1/remote/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ func (p *Pusher) writer(ctx context.Context, repo name.Repository, o *options) (
return rw, rw.init(ctx)
}

func (p *Pusher) Put(ctx context.Context, ref name.Reference, t Taggable) error {
w, err := p.writer(ctx, ref.Context(), p.o)
if err != nil {
return err
}

m, err := taggableToManifest(t)
if err != nil {
return err
}

return w.commitManifest(ctx, ref, m)
}

func (p *Pusher) Push(ctx context.Context, ref name.Reference, t Taggable) error {
w, err := p.writer(ctx, ref.Context(), p.o)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,5 +709,5 @@ func Put(ref name.Reference, t Taggable, options ...Option) error {
if err != nil {
return err
}
return newPusher(o).Push(o.context, ref, t)
return newPusher(o).Put(o.context, ref, t)
}
24 changes: 12 additions & 12 deletions pkg/v1/remote/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ func TestScopesForUploadingImage(t *testing.T) {
if err != nil {
t.Fatalf("img.Layers() = %v", err)
}
dummyLayer := layers[0]
wokeLayer := layers[0]

testCases := []struct {
name string
Expand All @@ -1122,7 +1122,7 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: sameReference,
},
},
Expand All @@ -1135,7 +1135,7 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
},
Expand All @@ -1149,11 +1149,11 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
},
Expand All @@ -1167,11 +1167,11 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo2,
},
},
Expand All @@ -1186,19 +1186,19 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo2,
},
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo1,
},
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: anotherRepo2,
},
},
Expand All @@ -1213,7 +1213,7 @@ func TestScopesForUploadingImage(t *testing.T) {
reference: referenceToUpload,
layers: []v1.Layer{
&MountableLayer{
Layer: dummyLayer,
Layer: wokeLayer,
Reference: repoOnOtherRegistry,
},
},
Expand Down

0 comments on commit d36047a

Please sign in to comment.