Hi guys, I have a question around building a Docke...
# general
a
Hi guys, I have a question around building a Docker image from a python source. So far I have understood that if I want to publish a python library from a python source, I should be using
python_distribution()
target and for a Docker image it should be
docker_image()
target. Throwing in gRPC and Protobufs in the mixture and there I know that
python_distribution()
target type will resolve the proto dependency at the time of executing
package
goal. Would the target type
docker_image()
do the same? Is
package
the right goal for my use case here as in to build a Docker image?
r
This might be helpful. https://blog.pantsbuild.org/pants-pex-and-docker/ Generally
pex_binary
is the recommended target for docker image.
a
This might be helpful.
https://blog.pantsbuild.org/pants-pex-and-docker/
Generally
pex_binary
is the recommended target for docker image.
Ok, what would be the workflow then? Adding the dependency of
pex_binary()
target to the
docker_image()
target?
r
You don't need to explicitly add dependency on
pex_binary
. It's from the docs.
When you COPY PEX binaries into your image, the dependency on the pex_binary target will be inferred, so you don't have to add that explicitly to the list of dependencies on your docker_image target.
https://www.pantsbuild.org/docs/docker
One important thing to know about
pex_binary
is that they are platform dependent and when you copy them inside docker, they are first built on the host not inside the docker container. So if your host is macos and you copy a PEX inside Linux docker Image, it won't work.
a
Yeah, that’s why I was looking for building a Docker image from
python_distribution()
.
r
It has its cons too like if you have local python distribution (1st party) on which your
python_distribution
depends on then you will have to host them somewhere and then pass the necessary secrets to docker build so that it gets installed inside the image.
pex_binary
bundles all 1st party and 3rd party dependencies without much from your side.
a
Ok, but right now I am just focused on getting the
package
goal working and see the results. I can think about the target types later once I have a clear picture in mind and I proceed towards implementing the learnings in prod.