Hi, we built our own pants because we have minor c...
# general
s
Hi, we built our own pants because we have minor changes that we needed and it all works fine. However in the CICD pipeline which uses the pants-init github action, it fails because it doesn’t recognize the goal
bootstrap-cache-key
while using
PANTS_BOOTSTRAP_VERSION=2
. Is there anything we missed?
f
What do you mean by "we built our own pants"? Did you build a Pants pex or something else? How is the artifact being distributed?
s
We adjusted the actual pantsbuild source
f
Right, but then what binary artifact are you building and distributing to CI to invoke that modified version? The whole Pants source? The Pants Pex built by
./pants package src/python/pants:pants-pex
or the wheel built by
./pants package src/python/pants:pants-packaged
?
Then can you share the full logs for failing invocations? (please of course redact confidential items)
There are a few ways to distribute a modified Pants and those details are essential to understanding how the
init-pants
GHA action is interacting with it.
(it is hard to answer or even speculate without sufficient technical detail.)
s
Copy code
# Install Pants
RUN curl --proto '=https' --tlsv1.2 -fsSL <https://static.pantsbuild.org/setup/get-pants.sh|https://static.pantsbuild.org/setup/get-pants.sh> | bash

# Add Pants to PATH
ENV PATH="${HOME}/.local/bin:${PATH}"

# Create directory for Pants named caches
RUN mkdir -p ~/.cache/pants/named_caches
# Set default environment variables for Pants and Cloud SDK
ENV PANTS_PANTSD="True"
ENV PANTS_CACHE_DIR="${HOME}/.cache/pants"
ENV PANTS_NAMED_CACHES_DIR="${HOME}/.cache/pants/named_caches"

# Add pants source
COPY --chown=runner:runner third-party/infra/pants /third-party/infra/pants
# Pants requires a .git directory to function properly
# This is to handle the fact that we use a submodule for Pants
RUN rm /third-party/infra/pants/.git
COPY --chown=runner:runner .git/modules/third-party/infra/pants /third-party/infra/pants/.git
ENV PANTS_SOURCE=/third-party/infra/pants
Sorry mobile is not formatting correctly
f
I would recommend not adding the Pants source that way. Build the
pants.pex
and just bundle that in the container. You can point the Pants launcher at it by setting
PANTS_BOOTSTRAP_URLS
as per https://github.com/pantsbuild/scie-pants?tab=readme-ov-file#firewall-support and using a
file://
URL.
Another way would be to invoke the
pants.pex
directly as I do for example in this plugin's integration tests: https://github.com/shoalsoft/shoalsoft-pants-opentelemetry-plugin/blob/main/src/py[…]ft/pants_opentelemetry_plugin/opentelemetry_integration_test.py, but a big downside is it forgoes using the scie-pants launcher to supply a Python Build Standalone interpreter (but I decided that was fine for my plugin's tests).
The Pants launcher invokes Pants via the Pex and so using a Pex will probably solve your issue with the boostrap protocol since you would be switching to distributing your custom Pants in the same way that official Pants is distributed. The Pants launcher actually just downloads
pants.pex
for a release from GitHub Releases.
You can builds a
pants.pex
with
./pants package src/python/pants:pants-pex
in the Pants repository. Look in
dist/
for the output.
s
Something like this? and then setting the version to 2.61.1?
Copy code
RUN curl --proto '=https' --tlsv1.2 -fsSL <https://static.pantsbuild.org/setup/get-pants.sh> | bash

COPY third-party/infra/pants/dist/src.python.pants/pants-pex.pex /opt/pants/pants.pex
RUN sudo chmod +x /opt/pants/pants.pex && \
    sudo chown coder:coder /opt/pants/pants.pex


RUN sudo mkdir -p /opt/pants/.config
RUN echo '{\
    "ptex": {\
    "cpython-3.10.18+20250612-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20250612/cpython-3.10.18%2B20250612-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "cpython-3.11.13+20250612-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20250612/cpython-3.11.13%2B20250612-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "cpython-3.12.11+20250612-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20250612/cpython-3.12.11%2B20250612-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "cpython-3.13.5+20250612-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20250612/cpython-3.13.5%2B20250612-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "cpython-3.8.20+20241002-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20241002/cpython-3.8.20%2B20241002-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "cpython-3.9.23+20250612-x86_64-unknown-linux-gnu-install_only.tar.gz": "<https://github.com/astral-sh/python-build-standalone/releases/download/20250612/cpython-3.9.23%2B20250612-x86_64-unknown-linux-gnu-install_only.tar.gz>",\
    "pants.2.61.1-cp12-linux_x86_64.pex": "file:///opt/pants/pants.pex"\
    }\
    }' | sudo tee /opt/pants/.config/ptex.json > /dev/null
RUN sudo chown coder:coder /opt/pants/.config/ptex.json && \
    sudo chmod 644 /opt/pants/.config/ptex.json

# Set PANTS_BOOTSTRAP_URLS to use local ptex json
ENV PANTS_BOOTSTRAP_URLS="/opt/pants/.config/ptex.json"
f
probably, the ptex JSON looks generally correct. although from
pants.2.61.1-cp12-linux_x86_64.pex
, you are building the pex with Python 3.12? Pants is on Python 3.11, so you should set interpreter constraints to Python 3.11 (the
cp12
is what I'm reacting to, although shouldn't that be
cp312
then?)
(The Python version used for your user code can differ from the Python used by Pants.)
You may also want to run
pants --version
as a test and, as a side effect, force the Pants launcher to unpack the Pants venv from the pex which will then be cached in your Docker image.
c
Thanks for sharing this! I was not aware of anyone using a process like this. If applicable, I hope we can help get those minor changes upstream.
s
@fast-nail-55400 thanks a lot for your help! It all worked out following you guidance