Skip to content

Commit

Permalink
improve push failure errors
Browse files Browse the repository at this point in the history
If the push fails, the registry might include additional error messages
in the body of the http response; we should include it in the error we
return to the client.

This changes an error such as

    unexpected status from PUT request to https://123456789.dkr.ecr.us-west-2.amazonaws.com/v2/integration-test/manifests/latest: 403 Forbidden

to

    unexpected status from PUT request to https://123456789.dkr.ecr.us-west-2.amazonaws.com/v2/integration-test/manifests/latest: 403 Forbidden body={"errors":[{"code":"DENIED","message":"The repository with name 'my-cool-image' in registry with id '123456789' already has the maximum allowed number of images which is '10000'"}]}

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
  • Loading branch information
alexcb committed Nov 23, 2023
1 parent b61b1c9 commit 54a4452
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exporter/earthlyoutputs/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes/docker"
remoteserrors "github.com/containerd/containerd/remotes/errors"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/idtools"
"github.com/moby/buildkit/cache"
Expand Down Expand Up @@ -555,6 +556,11 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
e.opt.ImageWriter.ContentStore(), img.mfstDesc.Digest,
imgName, img.insecurePush, e.opt.RegistryHosts, false, annotations)
if err != nil {
var errStatus remoteserrors.ErrUnexpectedStatus
if errors.As(err, &errStatus) {
// TODO body might be json, e.g. `{"errors":[{"code":"DENIED","message":"The repository with name 'my-cool-image' in registry with id '123456789' already has the maximum allowed number of images which is '10000'"}]}`, we should attempt to parse this
return nil, nil, fmt.Errorf("failed to push %s: %w body=%s", imgName, errStatus, errStatus.Body)
}
return nil, nil, err
}
}
Expand Down

0 comments on commit 54a4452

Please sign in to comment.