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

[DockerSize] Docker image size multi arch #8290

Merged
merged 28 commits into from Aug 25, 2022

Conversation

PaulaBarszcz
Copy link
Collaborator

@PaulaBarszcz PaulaBarszcz commented Aug 6, 2022

Related issue: #8238

All of my changes are pushed to the feature branch (docker-imageSize-multiArch).

The full_size is used only if no architecture was specified.

If the user supplied the arch param:
if the image with the given arch was found, we give its size,
if the image with the given arch was not found, we throw an architecture not found error.

Some examples below:

with tag:

https://registry.hub.docker.com/v2/repositories/library/mysql/tags/latest

  • incorrect repo name:

http://localhost:8080/docker/image-size/_/mysqppppl

Zrzut ekranu 2022-08-11 o 18 20 23

  • incorrect tag:

http://localhost:8080/docker/image-size/_/mysql/nonexistentTag

Zrzut ekranu 2022-08-11 o 18 15 17

  • correct arch param supplied:

http://localhost:8080/docker/image-size/_/mysql/latest?arch=amd64

Zrzut ekranu 2022-08-11 o 18 03 00

http://localhost:8080/docker/image-size/_/mysql/latest?arch=amd64555

Zrzut ekranu 2022-08-11 o 18 10 30

without tag:

https://registry.hub.docker.com/v2/repositories/library/mysql/tags?page_size=100&ordering=last_updated

  • correct arch param supplied:

http://localhost:8080/docker/image-size/_/mysql?arch=arm64

Zrzut ekranu 2022-08-11 o 18 08 24

http://localhost:8080/docker/image-size/_/mysql?arch=444444

Zrzut ekranu 2022-08-11 o 18 11 46

  • correct arch param supplied, that is not present in the fetched docker images response:

http://localhost:8080/docker/image-size/_/mysql?arch=386

Zrzut ekranu 2022-08-11 o 18 26 39

  • correct arch param supplied (that is present in the fetched docker images response), with semver as a sorting method:

http://localhost:8080/docker/image-size/_/mysql?sort=semver&arch=arm64

Zrzut ekranu 2022-08-11 o 18 27 46

@shields-ci
Copy link

shields-ci commented Aug 6, 2022

Messages
📖 ✨ Thanks for your contribution to Shields, @PaulaBarszcz!

Generated by 🚫 dangerJS against 489619c

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

Tbh this will be easier to review once there are some tests, but it looks like a reasonable start. I'd suggest given the type of changes you're making here, you're going to want most (or possibly all) of your tests to be unit tests in https://github.com/badges/shields/blob/master/services/docker/docker-size.spec.js rather than service tests. If writing the tests is a bit cumbersome because this transform() function is doing a lot of things, it might also make things easier if we split out the 3 main code paths in transform() (sort by date, sort by semver, specified tag) down to smaller functions.

I've not really done a proper review but I've had a quick look and left a few comments. We can do a full review once it is finished.

services/docker/docker-size.service.js Outdated Show resolved Hide resolved
services/docker/docker-size.service.js Outdated Show resolved Hide resolved
services/docker/docker-size.service.js Outdated Show resolved Hide resolved
@PaulaBarszcz PaulaBarszcz marked this pull request as ready for review August 11, 2022 16:31
@PaulaBarszcz
Copy link
Collaborator Author

Hi @chris48s,
Thank you for all your suggestions, I finished this batch of corrections and updated tests.

This PR is ready to be reviewed.

'mips64',
'mips64le',
'riscv64',
386,
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need 386 as a number as well as a string here?
If I look at an image which publishes a 386 version, for example:
https://registry.hub.docker.com/v2/repositories/library/debian/tags/latest
it appears in the JSON as a string:

"architecture": "386",

Do we have an example where the architecture is a number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the variable validArchitectures inside services/docker/docker-helpers.js file
contains 386 both as a number and as a string,
the resulting badge of http://localhost:8080/docker/image-size/_/mysql?arch=386 is
arch not found
That would mean that the supplied arch parameter passes Joi schema verification
and that the response does not contain the image with the architecture supplied by the user.

When the variable validArchitectures inside services/docker/docker-helpers.js file
contains 386 only as a string,
the resulting badge of http://localhost:8080/docker/image-size/_/mysql?arch=386 is
inv query param arch
That would mean that the supplied arch parameter does not pass Joi schema verification.
From this I inferred that we read 386 from the query params as a number and thus I need to add it as a number to the validArchitectures variable.

What is the preferred course of action here - should 386 remain in validArchitectures both as a number and as a string, or should we look more closely at how we transform query params?

Copy link
Member

Choose a reason for hiding this comment

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

OK. thanks for explaining. I can see what we're trying to achieve now. Here's my suggestion.

Lets define a shared Joi schema in docker-helpers.js that looks like this:

const archSchema = Joi.alternatives([
  Joi.string().valid(
    'amd64',
    'arm',
    'arm64',
    's390x',
    '386',
    'ppc64',
    'ppc64le',
    'wasm',
    'mips',
    'mipsle',
    'mips64',
    'mips64le',
    'riscv64',
  ),
  Joi.number().valid(386).cast('string'),
])

That will accept all the normal architecture values and 386 as a number (but will cast it to a string so it will match the API data when we compare with === ).

Then in both docker-size.service.js and docker-version.service.js we can use that schema in our queryParamSchema, and in docker-version.service.js you can chain .default('amd64')

How does that sound?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 42 to 45
arch: Joi.alternatives([
Joi.string().valid(...validArchitectures),
Joi.number().valid(...validArchitectures),
]),
Copy link
Member

Choose a reason for hiding this comment

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

I've put a comment in elsewhere saying I don't think we need to allow architecture to be a number at all. Assuming we can ditch it, this can just be arch: Joi.string().valid(...validArchitectures). If not, lets come back to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is connected to my comment #8290 (comment)
If needed, I will update this chunk of code :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated as per #8290 (comment)

services/docker/docker-size.service.js Outdated Show resolved Hide resolved
services/docker/docker-size.service.js Outdated Show resolved Hide resolved
services/docker/docker-size.spec.js Outdated Show resolved Hide resolved
services/docker/docker-size.service.js Outdated Show resolved Hide resolved
@calebcartwright calebcartwright added the service-badge Accepted and actionable changes, features, and bugs label Aug 19, 2022
@PaulaBarszcz
Copy link
Collaborator Author

Hi @chris48s,
Thanks for your review; I applied your suggestions. This PR is ready to be re-reviewed.

Who closes discussions in PRs - the author of the comment/suggestion,
or the author of the PR (once the changes are implemented)?

@PaulaBarszcz
Copy link
Collaborator Author

Hi @chris48s,
Thanks for your suggestion regarding valid architectures. The changes are already pushed to the feature branch.

This PR is ready to be re-reviewed.

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

nice 👍 thanks for working on this one

@chris48s chris48s merged commit bb326a0 into badges:master Aug 25, 2022
@PaulaBarszcz PaulaBarszcz deleted the docker-imageSize-multiArch branch August 25, 2022 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants