thinhvv commited on
Commit
e2b3833
·
verified ·
1 Parent(s): d77085e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -50
Dockerfile CHANGED
@@ -3,42 +3,37 @@
3
  # ----------------------------
4
  FROM python:3.10-slim as builder
5
 
 
 
 
 
6
  WORKDIR /build
7
 
8
- # Install git and other necessary packages
9
  RUN apt-get update && \
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 \
21
- /bin/sh -c " \
22
- GIT_USER=\$(cat /run/secrets/GIT_USER); \
23
- GIT_TOKEN=\$(cat /run/secrets/GIT_TOKEN); \
24
- REPO_NAME=\$(cat /run/secrets/GIT_REPO); \
25
- echo \"Cloning repository: \$REPO_NAME\"; \
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
42
  RUN echo "Installing Python dependencies from requirements.txt:" && \
43
  pip install --no-cache-dir -r requirements.txt
44
 
@@ -51,7 +46,7 @@ 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:" && \
53
  echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
54
- echo "Installing package: $pkg" && \
55
  pip install --no-cache-dir $pkg; \
56
  done
57
 
@@ -60,43 +55,28 @@ RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
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"]
 
3
  # ----------------------------
4
  FROM python:3.10-slim as builder
5
 
6
+ # Declare and persist the repository name.
7
+ ARG GIT_REPO
8
+ ENV GIT_REPO=${GIT_REPO}
9
+
10
  WORKDIR /build
11
 
12
+ # Install git and other necessary packages.
13
  RUN apt-get update && \
14
  apt-get install -y git && \
15
  rm -rf /var/lib/apt/lists/*
16
 
17
+ # Clone the single private repository using secret mounts for credentials and repository name.
18
+ # The secret for GIT_REPO should contain the repository name (e.g., internal_demo_signal_portfolio).
 
 
 
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 "Cloning repository: $REPO"; \
27
+ git clone https://$GIT_USER:$GIT_TOKEN@github.com/$GIT_USER/$REPO.git; \
28
+ '
29
+
30
+ # Change directory into the private_repo subfolder of the cloned repository.
 
 
 
 
 
 
31
  WORKDIR /build/${GIT_REPO}/private_repo
32
 
33
+ # Debug: List the contents of private_repo to verify that requirements.txt, st_app.py, etc. are present.
34
  RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
35
 
36
+ # Install Python dependencies from requirements.txt.
37
  RUN echo "Installing Python dependencies from requirements.txt:" && \
38
  pip install --no-cache-dir -r requirements.txt
39
 
 
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; \
51
  done
52
 
 
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
+ # (Optional) Install git in the final image if needed.
65
  RUN apt-get update && \
66
  apt-get install -y git && \
67
  rm -rf /var/lib/apt/lists/*
68
 
69
+ # Copy the entire contents of private_repo from the builder stage.
70
+ COPY --from=builder /build/${GIT_REPO}/private_repo/ /usr/src/app/
 
 
 
 
 
 
 
71
 
72
+ # Debug: List contents of the final working directory to verify that st_app.py and related files are present.
73
+ RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
 
 
 
 
 
74
 
75
+ # Expose Streamlit's default port.
 
 
 
76
  EXPOSE 8501
77
 
78
  # Set the working directory to where st_app.py is located.
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"]