thinhvv commited on
Commit
9b3d64b
·
verified ·
1 Parent(s): 6ca5465

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -19
Dockerfile CHANGED
@@ -3,12 +3,6 @@
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
 
14
  # Install git and other necessary packages.
@@ -17,7 +11,6 @@ RUN apt-get update && \
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 \
@@ -32,23 +25,32 @@ RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
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; \
@@ -61,20 +63,22 @@ 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"]
 
3
  # ----------------------------
4
  FROM python:3.10-slim as builder
5
 
 
 
 
 
 
 
6
  WORKDIR /build
7
 
8
  # Install git and other necessary packages.
 
11
  rm -rf /var/lib/apt/lists/*
12
 
13
  # Clone the repository using secret mounts for credentials and repository name.
 
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
  # Debug: List directories under /build.
26
  RUN echo "Directory structure in /build:" && ls -la /build
27
 
28
+ # Use a secret mount to read the repository name again and copy the private_repo folder to a fixed location.
29
+ RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
30
+ sh -c " \
31
+ REPO=\$(cat /run/secrets/GIT_REPO); \
32
+ echo 'Copying /build/'\$REPO'/private_repo to /build/private_repo'; \
33
+ cp -r /build/\$REPO/private_repo /build/private_repo; \
34
+ "
35
 
36
+ # Change directory into the fixed location.
37
  WORKDIR /build/private_repo
38
 
39
+ # Debug: List the contents to verify that requirements.txt, st_app.py, etc. are present.
40
  RUN echo "Contents of /build/private_repo:" && ls -la
41
 
42
+ # Install Python dependencies from requirements.txt.
43
+ RUN echo "Installing Python dependencies from requirements.txt:" && \
44
  pip install --no-cache-dir -r requirements.txt
45
 
46
+ # ----------------------------
47
+ # Install Custom Packages
48
+ # ----------------------------
49
+ # PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns.
50
+ ARG PACKAGE_SEQUENCE
51
  WORKDIR /build/private_repo/packages
52
  RUN echo "Contents of /build/private_repo/packages:" && ls -la && \
53
+ echo "Installing custom packages in the following sequence:" && \
54
  echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
55
  echo "Installing package: $pkg"; \
56
  pip install --no-cache-dir $pkg; \
 
63
 
64
  WORKDIR /usr/src/app
65
 
66
+ # (Optional) 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 the fixed private_repo folder from the builder stage.
72
  COPY --from=builder /build/private_repo/ /usr/src/app/
73
 
74
+ # Debug: List contents of the final working directory to verify that st_app.py and related files are present.
75
  RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
76
 
77
  # Expose the default Streamlit port.
78
  EXPOSE 8501
79
 
80
+ # Set the working directory to where st_app.py is located.
81
  WORKDIR /usr/src/app
82
+
83
+ # Start the Streamlit app.
84
  CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.enableCORS", "false", "--server.enableXsrfProtection", "false", "--server.fileWatcherType", "none"]