Skip to content

Commit 552a0cc

Browse files
authored
Fast Push Fixes (#2133)
* Allow StatusCreated to indicate accepted upload * Add User-Agent to cog push headers * Use auto region in S3 config
1 parent ecbe178 commit 552a0cc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/docker/fast_push.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ type VerificationStatus struct {
4949
Complete bool `json:"complete"`
5050
}
5151

52+
func userAgent() string {
53+
return fmt.Sprintf("Cog/%s", global.Version)
54+
}
55+
5256
func FastPush(ctx context.Context, image string, projectDir string, command Command) error {
5357
g, _ := errgroup.WithContext(ctx)
5458

@@ -193,6 +197,7 @@ func uploadFile(ctx context.Context, objectType string, digest string, path stri
193197
return err
194198
}
195199
req.Header.Set("Authorization", "Bearer "+token)
200+
req.Header.Set("User-Agent", userAgent())
196201
resp, err := client.Do(req)
197202
if err != nil {
198203
return err
@@ -202,7 +207,7 @@ func uploadFile(ctx context.Context, objectType string, digest string, path stri
202207
// A conflict means we have already uploaded this file.
203208
if resp.StatusCode == http.StatusConflict {
204209
return nil
205-
} else if resp.StatusCode != http.StatusOK {
210+
} else if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
206211
return errors.New("Bad response: " + strconv.Itoa(resp.StatusCode))
207212
}
208213

@@ -225,6 +230,7 @@ func uploadFile(ctx context.Context, objectType string, digest string, path stri
225230
console.Debug("multi-part uploading file: " + path)
226231
cfg := aws.NewConfig()
227232
cfg.BaseEndpoint = &data.Endpoint
233+
cfg.Region = "auto"
228234
cfg.Credentials = credentials.StaticCredentialsProvider{
229235
Value: aws.Credentials{
230236
AccessKeyID: data.AccessKeyId,
@@ -255,6 +261,7 @@ func uploadFile(ctx context.Context, objectType string, digest string, path stri
255261
return err
256262
}
257263
req.Header.Set("Authorization", "Bearer "+token)
264+
req.Header.Set("User-Agent", userAgent())
258265
beginResp, err := client.Do(req)
259266
if err != nil {
260267
return err
@@ -270,6 +277,7 @@ func uploadFile(ctx context.Context, objectType string, digest string, path stri
270277
return err
271278
}
272279
req.Header.Set("Authorization", "Bearer "+token)
280+
req.Header.Set("User-Agent", userAgent())
273281
for i := 0; i < 100; i++ {
274282
final, err := checkVerificationStatus(req, client)
275283
if final {

0 commit comments

Comments
 (0)