Update Dockerfile
Browse files- Dockerfile +37 -26
Dockerfile
CHANGED
|
@@ -3,12 +3,6 @@
|
|
| 3 |
# ----------------------------
|
| 4 |
FROM python:3.10-slim as builder
|
| 5 |
|
| 6 |
-
# Declare build arguments and immediately set them as environment variables
|
| 7 |
-
ARG GIT_REPO
|
| 8 |
-
ENV GIT_REPO=${GIT_REPO}
|
| 9 |
-
ARG PACKAGE_SEQUENCE
|
| 10 |
-
ENV PACKAGE_SEQUENCE=${PACKAGE_SEQUENCE}
|
| 11 |
-
|
| 12 |
WORKDIR /build
|
| 13 |
|
| 14 |
# Install git and other necessary packages
|
|
@@ -16,8 +10,11 @@ RUN apt-get update && \
|
|
| 16 |
apt-get install -y git && \
|
| 17 |
rm -rf /var/lib/apt/lists/*
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Clone the single private repository using secret mounts for credentials and repo name.
|
| 20 |
-
# The secret for GIT_REPO should contain the repository name (e.g., internal_demo_signal_portfolio)
|
| 21 |
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
| 22 |
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
|
| 23 |
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
|
@@ -29,14 +26,16 @@ RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
|
| 29 |
git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$REPO_NAME.git \
|
| 30 |
"
|
| 31 |
|
| 32 |
-
#
|
|
|
|
|
|
|
|
|
|
| 33 |
RUN echo "Directory structure in /build:" && ls -la /build
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
# With ENV GIT_REPO now set, this should correctly expand.
|
| 37 |
WORKDIR /build/${GIT_REPO}/private_repo
|
| 38 |
|
| 39 |
-
# Debug:
|
| 40 |
RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
|
| 41 |
|
| 42 |
# Install Python dependencies from requirements.txt
|
|
@@ -47,6 +46,7 @@ RUN echo "Installing Python dependencies from requirements.txt:" && \
|
|
| 47 |
# Install Custom Packages
|
| 48 |
# ----------------------------
|
| 49 |
# PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns.
|
|
|
|
| 50 |
WORKDIR /build/${GIT_REPO}/private_repo/packages
|
| 51 |
RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
|
| 52 |
echo "Installing custom packages in the following sequence:" && \
|
|
@@ -60,32 +60,43 @@ RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
|
|
| 60 |
# ----------------------------
|
| 61 |
FROM python:3.10-slim
|
| 62 |
|
|
|
|
| 63 |
WORKDIR /usr/src/app
|
| 64 |
|
| 65 |
-
#
|
| 66 |
RUN apt-get update && \
|
| 67 |
apt-get install -y git && \
|
| 68 |
rm -rf /var/lib/apt/lists/*
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
RUN
|
| 79 |
|
| 80 |
-
# Expose
|
| 81 |
EXPOSE 8501
|
| 82 |
|
| 83 |
# Set the working directory to where st_app.py is located.
|
| 84 |
-
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# Start the Streamlit app.
|
| 87 |
-
CMD streamlit run st_app.py
|
| 88 |
-
--server.headless true \
|
| 89 |
-
--server.enableCORS false \
|
| 90 |
-
--server.enableXsrfProtection false \
|
| 91 |
-
--server.fileWatcherType none
|
|
|
|
| 3 |
# ----------------------------
|
| 4 |
FROM python:3.10-slim as builder
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
WORKDIR /build
|
| 7 |
|
| 8 |
# Install git and other necessary packages
|
|
|
|
| 10 |
apt-get install -y git && \
|
| 11 |
rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Build argument for repository name (e.g., internal_demo_signal_portfolio)
|
| 14 |
+
ARG GIT_REPO
|
| 15 |
+
# Note: The secret GIT_REPO (a file) should contain the same value.
|
| 16 |
+
|
| 17 |
# Clone the single private repository using secret mounts for credentials and repo name.
|
|
|
|
| 18 |
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
| 19 |
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
|
| 20 |
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
|
|
|
| 26 |
git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$REPO_NAME.git \
|
| 27 |
"
|
| 28 |
|
| 29 |
+
# Save the repository name for later reference.
|
| 30 |
+
RUN echo "$GIT_REPO" > main_repo_dir.txt
|
| 31 |
+
|
| 32 |
+
# Debug: List the /build directory structure
|
| 33 |
RUN echo "Directory structure in /build:" && ls -la /build
|
| 34 |
|
| 35 |
+
# Change into the private_repo directory inside the cloned repository.
|
|
|
|
| 36 |
WORKDIR /build/${GIT_REPO}/private_repo
|
| 37 |
|
| 38 |
+
# Debug: Verify the contents of private_repo (should show requirements.txt, st_app.py, packages, etc.)
|
| 39 |
RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
|
| 40 |
|
| 41 |
# Install Python dependencies from requirements.txt
|
|
|
|
| 46 |
# Install Custom Packages
|
| 47 |
# ----------------------------
|
| 48 |
# PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns.
|
| 49 |
+
ARG PACKAGE_SEQUENCE
|
| 50 |
WORKDIR /build/${GIT_REPO}/private_repo/packages
|
| 51 |
RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
|
| 52 |
echo "Installing custom packages in the following sequence:" && \
|
|
|
|
| 60 |
# ----------------------------
|
| 61 |
FROM python:3.10-slim
|
| 62 |
|
| 63 |
+
# Set working directory for final image
|
| 64 |
WORKDIR /usr/src/app
|
| 65 |
|
| 66 |
+
# Install git in the final image (if needed)
|
| 67 |
RUN apt-get update && \
|
| 68 |
apt-get install -y git && \
|
| 69 |
rm -rf /var/lib/apt/lists/*
|
| 70 |
|
| 71 |
+
# Copy entire /build directory from the builder stage into /usr/src/app
|
| 72 |
+
COPY --from=builder /build /usr/src/app
|
| 73 |
+
|
| 74 |
+
# (Optional) If your app requires additional installation, do it here.
|
| 75 |
+
# For example, if you have a dependency package named "numerology_reading":
|
| 76 |
+
# RUN pip install --no-cache-dir /usr/src/app/numerology_reading
|
| 77 |
+
|
| 78 |
+
# Ensure Python can find your code.
|
| 79 |
+
ENV PYTHONPATH="/usr/src/app:$PYTHONPATH"
|
| 80 |
|
| 81 |
+
# Read the main repository directory name and reassemble the app.
|
| 82 |
+
RUN MAIN_REPO_DIR=$(cat /usr/src/app/main_repo_dir.txt) && \
|
| 83 |
+
echo "Primary repository is \$MAIN_REPO_DIR" && \
|
| 84 |
+
cp -r /usr/src/app/\$MAIN_REPO_DIR/private_repo /usr/src/app/main_app && \
|
| 85 |
+
if [ -f /usr/src/app/main_app/requirements.txt ]; then \
|
| 86 |
+
pip install --no-cache-dir -r /usr/src/app/main_app/requirements.txt; \
|
| 87 |
+
fi
|
| 88 |
|
| 89 |
+
# Grant system-wide permissions to avoid any file access issues.
|
| 90 |
+
RUN chmod -R 777 /usr/src/app
|
| 91 |
|
| 92 |
+
# Expose the default Streamlit port.
|
| 93 |
EXPOSE 8501
|
| 94 |
|
| 95 |
# Set the working directory to where st_app.py is located.
|
| 96 |
+
WORKDIR /usr/src/app/main_app/private_repo
|
| 97 |
+
|
| 98 |
+
# Debug: List contents to confirm st_app.py is present.
|
| 99 |
+
RUN echo "Contents of /usr/src/app/main_app/private_repo:" && ls -la
|
| 100 |
|
| 101 |
# Start the Streamlit app.
|
| 102 |
+
CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.enableCORS", "false", "--server.enableXsrfProtection", "false", "--server.fileWatcherType", "none"]
|
|
|
|
|
|
|
|
|
|
|
|