-
Notifications
You must be signed in to change notification settings - Fork 692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add retry_count to container_push #2101
base: master
Are you sure you want to change the base?
Changes from 1 commit
dc9b470
43f6d3f
ddd6949
5a1f982
5e5bec0
4e54051
4c2fffe
f63e72a
776c2d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,6 +44,7 @@ var ( | |||||
format = flag.String("format", "", "The format of the uploaded image (Docker or OCI).") | ||||||
clientConfigDir = flag.String("client-config-dir", "", "The path to the directory where the client configuration files are located. Overiddes the value from DOCKER_CONFIG.") | ||||||
skipUnchangedDigest = flag.Bool("skip-unchanged-digest", false, "If set to true, will only push images where the digest has changed.") | ||||||
retryCount = flag.Int("retry-count", 0, "Amount of times the push will be retried.") | ||||||
layers utils.ArrayStringFlags | ||||||
stampInfoFile utils.ArrayStringFlags | ||||||
) | ||||||
|
@@ -126,8 +127,17 @@ func main() { | |||||
log.Printf("Failed to digest image: %v", err) | ||||||
} | ||||||
|
||||||
if err := push(stamped, img); err != nil { | ||||||
log.Fatalf("Error pushing image to %s: %v", stamped, err) | ||||||
for retry := 0; retry < *retryCount+1; retry++ { | ||||||
err := push(stamped, img) | ||||||
if err == nil { | ||||||
break | ||||||
} | ||||||
|
||||||
if *retryCount > 0 && retry < *retryCount { | ||||||
log.Printf("Failed to push image on attempt %d: %v", retry+1, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error is missing the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense! Pushed that change. |
||||||
} else { | ||||||
log.Fatalf("Error pushing image to %s: %v", stamped, err) | ||||||
} | ||||||
uhthomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
digestStr := "" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,9 @@ def _impl(ctx): | |
tag = tag, | ||
)) | ||
|
||
if ctx.attr.retry_count > 0: | ||
pusher_args.append("-retry-count={}".format(ctx.attr.retry_count)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there should be some validation here? Might be confusing if a user provides -1 and nothing happens. I think we can merge given this change. |
||
|
||
if ctx.attr.skip_unchanged_digest: | ||
pusher_args.append("-skip-unchanged-digest") | ||
digester_args += ["--dst", str(ctx.outputs.digest.path), "--format", str(ctx.attr.format)] | ||
|
@@ -168,6 +171,9 @@ container_push_ = rule( | |
allow_single_file = True, | ||
doc = "The label of the file with repository value. Overrides 'repository'.", | ||
), | ||
"retry_count": attr.int( | ||
doc = "Number of times to retry pushing the image.", | ||
), | ||
"skip_unchanged_digest": attr.bool( | ||
default = False, | ||
doc = "Check if the container registry already contain the image's digest. If yes, skip the push for that image. " + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we validate this value? What happens when the retry count is
-1
? Some users may assume this to mean infinite retries, when in fact the container image would not even attempt to be pushed once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Do you think it's better to log using
log.Fatalln
if it's negative or set it to0
and log a warning instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a version that exits with
Fatalln
as that matches the other validation behaviour.