Update Dockerfile
Browse files- Dockerfile +23 -25
Dockerfile
CHANGED
|
@@ -5,12 +5,13 @@ FROM python:3.10-slim as builder
|
|
| 5 |
|
| 6 |
WORKDIR /build
|
| 7 |
|
| 8 |
-
# Install git and
|
| 9 |
RUN apt-get update && \
|
| 10 |
apt-get install -y git && \
|
| 11 |
rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
# Clone the repository using secret mounts
|
|
|
|
| 14 |
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
| 15 |
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
|
| 16 |
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
|
@@ -25,7 +26,7 @@ RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
|
| 25 |
# Debug: List directories under /build.
|
| 26 |
RUN echo "Directory structure in /build:" && ls -la /build
|
| 27 |
|
| 28 |
-
# Use
|
| 29 |
RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
| 30 |
sh -c " \
|
| 31 |
REPO=\$(cat /run/secrets/GIT_REPO); \
|
|
@@ -33,10 +34,10 @@ RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
|
| 33 |
cp -r /build/\$REPO/private_repo /build/private_repo; \
|
| 34 |
"
|
| 35 |
|
| 36 |
-
# Change directory
|
| 37 |
WORKDIR /build/private_repo
|
| 38 |
|
| 39 |
-
# Debug: List
|
| 40 |
RUN echo "Contents of /build/private_repo:" && ls -la
|
| 41 |
|
| 42 |
# Install Python dependencies from requirements.txt.
|
|
@@ -46,8 +47,7 @@ RUN echo "Installing Python dependencies from requirements.txt:" && \
|
|
| 46 |
# ----------------------------
|
| 47 |
# Install Custom Packages
|
| 48 |
# ----------------------------
|
| 49 |
-
#
|
| 50 |
-
# The secret file PACKAGE_SEQUENCE should contain a newline-separated list of package patterns.
|
| 51 |
WORKDIR /build/private_repo/packages
|
| 52 |
RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
|
| 53 |
sh -c " \
|
|
@@ -56,7 +56,7 @@ RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
|
|
| 56 |
PACKAGE_SEQUENCE=\$(cat /run/secrets/PACKAGE_SEQUENCE); \
|
| 57 |
echo \"\$PACKAGE_SEQUENCE\"; \
|
| 58 |
echo \"\$PACKAGE_SEQUENCE\" | while IFS= read -r pkg; do \
|
| 59 |
-
echo 'Installing package:
|
| 60 |
pip install --no-cache-dir \$pkg; \
|
| 61 |
done; \
|
| 62 |
"
|
|
@@ -68,7 +68,7 @@ FROM python:3.10-slim
|
|
| 68 |
|
| 69 |
WORKDIR /usr/src/app
|
| 70 |
|
| 71 |
-
# Install git
|
| 72 |
RUN apt-get update && \
|
| 73 |
apt-get install -y git && \
|
| 74 |
rm -rf /var/lib/apt/lists/*
|
|
@@ -76,30 +76,28 @@ RUN apt-get update && \
|
|
| 76 |
# Copy the entire fixed private_repo folder from the builder stage.
|
| 77 |
COPY --from=builder /build/private_repo/ /usr/src/app/
|
| 78 |
|
| 79 |
-
# Reinstall Python dependencies in the final stage.
|
| 80 |
-
# This ensures that streamlit (and all other dependencies) are installed.
|
| 81 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 82 |
|
| 83 |
-
# (Optional)
|
| 84 |
-
# For example, if your custom packages are not on PyPI, you might need to install them here.
|
| 85 |
-
# You can also run any additional installation steps if needed.
|
| 86 |
|
| 87 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
|
| 89 |
|
| 90 |
-
# Expose
|
| 91 |
EXPOSE 8501
|
| 92 |
|
| 93 |
-
# Set
|
| 94 |
WORKDIR /usr/src/app
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
RUN echo "
|
| 98 |
|
| 99 |
# Start the Streamlit app.
|
| 100 |
-
CMD streamlit run st_app.py
|
| 101 |
-
--server.headless true \
|
| 102 |
-
--server.enableCORS false \
|
| 103 |
-
--server.enableXsrfProtection false \
|
| 104 |
-
--server.fileWatcherType none \
|
| 105 |
-
--server.port 8501
|
|
|
|
| 5 |
|
| 6 |
WORKDIR /build
|
| 7 |
|
| 8 |
+
# Install git and required packages.
|
| 9 |
RUN apt-get update && \
|
| 10 |
apt-get install -y git && \
|
| 11 |
rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Clone the repository using secret mounts.
|
| 14 |
+
# Secrets: GIT_USER, GIT_TOKEN, GIT_REPO (the latter contains the repository name, e.g., internal_demo_signal_portfolio)
|
| 15 |
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
| 16 |
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
|
| 17 |
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
|
|
|
| 26 |
# Debug: List directories under /build.
|
| 27 |
RUN echo "Directory structure in /build:" && ls -la /build
|
| 28 |
|
| 29 |
+
# Use secret mount to read the repository name and copy the private_repo folder to a fixed location.
|
| 30 |
RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
| 31 |
sh -c " \
|
| 32 |
REPO=\$(cat /run/secrets/GIT_REPO); \
|
|
|
|
| 34 |
cp -r /build/\$REPO/private_repo /build/private_repo; \
|
| 35 |
"
|
| 36 |
|
| 37 |
+
# Change directory to the fixed location.
|
| 38 |
WORKDIR /build/private_repo
|
| 39 |
|
| 40 |
+
# Debug: List contents of /build/private_repo to verify required files are present.
|
| 41 |
RUN echo "Contents of /build/private_repo:" && ls -la
|
| 42 |
|
| 43 |
# Install Python dependencies from requirements.txt.
|
|
|
|
| 47 |
# ----------------------------
|
| 48 |
# Install Custom Packages
|
| 49 |
# ----------------------------
|
| 50 |
+
# The secret PACKAGE_SEQUENCE is a newline‐separated list of tar.gz file patterns.
|
|
|
|
| 51 |
WORKDIR /build/private_repo/packages
|
| 52 |
RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
|
| 53 |
sh -c " \
|
|
|
|
| 56 |
PACKAGE_SEQUENCE=\$(cat /run/secrets/PACKAGE_SEQUENCE); \
|
| 57 |
echo \"\$PACKAGE_SEQUENCE\"; \
|
| 58 |
echo \"\$PACKAGE_SEQUENCE\" | while IFS= read -r pkg; do \
|
| 59 |
+
echo 'Installing package:' \$pkg; \
|
| 60 |
pip install --no-cache-dir \$pkg; \
|
| 61 |
done; \
|
| 62 |
"
|
|
|
|
| 68 |
|
| 69 |
WORKDIR /usr/src/app
|
| 70 |
|
| 71 |
+
# Install git and any necessary system dependencies.
|
| 72 |
RUN apt-get update && \
|
| 73 |
apt-get install -y git && \
|
| 74 |
rm -rf /var/lib/apt/lists/*
|
|
|
|
| 76 |
# Copy the entire fixed private_repo folder from the builder stage.
|
| 77 |
COPY --from=builder /build/private_repo/ /usr/src/app/
|
| 78 |
|
| 79 |
+
# Reinstall Python dependencies in the final stage to ensure a clean environment (and that streamlit is available).
|
|
|
|
| 80 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 81 |
|
| 82 |
+
# (Optional) If custom packages aren’t in requirements.txt, you can re-install them here if needed.
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
# Switch to a non-root user and adjust the PATH.
|
| 85 |
+
RUN useradd -m -u 1000 user
|
| 86 |
+
USER user
|
| 87 |
+
ENV HOME /home/user
|
| 88 |
+
ENV PATH $HOME/.local/bin:$PATH
|
| 89 |
+
|
| 90 |
+
# Debug: List contents of /usr/src/app to verify st_app.py and other files.
|
| 91 |
RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
|
| 92 |
|
| 93 |
+
# Expose port 8501.
|
| 94 |
EXPOSE 8501
|
| 95 |
|
| 96 |
+
# Set working directory to where st_app.py is located.
|
| 97 |
WORKDIR /usr/src/app
|
| 98 |
|
| 99 |
+
# Debug: List files to confirm the entry point.
|
| 100 |
+
RUN echo "Final working directory contents:" && ls -la
|
| 101 |
|
| 102 |
# Start the Streamlit app.
|
| 103 |
+
CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.port", "8501"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|