hey everyone! :smile: I want to know if someone ca...
# general
b
hey everyone! 😄 I want to know if someone can help me. I've just started using Pants, and I'm now creating my Docker image to publish the application. I have the setup working locally to build my PEX file, but when I install
pants
on my Docker image and I run
pants package
I get this error:
Copy code
------
 > [base 9/9] RUN ./pants package apps/api:prod:
106.4 Traceback (most recent call last):
106.4   File "/root/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/runpy.py", line 197, in _run_module_as_main
106.4     return _run_code(code, main_globals, None,
106.4   File "/root/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/runpy.py", line 87, in _run_code
106.4     exec(code, run_globals)
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/__main__.py", line 106, in <module>
106.4     bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/pex_bootstrapper.py", line 621, in bootstrap_pex
106.4     venv_pex = _bootstrap_venv(entry_point, interpreter=target)
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/pex_bootstrapper.py", line 688, in _bootstrap_venv
106.4     return ensure_venv(pex.PEX(entry_point, interpreter=interpreter))
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/pex_bootstrapper.py", line 498, in ensure_venv
106.4     virtualenv = Virtualenv.create_atomic(
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/venv/virtualenv.py", line 268, in create_atomic
106.4     virtualenv = cls.create(
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/venv/virtualenv.py", line 254, in create
106.4     interpreter.execute(args=args, env=env)
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/interpreter.py", line 1540, in execute
106.4     stdout, stderr = Executor.execute(cmd, stdin_payload=stdin_payload, env=env, **kwargs)
106.4   File "/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/unzipped_pexes/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/.bootstrap/pex/executor.py", line 99, in execute
106.4     raise cls.NonZeroExit(cmd, process.returncode, stdout, stderr)
106.4 pex.executor.Executor.NonZeroExit: received exit code 1 during execution of `['/root/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.9', '-s', '-E', '-m', 'venv', '--without-pip', '/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/venvs/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/327f457f25e419eeb572d4624fc6cd8ccb017a05.lck.work', '--prompt', 'tools.pex']` while trying to execute `['/root/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.9', '-s', '-E', '-m', 'venv', '--without-pip', '/root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/pex_root/venvs/10065e08ffb3b880c0f2fc1126cc528a64b9e10b/327f457f25e419eeb572d4624fc6cd8ccb017a05.lck.work', '--prompt', 'tools.pex']`
106.5 Error: Failed to establish atomic directory /root/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/locks/configure-0396e38ee35908f2900222e74f164e69cffaabc49ab6340c41ff10dea810ec6f. Population of work directory failed: Boot binding command failed: exit status: 1
106.5
106.5 Isolates your Pants from the elements.
106.5
106.5 Please select from the following boot commands:
106.5
106.5 <default> (when SCIE_BOOT is not set in the environment)  Detects the current Pants installation and launches it.
106.5 bootstrap-tools                                           Introspection tools for the Pants bootstrap process.
106.5 update                                                    Update scie-pants.
106.5
106.5 You can select a boot command by setting the SCIE_BOOT environment variable.
Anyone knows what should I do?
1
this is my Dockerfile:
Copy code
# Base image
FROM ubuntu:20.04 as base

# Create a non-root user
RUN useradd -m builduser

# Set working directory
WORKDIR /build

# Set environment variables
ENV PATH="/usr/bin:${PATH}"
ENV DEBIAN_FRONTEND=noninteractive

# Install Pants and other dependencies
RUN apt-get update && \
    apt-get install -y \
    curl \
    bash \
    libc-dev \
    gcc \
    python3-dev \
    python3-distutils \
    python3 \
    python3-pip && \
    rm -rf /var/lib/apt/lists/* && \
    curl --proto '=https' --tlsv1.2 -fsSL <https://static.pantsbuild.org/setup/get-pants.sh> -o get-pants.sh && \
    chmod +x get-pants.sh && \
    ./get-pants.sh --bin-dir /build

# Set the default Python version to Python 3
RUN ln -s /usr/bin/python3 /usr/bin/python

# Copy project files
COPY apps/ \
    libs/ \
    BUILD \
    pants.toml \
    pyproject.toml \
    python-default.lock \
    ./

# Generate dependencies file
RUN awk '/dependencies = \[/{flag=1;next}/\]/{flag=0}flag' pyproject.toml | sed 's/^[ \t]*//;s/[",]//g' > requirements.txt

# Set to use the builduser
RUN chown -R builduser:builduser /build
USER builduser

####################################################################################################
# Build image for API
FROM base as api-build

WORKDIR /build

# Copy files from base
COPY --from=base /build .

# Run Pants commands to package the application
RUN pip install -r requirements.txt
RUN ./pants package apps/api:prod


####################################################################################################
# Runtime image for API
FROM python:3.9-alpine3.20 as api-runtime

# Define run arguments
ARG UID=1000
ARG GID=984
ARG UNAME=vocatales
ARG GNAME=vocatales-users

# Set environment variables
ENV HOME=/home/${UNAME}
ENV BASEDIR=${HOME}/app

# Create user and group
RUN if getent passwd ${UID} >/dev/null; then \
    deluser $(getent passwd ${UID} | cut -d: -f1); fi && \
    if getent group ${GID} >/dev/null; then \
    delgroup $(getent group ${GID} | cut -d: -f1); fi && \
    addgroup --system --gid ${GID} ${GNAME} && \
    adduser --system --disabled-password --home /home/${UNAME} --uid ${UID} --ingroup ${GNAME} ${UNAME}
RUN chown -R ${UID}:${GID} ${HOME}

# Set user and work directory
USER ${UID}
WORKDIR ${BASEDIR}

# Copy built application and pyproject.toml from api-build stage
COPY --chown=${UID}:${GID} --from=base /build/requirements.txt .
COPY --chown=${UID}:${GID} --from=base /build/dist/apps.api/prod.pex api.pex

# Install dependencies
RUN pip install -r requirements.txt

# Set entrypoint and command
ENTRYPOINT ["python3"]
CMD ["./api.pex"]
I've already tried without the build user (as root) but got the same error
don't know if this is relevant, but this is my
pants.toml
file:
Copy code
[GLOBAL]
pants_version = "2.21.0"
build_ignore = ["legacy/*", "legacy/**/*"]
backend_packages = [
  "pants.backend.build_files.fmt.black",  
  "pants.backend.python",
  "pants.backend.python.lint.docformatter",
  "pants.backend.python.lint.black",
  "pants.backend.python.lint.flake8",
  "pants.backend.python.lint.isort",
  "pants.backend.python.typecheck.mypy",
  "pants.backend.docker",
]

[source]
root_patterns = ["/"]

[python]
interpreter_constraints = ["==3.11.*"]
enable_resolves = true
resolves = { python-default = "python-default.lock"}

[python-infer]
use_rust_parser = true

[tailor]
ignore_paths = ["legacy/*", "legacy/**/*"]
and this is the API BULD file:
Copy code
python_source(
    name="dev",
    source="src/serve.py",
    restartable=True,
)

pex_binary(
    name="prod",
    dependencies=[":api"],
    entry_point="src/serve.py",
)

python_sources(
    name="api",
    sources=["**/*.py"],
)

python_tests(
    name="tests",
    sources=["tests/**/test_*.py"],
)

python_test_utils(
    name="test_utils",
    sources=["tests/conftest.py"],
)
👍 1
sorry, I was able to figure it out. It turns out it was happening because I was running
pants
the first time on the folder that contained all my files. Honestly, I don't think that should happen, but if I run it on another folder before it solves the issue
c
That seems like it could be due to a permission issue on some file or folder perhaps.
b
@curved-television-6568 I'm not sure, simply by running
pants
before copying the contents to the Docker image solved the issue