canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
25 stars 33 forks source link

Use new python3.10-venv slices when bare in flask-framework extension #606

Closed gregory-schiano closed 6 days ago

gregory-schiano commented 1 week ago

Using the new python3.11-venv slice to reduce the image of the generated rock when base is bare using flask-framework and django-framework extensions.

How to test: Install a build of rockcraft using this branch, you need to have docker installed too

git pull https://github.com/canonical/sample-flask.git
cd sample-flask
rockcraft init --profile flask-framework
# Edit the required fields in rockcraft.yaml
# 1. We ensure that when using ubuntu@22.04 base it still works
rockcraft pack
rockcraft.skopeo copy --insecure-policy oci-archive:sample-flask_0.1_amd64.rock docker-daemon:sample-flask:ubuntu
docker run -d --name flask-ubuntu -p 8000:8000 sample-flask:ubuntu
curl localhost:8000
# Should return <h1>Hello</h1>
docker exec -ti flask-ubuntu bash
/bin/python3 --version
# Should return "Python 3.10.12"
exit
docker stop flask-ubuntu
# Edit rockcraft.yaml, change base to "bare" and add "build-base: ubuntu@22.04"
rockcraft clean
rockcraft pack
rockcraft.skopeo copy --insecure-policy oci-archive:sample-flask_0.1_amd64.rock docker-daemon:sample-flask:bare
docker run -d --name flask-bare -p 8000:8000 sample-flask:bare
curl localhost:8000
# Should return <h1>Hello</h1>
docker exec -ti flask-bare bash
/bin/python3 --version
# Should return "Python 3.10.12"
exit
docker stop flask-bare

You can also test using the tutorial (follow the chiseling part of the tutorial): https://documentation.ubuntu.com/rockcraft/en/latest/tutorials/getting-started-with-flask/

jdkandersson commented 1 week ago

Why is it Python 3.11.0rc1? The latest version of Python 3.11 is 3.11.9, 0rc1 I think is pre-release so probably doesn't contain a bunch of security fixes etc

gregory-schiano commented 1 week ago

Btw, the docs (https://documentation.ubuntu.com/rockcraft/en/stable/tutorials/getting-started-with-flask/#chisel-the-rock) should be updated as I'm expecting the resulting rock to now be more than 15% smaller

Indeed, but not that this %age (like the size also provided in this tutorial) might change at any time due to new packages, and dependencies.

cjdcordeiro commented 1 week ago

Btw, the docs (https://documentation.ubuntu.com/rockcraft/en/stable/tutorials/getting-started-with-flask/#chisel-the-rock) should be updated as I'm expecting the resulting rock to now be more than 15% smaller

Indeed, but not that this %age (like the size also provided in this tutorial) might change at any time due to new packages, and dependencies.

It was my impression, from this PR, that if you use a base: bare, the extension will use a slice instead of a deb (which is the case today). Thus, the resulting rock will be smaller.

gregory-schiano commented 1 week ago

Btw, the docs (https://documentation.ubuntu.com/rockcraft/en/stable/tutorials/getting-started-with-flask/#chisel-the-rock) should be updated as I'm expecting the resulting rock to now be more than 15% smaller

Indeed, but not that this %age (like the size also provided in this tutorial) might change at any time due to new packages, and dependencies.

It was my impression, from this PR, that if you use a base: bare, the extension will use a slice instead of a deb (which is the case today). Thus, the resulting rock will be smaller.

You understood properly, but the size of the images depends on the size of the dependencies installed and the size of the files the slices are setting. This can change overtime.

cjdcordeiro commented 1 week ago

Btw, the docs (https://documentation.ubuntu.com/rockcraft/en/stable/tutorials/getting-started-with-flask/#chisel-the-rock) should be updated as I'm expecting the resulting rock to now be more than 15% smaller

Indeed, but not that this %age (like the size also provided in this tutorial) might change at any time due to new packages, and dependencies.

It was my impression, from this PR, that if you use a base: bare, the extension will use a slice instead of a deb (which is the case today). Thus, the resulting rock will be smaller.

You understood properly, but the size of the images depends on the size of the dependencies installed and the size of the files the slices are setting. This can change overtime.

Ofc it can, but in that case, we wouldn't be stating any sizes anywhere, and we are (64MB , and then 15% reduction). You do agree that, with your changes, the size reduction will no longer be 15% right? If that's true, then the doc needs fixing

gregory-schiano commented 1 week ago

Btw, the docs (https://documentation.ubuntu.com/rockcraft/en/stable/tutorials/getting-started-with-flask/#chisel-the-rock) should be updated as I'm expecting the resulting rock to now be more than 15% smaller

Indeed, but not that this %age (like the size also provided in this tutorial) might change at any time due to new packages, and dependencies.

It was my impression, from this PR, that if you use a base: bare, the extension will use a slice instead of a deb (which is the case today). Thus, the resulting rock will be smaller.

You understood properly, but the size of the images depends on the size of the dependencies installed and the size of the files the slices are setting. This can change overtime.

Ofc it can, but in that case, we wouldn't be stating any sizes anywhere, and we are (64MB , and then 15% reduction). You do agree that, with your changes, the size reduction will no longer be 15% right? If that's true, then the doc needs fixing

Sure agree, that was just a side note. I've already updated the doc, we went from 65MB to 46MB, so 30% less

cjdcordeiro commented 1 week ago

Waiting on https://github.com/canonical/chisel-releases/pull/271

gregory-schiano commented 6 days ago

For reference, the ubuntu 22.04 base leads to a 65MB image, while the bare base image (with python3.10) leads to a 44MB image size

tigarmo commented 6 days ago

Thanks a lot! Does anyone else want to look into this before I sync it with main & merge?

cjdcordeiro commented 6 days ago

@tigarmo please wait for a check on the documentation. Is https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework/ up to date after this merge?

If the rockcraft.yaml accurate?

gregory-schiano commented 6 days ago

@tigarmo please wait for a check on the documentation. Is https://documentation.ubuntu.com/rockcraft/en/stable/reference/extensions/flask-framework/ up to date after this merge?

If the rockcraft.yaml accurate?

I didn't change anything about the user experience. The documentation update needed was about the size reduction of the produced chiseled rock. I've done a review of the existing documentation to ensure something needs to be updated, and didn't find anything else. But could be good to have a second pair of eyes