Update Dockerfile
Browse files- Dockerfile +37 -39
Dockerfile
CHANGED
|
@@ -3,9 +3,11 @@
|
|
| 3 |
# ----------------------------
|
| 4 |
FROM python:3.10-slim as builder
|
| 5 |
|
| 6 |
-
# Declare and
|
| 7 |
ARG GIT_REPO
|
|
|
|
| 8 |
ENV GIT_REPO=${GIT_REPO}
|
|
|
|
| 9 |
|
| 10 |
WORKDIR /build
|
| 11 |
|
|
@@ -14,37 +16,39 @@ RUN apt-get update && \
|
|
| 14 |
apt-get install -y git && \
|
| 15 |
rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
# Clone the
|
| 18 |
-
#
|
| 19 |
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
|
| 20 |
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
|
| 21 |
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
|
| 22 |
-
sh -c
|
| 23 |
-
GIT_USER=$(cat /run/secrets/GIT_USER); \
|
| 24 |
-
GIT_TOKEN=$(cat /run/secrets/GIT_TOKEN); \
|
| 25 |
-
REPO=$(cat /run/secrets/GIT_REPO); \
|
| 26 |
-
echo
|
| 27 |
-
git clone https://$GIT_USER:$GIT_TOKEN@github.com/$GIT_USER/$REPO.git; \
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
RUN
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
pip install --no-cache-dir -r requirements.txt
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
ARG PACKAGE_SEQUENCE
|
| 45 |
-
WORKDIR /build/${GIT_REPO}/private_repo/packages
|
| 46 |
-
RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
|
| 47 |
-
echo "Installing custom packages in the following sequence:" && \
|
| 48 |
echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
|
| 49 |
echo "Installing package: $pkg"; \
|
| 50 |
pip install --no-cache-dir $pkg; \
|
|
@@ -55,28 +59,22 @@ RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
|
|
| 55 |
# ----------------------------
|
| 56 |
FROM python:3.10-slim
|
| 57 |
|
| 58 |
-
# Bring the GIT_REPO argument into the final stage.
|
| 59 |
-
ARG GIT_REPO
|
| 60 |
-
ENV GIT_REPO=${GIT_REPO}
|
| 61 |
-
|
| 62 |
WORKDIR /usr/src/app
|
| 63 |
|
| 64 |
-
#
|
| 65 |
RUN apt-get update && \
|
| 66 |
apt-get install -y git && \
|
| 67 |
rm -rf /var/lib/apt/lists/*
|
| 68 |
|
| 69 |
-
# Copy the
|
| 70 |
-
COPY --from=builder /build/
|
| 71 |
|
| 72 |
-
# Debug: List contents of
|
| 73 |
RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
|
| 74 |
|
| 75 |
-
# Expose
|
| 76 |
EXPOSE 8501
|
| 77 |
|
| 78 |
-
# Set
|
| 79 |
WORKDIR /usr/src/app
|
| 80 |
-
|
| 81 |
-
# Start the Streamlit app.
|
| 82 |
CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.enableCORS", "false", "--server.enableXsrfProtection", "false", "--server.fileWatcherType", "none"]
|
|
|
|
| 3 |
# ----------------------------
|
| 4 |
FROM python:3.10-slim as builder
|
| 5 |
|
| 6 |
+
# Declare build arguments and immediately set as environment variables
|
| 7 |
ARG GIT_REPO
|
| 8 |
+
ARG PACKAGE_SEQUENCE
|
| 9 |
ENV GIT_REPO=${GIT_REPO}
|
| 10 |
+
ENV PACKAGE_SEQUENCE=${PACKAGE_SEQUENCE}
|
| 11 |
|
| 12 |
WORKDIR /build
|
| 13 |
|
|
|
|
| 16 |
apt-get install -y git && \
|
| 17 |
rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Clone the repository using secret mounts for credentials and repository name.
|
| 20 |
+
# Ensure your secret file for GIT_REPO contains 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 \
|
| 24 |
+
sh -c " \
|
| 25 |
+
GIT_USER=\$(cat /run/secrets/GIT_USER); \
|
| 26 |
+
GIT_TOKEN=\$(cat /run/secrets/GIT_TOKEN); \
|
| 27 |
+
REPO=\$(cat /run/secrets/GIT_REPO); \
|
| 28 |
+
echo 'Cloning repository:' \$REPO; \
|
| 29 |
+
git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$REPO.git; \
|
| 30 |
+
"
|
| 31 |
+
|
| 32 |
+
# Debug: List directories under /build.
|
| 33 |
+
RUN echo "Directory structure in /build:" && ls -la /build
|
| 34 |
+
|
| 35 |
+
# Copy the private_repo subdirectory to a fixed location (/build/private_repo)
|
| 36 |
+
RUN cp -r /build/${GIT_REPO}/private_repo /build/private_repo
|
| 37 |
+
|
| 38 |
+
# Change into the fixed directory.
|
| 39 |
+
WORKDIR /build/private_repo
|
| 40 |
+
|
| 41 |
+
# Debug: List the contents to verify that requirements.txt, st_app.py, etc. exist.
|
| 42 |
+
RUN echo "Contents of /build/private_repo:" && ls -la
|
| 43 |
+
|
| 44 |
+
# Install Python dependencies.
|
| 45 |
+
RUN echo "Installing dependencies from requirements.txt:" && \
|
| 46 |
pip install --no-cache-dir -r requirements.txt
|
| 47 |
|
| 48 |
+
# Install custom packages from the packages directory.
|
| 49 |
+
WORKDIR /build/private_repo/packages
|
| 50 |
+
RUN echo "Contents of /build/private_repo/packages:" && ls -la && \
|
| 51 |
+
echo "Installing custom packages (in provided sequence):" && \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
|
| 53 |
echo "Installing package: $pkg"; \
|
| 54 |
pip install --no-cache-dir $pkg; \
|
|
|
|
| 59 |
# ----------------------------
|
| 60 |
FROM python:3.10-slim
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
WORKDIR /usr/src/app
|
| 63 |
|
| 64 |
+
# Install git if needed.
|
| 65 |
RUN apt-get update && \
|
| 66 |
apt-get install -y git && \
|
| 67 |
rm -rf /var/lib/apt/lists/*
|
| 68 |
|
| 69 |
+
# Copy the fixed private_repo folder from builder.
|
| 70 |
+
COPY --from=builder /build/private_repo/ /usr/src/app/
|
| 71 |
|
| 72 |
+
# Debug: List contents of /usr/src/app.
|
| 73 |
RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
|
| 74 |
|
| 75 |
+
# Expose the default Streamlit port.
|
| 76 |
EXPOSE 8501
|
| 77 |
|
| 78 |
+
# Set working directory and run the Streamlit app.
|
| 79 |
WORKDIR /usr/src/app
|
|
|
|
|
|
|
| 80 |
CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.enableCORS", "false", "--server.enableXsrfProtection", "false", "--server.fileWatcherType", "none"]
|