Hey friends, how are you doing? I hope you're all ...
# general
r
Hey friends, how are you doing? I hope you're all good! So, I am trying to run the
pants
command in a machine that doesn't contain any pants repo. What happens is that pants bootstraps itself by downloading python3.9 and everything else that it needs, which is nice. My issue is that pants than asks if I want to create a new pants repo in the directory that I am running the
pants
command, and I don't want it to happen. Is there any
pants
subcommand that make it bootstraps itself but makes pants not ask to create a new pants project? Just to give more context, I want to build a docker image containing all necessary pants dependencies to run some CI/CD steps, but I am struggling when pants asks to create a new pants repo.
e
Why do you run
pants
at all in this context then?
Ah, missed the edited question.
So,
pants
is not pants. It's a shim binary and it's already bootstrapped.
The pants you're thinking of can only be bootstrapped for a given version.
Which version? That's usually spelled out in a repo's
pants.toml
r
Currently, we're using pants 2.16 that runs on Python 3.9. I'd like to create a docker image containing this guy, so we don't need to download and build all pants dependencies in every CI/CD build.
e
Right - so the 2.16.0 is secret hidden knowledge known only to you!
So you could do something like this for the least setup:
Copy code
$ touch pants.toml && PANTS_VERSION=2.16.0 pants -V && rm pants.toml
Bootstrapping Pants 2.16.0 using cpython 3.9.16
Installing pantsbuild.pants==2.16.0 into a virtual environment at /home/jsirois/.cache/nce/260e9f180e257368873660af8dd93ef1ae670cb61bde99eea1fd914ad6e534bb/bindings/venvs/2.16.0
New virtual environment successfully created at /home/jsirois/.cache/nce/260e9f180e257368873660af8dd93ef1ae670cb61bde99eea1fd914ad6e534bb/bindings/venvs/2.16.0.
2.16.0
🤩 1
❤️ 1
Otherwise, with no
pants.toml
, Pants assumes the latest stable version (currently 2.17.0), bootstraps that, and then offers to record that in
pants.toml
in CWD.
r
Hey, this looks great! I think that's exactly what I needed.
That being said, I am not sure if building a pants docker image is the best approach as it would break if we changed to newer pants version, but I feel we can try to maintain it internally if it makes our CI/CD builds faster.
e
Well, do you have 1 Pants-using repo or >1?
r
Only 1
e
So ... why not
COPY pants.toml ..
then bootstrap pants then remove it?
The pants.toml records
pants_version
in it.
r
That's a great idea lol. I didn't think about it because I'm creating the docker image from outside the monorepo, but if we add the dockerfile to the repo, we can get the pants_version as you said.
e
You can clearly automate a CI job that auto-rebuilds the image only when needed that way.
r
Thanks a lot for the answers. These ideas are excellent. I'll implement them right away! 😺