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

Do not pull all available tags with --pull #100

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

meyerj
Copy link
Contributor

@meyerj meyerj commented Oct 20, 2020

rocker --pull <image> without a tag pulls all available tags for that image, and hence can fill the disk quickly.

The reason is that the underlying docker_client.pull(image,tag=None) pulls all available tags if no specific tag is specfied:

If no tag was specified, the method will return a list of Image objects belonging to this repository.

So the removed method rocker.core.pull_image(image_name) would have to decompose the URL given at the command line, and either pass the tag separately, or append :latest to image_name if no other tag was specified.

This patch removes the broken method completely. It is not needed, because the pull flag can simply be forwarded to the docker_client.build() command, at least for docker-py version 2.5.1 provided by Ubuntu Bionic and version 1.8.0 provided by Ubuntu Xenial.

Verified with:

$ docker pull ubuntu:bionic
bionic: Pulling from library/ubuntu
171857c49d0f: Already exists 
419640447d26: Already exists 
61e52f862619: Already exists 
Digest: sha256:646942475da61b4ce9cc5b3fadb42642ea90e5d0de46111458e100ff2c7031e6
Status: Downloaded newer image for ubuntu:bionic
docker.io/library/ubuntu:bionic
$ docker tag ubuntu:bionic ubuntu:latest
$ rocker ubuntu    # expectation: same as ubuntu:latest
[...]
Building docker file with arguments:  {'path': '/tmp/tmppa0oykh2', 'rm': True, 'nocache': False, 'pull': False}
[...]
root@a95d93f22ee6:/# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
root@a95d93f22ee6:/# exit
exit

So the version tagged as ubuntu:latest is actually ubuntu:bionic. rocker did not attempt to pull a newer version.

--pull still has the desired effect and the docker daemon pulls the image during the build:

$ rocker --pull ubuntu    # expectation: same as ubuntu:latest
[...]
Building docker file with arguments:  {'path': '/tmp/tmp8zlicrod', 'rm': True, 'nocache': False, 'pull': True}
[...]
root@475275ae66cc:/# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
root@475275ae66cc:/# exit
exit

Without this patch, the second invocation rocker --pull ubuntu would take very long and pull all available tags.

@meyerj meyerj requested a review from tfoote as a code owner October 20, 2020 19:02
`docker_client.pull(image,tag=None)` pulls all available tags if no specific tag
is specfied:
https://docker-py.readthedocs.io/en/2.5.1/images.html#docker.models.images.ImageCollection.pull

> If no tag was specified, the method will return a list of Image objects belonging to this repository.

So the removed method pull_image(image_name) would have to decompose the URL given at
the command line.

This patch removes the broken method completely. It is not needed, because the pull flag
can simply be forward to the `docker_client.build()` command:
https://docker-py.readthedocs.io/en/2.5.1/images.html#docker.models.images.ImageCollection.build
@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #100 into master will decrease coverage by 0.17%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #100      +/-   ##
==========================================
- Coverage   86.70%   86.52%   -0.18%     
==========================================
  Files           7        7              
  Lines         564      579      +15     
==========================================
+ Hits          489      501      +12     
- Misses         75       78       +3     
Impacted Files Coverage Δ
src/rocker/cli.py 0.00% <ø> (ø)
src/rocker/core.py 90.14% <ø> (-1.08%) ⬇️
src/rocker/extensions.py 100.00% <0.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 b1fae79...600dda8. Read the comment docs.

Copy link
Collaborator

@tfoote tfoote left a comment

Choose a reason for hiding this comment

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

Thanks it's always great to reduce the amount of code and make it more efficient.

@tfoote tfoote merged commit da46a95 into osrf:master Nov 2, 2020
@meyerj meyerj deleted the fix/docker-pull-multiple-tags branch December 9, 2020 19:47
130s pushed a commit to plusone-robotics/rocker that referenced this pull request Apr 17, 2021
`docker_client.pull(image,tag=None)` pulls all available tags if no specific tag
is specfied:
https://docker-py.readthedocs.io/en/2.5.1/images.html#docker.models.images.ImageCollection.pull

> If no tag was specified, the method will return a list of Image objects belonging to this repository.

So the removed method pull_image(image_name) would have to decompose the URL given at
the command line.

This patch removes the broken method completely. It is not needed, because the pull flag
can simply be forward to the `docker_client.build()` command:
https://docker-py.readthedocs.io/en/2.5.1/images.html#docker.models.images.ImageCollection.build
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.

2 participants