Skip to content
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 checksum harvesting for Amazon ECR images in workflows #4376

Merged

Conversation

kathy-t
Copy link
Contributor

@kathy-t kathy-t commented Jul 30, 2021

For #4330

Uses the same checksum harvesting method as GitHub Container Registry images (idea 5 from the ticket).

Oddly enough, I ran into rate limit issues for the GET manifest endpoint if I ran the Amazon ECR test around 5 times in a row, which doesn't happen with the GHCR test. I couldn't find any rate limit documentation for Amazon ECR's support of the Docker Registry API, and the responses don't have a rate limit header. Docker's is 100 per 6 hours for anonymous calls, but I don't think this is Amazon ECR's rate limit because I haven't had to wait 6 hours to re-run the tests. The rate limit issue was sporadic. The test would some times fail but then pass when I tried it again immediately.

Got around the rate limit issue by implementing retries for the GET manifest call with exponentially back-off. In my testing, it only needed one retry to pass if there was a rate limit error.

@kathy-t kathy-t self-assigned this Jul 30, 2021
@kathy-t
Copy link
Contributor Author

kathy-t commented Jul 30, 2021

Will also need to investigate caching for public.ecr.aws in #4368. So far, I haven't seen an ETag header in the GET manifest response for public.ecr.aws so conditional requests may not be possible.

@codecov
Copy link

codecov bot commented Jul 30, 2021

Codecov Report

Merging #4376 (902ef61) into develop (8f3d735) will decrease coverage by 0.08%.
The diff coverage is 47.22%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4376      +/-   ##
=============================================
- Coverage      69.12%   69.04%   -0.09%     
- Complexity      3654     3661       +7     
=============================================
  Files            266      266              
  Lines          15091    15123      +32     
  Branches        1638     1651      +13     
=============================================
+ Hits           10432    10442      +10     
- Misses          3896     3909      +13     
- Partials         763      772       +9     
Flag Coverage Δ
integrationtests 57.25% <2.77%> (-0.12%) ⬇️
languageparsingtests 0.58% <0.00%> (-0.01%) ⬇️
toolintegrationtests 30.34% <0.92%> (-0.07%) ⬇️
workflowintegrationtests 42.72% <47.22%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...webservice/languages/LanguageHandlerInterface.java 72.50% <46.72%> (-2.33%) ⬇️
...on/src/main/java/io/dockstore/common/Registry.java 66.66% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f3d735...902ef61. Read the comment docs.

@kathy-t kathy-t requested a review from coverbeck August 3, 2021 12:46
@denis-yuen
Copy link
Member

The rate limit issue was sporadic. The test would some times fail but then pass when I tried it again immediately.

The unpredictability could be a pain, we'll have to keep an eye on this.

boolean success = false;
int maxRetries = 3;
int retries = 0;
do {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I think I had intended on implementing this at some point but never got around to it.
https://github.com/dockstore/dockstore/blob/1.11.5/dockstore-webservice/src/main/java/io/dockstore/webservice/resources/ResourceUtilities.java#L78

Might be useful as a general utility

Copy link
Contributor

@coverbeck coverbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nit-picky stuff, your call on whether you want to do it or not.

}

if (tokenResponse.statusCode() != HttpStatus.SC_OK) {
Map<String, List<Map<String, String>>> errorMap = GSON.fromJson(tokenResponse.body(), Map.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you always rely on it returning a JSON response for all error conditions? If not, I think this line will throw an exception.

It may be so rare that you don't need to handle it; your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docker Registry API specs say that actionable failure conditions are reported as part of 4xx responses in a JSON response body, so I think it's pretty safe to assume that it'll return a JSON response

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory I would think you could get 5xx responses as well, which may not be actionable, and hence may not have have JSON responses.

I tend to think in edge cases, and this one is probably way out there, so what you have should be fine.

if (manifestResponse.statusCode() == HttpStatus.SC_OK) {
success = true;
} else {
Map<String, List<Map<String, String>>> errorMap = GSON.fromJson(manifestResponse.body(), Map.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment

}

return gitHubContainerRegistryImages;
if (blobResponse.statusCode() != HttpStatus.SC_OK) {
Map<String, List<Map<String, String>>> errorMap = GSON.fromJson(blobResponse.body(), Map.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comments. Also just noticed that all 3 places where you do the error handling are near duplicates (I think), so you could create a common method.

@kathy-t kathy-t requested a review from coverbeck August 5, 2021 17:04
@sonarcloud
Copy link

sonarcloud bot commented Aug 5, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

8.8% 8.8% Coverage
0.0% 0.0% Duplication

@kathy-t kathy-t merged commit 65119f4 into develop Aug 5, 2021
@kathy-t kathy-t deleted the feature/4330/amazon-ecr-workflow-checksum-harvesting branch August 5, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants