diff --git a/pkg/docker/push.go b/pkg/docker/push.go index b6386d43d5..7fcd93fc63 100644 --- a/pkg/docker/push.go +++ b/pkg/docker/push.go @@ -30,6 +30,10 @@ func Push(image string, fast bool, projectDir string, command command.Command, b if fast { monobeamClient := monobeam.NewClient(client) + if err := monobeamClient.PostPreUpload(ctx); err != nil { + // The pre upload is not required, just helpful. If it fails, log and continue + console.Debugf("Failed to POST pre_upload: %v", err) + } return FastPush(ctx, image, projectDir, command, webClient, monobeamClient) } return StandardPush(image, command) diff --git a/pkg/monobeam/client.go b/pkg/monobeam/client.go index a6fa85c7e7..ecfe0acd18 100644 --- a/pkg/monobeam/client.go +++ b/pkg/monobeam/client.go @@ -17,10 +17,15 @@ import ( "github.com/vbauerster/mpb/v8" "github.com/replicate/cog/pkg/env" + "github.com/replicate/cog/pkg/util" "github.com/replicate/cog/pkg/util/console" "github.com/replicate/cog/tools/uploader" ) +const ( + preUploadPath = "/pre_upload" +) + type Client struct { client *http.Client } @@ -47,6 +52,20 @@ func NewClient(client *http.Client) *Client { } } +func (c *Client) PostPreUpload(ctx context.Context) error { + preUploadUrl := baseURL() + preUploadUrl.Path = preUploadPath + req, err := http.NewRequestWithContext(ctx, http.MethodPost, preUploadUrl.String(), nil) + if err != nil { + return util.WrapError(err, "create request") + } + _, err = c.client.Do(req) + if err != nil { + return util.WrapError(err, "do request") + } + return nil +} + func (c *Client) UploadFile(ctx context.Context, objectType string, digest string, path string, p *mpb.Progress, desc string) error { console.Debug("uploading file: " + path)