Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
9f944c00
Commit
9f944c00
authored
Aug 16, 2023
by
Michael Yang
Browse files
push: retry on unauthorized
parent
56e87cec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
server/images.go
server/images.go
+23
-2
No files found.
server/images.go
View file @
9f944c00
...
@@ -1106,7 +1106,11 @@ func GetSHA256Digest(r io.Reader) (string, int) {
...
@@ -1106,7 +1106,11 @@ func GetSHA256Digest(r io.Reader) (string, int) {
return
fmt
.
Sprintf
(
"sha256:%x"
,
h
.
Sum
(
nil
)),
int
(
n
)
return
fmt
.
Sprintf
(
"sha256:%x"
,
h
.
Sum
(
nil
)),
int
(
n
)
}
}
type
requestContextKey
string
func
startUpload
(
ctx
context
.
Context
,
mp
ModelPath
,
layer
*
Layer
,
regOpts
*
RegistryOptions
)
(
string
,
error
)
{
func
startUpload
(
ctx
context
.
Context
,
mp
ModelPath
,
layer
*
Layer
,
regOpts
*
RegistryOptions
)
(
string
,
error
)
{
retry
,
_
:=
ctx
.
Value
(
requestContextKey
(
"retry"
))
.
(
int
)
url
:=
fmt
.
Sprintf
(
"%s/v2/%s/blobs/uploads/"
,
mp
.
Registry
,
mp
.
GetNamespaceRepository
())
url
:=
fmt
.
Sprintf
(
"%s/v2/%s/blobs/uploads/"
,
mp
.
Registry
,
mp
.
GetNamespaceRepository
())
if
layer
.
From
!=
""
{
if
layer
.
From
!=
""
{
url
=
fmt
.
Sprintf
(
"%s/v2/%s/blobs/uploads/?mount=%s&from=%s"
,
mp
.
Registry
,
mp
.
GetNamespaceRepository
(),
layer
.
Digest
,
layer
.
From
)
url
=
fmt
.
Sprintf
(
"%s/v2/%s/blobs/uploads/?mount=%s&from=%s"
,
mp
.
Registry
,
mp
.
GetNamespaceRepository
(),
layer
.
Digest
,
layer
.
From
)
...
@@ -1119,8 +1123,25 @@ func startUpload(ctx context.Context, mp ModelPath, layer *Layer, regOpts *Regis
...
@@ -1119,8 +1123,25 @@ func startUpload(ctx context.Context, mp ModelPath, layer *Layer, regOpts *Regis
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
// Check for success
switch
resp
.
StatusCode
{
if
resp
.
StatusCode
!=
http
.
StatusAccepted
&&
resp
.
StatusCode
!=
http
.
StatusCreated
{
case
http
.
StatusAccepted
,
http
.
StatusCreated
:
// noop
case
http
.
StatusUnauthorized
:
if
retry
>
MaxRetries
{
return
""
,
fmt
.
Errorf
(
"max retries exceeded: %s"
,
resp
.
Status
)
}
auth
:=
resp
.
Header
.
Get
(
"www-authenticate"
)
authRedir
:=
ParseAuthRedirectString
(
auth
)
token
,
err
:=
getAuthToken
(
ctx
,
authRedir
,
regOpts
)
if
err
!=
nil
{
return
""
,
err
}
regOpts
.
Token
=
token
ctx
=
context
.
WithValue
(
ctx
,
requestContextKey
(
"retry"
),
retry
+
1
)
return
startUpload
(
ctx
,
mp
,
layer
,
regOpts
)
default
:
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
""
,
fmt
.
Errorf
(
"on upload registry responded with code %d: %s"
,
resp
.
StatusCode
,
body
)
return
""
,
fmt
.
Errorf
(
"on upload registry responded with code %d: %s"
,
resp
.
StatusCode
,
body
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment