cvg / pyceres

Factor graphs with Ceres in Python
Apache License 2.0
247 stars 34 forks source link

Split Dockerfile in two stages: builder and runtime. #31

Open pablospe opened 9 months ago

pablospe commented 9 months ago

By dividing the Dockerfile into two stages, we significantly reduce the size of the final image. This is because the build dependencies, which are not required in the final image, are excluded.

You can create tags for each stage separately using the --target option:

docker build --target builder -t pyceres:builder .
docker build --target runtime -t pyceres:runtime .

However, if you run the docker build command without the --target option, it will build up to the last stage defined in the Dockerfile. So, running:

docker build -t pyceres:latest .

is equivalent to specifying --target runtime, as runtime is the final stage in the Dockerfile.

Reduction in size:

pyceres:runtime    2.48GB
pyceres:builder    8.98GB
sarlinpe commented 9 months ago

I've removed the dependency on COLMAP - is the Docker size still an issue?

pablospe commented 9 months ago

If I do docker images after building it: pyceres latest 7653326fc398 6 minutes ago 8.32GB

Which seems weird because it has a lot less dependencies.

I guess you don't need the cuda image anymore: FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as builder Just changing to regular ubuntu image base could reduce the size.

I would still recommend doing the builder/runtime split, since it is not really needed all the *-dev libraries to run it.

pablospe commented 9 months ago

I quickly updated this PR locally, using regular ubuntu image and I get:

pyceres                                      runtime           93e79e43bd1a   55 seconds ago   425MB
pyceres                                      builder           2574cc974212   58 seconds ago   1.41GB

edit: I added some runtime libraries