alert-beard-13327
10/21/2024, 8:08 PM# syntax=docker/dockerfile:1
################################
# PYTHON-BASE
################################
ARG PYTHON_VERSION=3.12
FROM python:${PYTHON_VERSION}-slim as base
# Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# PIP
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
# Create a non-privileged user that the app will run under.
# See <https://docs.docker.com/go/dockerfile-user-best-practices/>
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/appuser" \
--shell "/sbin/nologin" \
--uid "${UID}" \
appuser
################################
# PRODUCTION
# Final image used for runtime
################################
FROM base as production
ENV TZ=America/Los_Angeles
WORKDIR /app
# Copy the built Pex file from the builder stage
COPY dist/healthdash_app.pex /app/healthdash_app.pex
# Switch to the non-privileged user to run the application.
USER appuser
# Expose the port for the Streamlit app
EXPOSE 80
# Run the Pex file to launch the Streamlit app
ENTRYPOINT ["/app/healthdash_app.pex", "healthdash/NOC_Pod_Overview.py", "--server.port=80", "--server.address=0.0.0.0"]
And this is my BUILD file:
python_sources(
name="healthdash_sources",
sources=["healthdash/**/*.py"],
)
pex_binary(
name="healthdash_app",
entry_point="streamlit.cli:main",
dependencies=[
":healthdash_sources",
],
)
docker_image(
name="healthdash_docker_image",
source="Dockerfile",
image_tags=["latest"],
)
But I keep getting an error like this:
Dockerfile:39
--------------------
37 |
38 | # Copy the built Pex file from the builder stage
39 | >>> COPY ./dist/healthdash_app.pex /app/healthdash_app.pex
40 |
41 | # Switch to the non-privileged user to run the application.
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref d9275964-4810-4dbf-98d1-c5af966bbab5::hkmghmks1fbol8tsee5fctfla: "/dist/healthdash_app.pex": not found
I tried building the pex file first, although my understanding was that it should be doing that itself, and it still didn't work. Maybe I'm misunderstanding the context that the package
command runs in?alert-beard-13327
10/21/2024, 8:17 PMapp.healthdash/healthdash_app.pex
, but I'd still like to understand why that worked vs providing the path directly.elegant-florist-94385
10/22/2024, 3:05 PMdist
to something else. All your dockerfiles would break).
Specifying the output as if rooted at the output folder ensures that pants can always find it.