thinhvv commited on
Commit
79c8c4f
·
verified ·
1 Parent(s): cbb38a3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -31
Dockerfile CHANGED
@@ -10,43 +10,44 @@ RUN apt-get update && \
10
  apt-get install -y git && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
- # Use secret mounts for Git credentials and repository name.
14
- # Note: Ensure the secret file for GIT_REPO 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 \
18
  /bin/sh -c " \
19
  GIT_USER=\$(cat /run/secrets/GIT_USER); \
20
  GIT_TOKEN=\$(cat /run/secrets/GIT_TOKEN); \
21
- GIT_REPO=\$(cat /run/secrets/GIT_REPO); \
22
- echo \"Cloning repository: \$GIT_REPO\"; \
23
- git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$GIT_REPO.git \
24
  "
25
 
26
- # Debug: List the directory structure at the /build level
27
  RUN echo "Directory structure in /build:" && ls -la /build
28
 
29
- # Set WORKDIR to the private_repo directory of the cloned repository
 
30
  WORKDIR /build/${GIT_REPO}/private_repo
31
 
32
- # Debug: List contents of private_repo to verify location and files
33
  RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
34
 
35
- # At this point, the directory should include:
36
- # - .streamlit, data, packages, panel, st_modules, requirements.txt, st_app.py, etc.
37
  # Install Python dependencies from requirements.txt
38
  RUN echo "Installing Python dependencies from requirements.txt:" && \
39
  pip install --no-cache-dir -r requirements.txt
40
 
41
  # ----------------------------
42
- # Install Custom Packages (if any)
43
  # ----------------------------
44
- # PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns in the order you want to install.
45
  ARG PACKAGE_SEQUENCE
46
  WORKDIR /build/${GIT_REPO}/private_repo/packages
47
- RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
48
  echo "Installing custom packages in the following sequence:" && \
49
- echo "$PACKAGE_SEQUENCE" && \
50
  echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
51
  echo "Installing package: $pkg" && \
52
  pip install --no-cache-dir $pkg; \
@@ -57,34 +58,26 @@ RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
57
  # ----------------------------
58
  FROM python:3.10-slim
59
 
60
- WORKDIR /usr/src/app
61
 
62
- # Install git in the final image (if needed)
63
  RUN apt-get update && \
64
  apt-get install -y git && \
65
  rm -rf /var/lib/apt/lists/*
66
 
67
- # Copy the entire cloned repository from the builder stage
68
- # We only need the private_repo folder as our main app.
69
- COPY --from=builder /build/${GIT_REPO}/private_repo /usr/src/app/main_app
70
 
71
- # (Optional) Re-install dependencies in the final image if necessary.
72
- RUN if [ -f /usr/src/app/main_app/requirements.txt ]; then \
73
- pip install --no-cache-dir -r /usr/src/app/main_app/requirements.txt; \
74
- fi
75
 
76
- # Grant system-wide permissions to avoid permission issues
77
- RUN chmod -R 777 /usr/src/app
78
 
79
  # Expose Streamlit's default port
80
  EXPOSE 8501
81
 
82
- # Set the working directory to where st_app.py is located in main_app
83
- WORKDIR /usr/src/app/main_app
84
-
85
- # Debug: List files to verify st_app.py and related files are present
86
- RUN echo "Contents of /usr/src/app/main_app:" && ls -la
87
-
88
  # Start the Streamlit app
89
  CMD streamlit run st_app.py \
90
  --server.headless true \
 
10
  apt-get install -y git && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
+ # Use a build argument for the repository name.
14
+ # This value must match the secret stored in GIT_REPO.
15
+ ARG GIT_REPO
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
+ GIT_REPO_SECRET=\$(cat /run/secrets/GIT_REPO); \
25
+ echo \"Cloning repository: \$GIT_REPO_SECRET\"; \
26
+ git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$GIT_REPO_SECRET.git \
27
  "
28
 
29
+ # Debug: List the directory structure in /build
30
  RUN echo "Directory structure in /build:" && ls -la /build
31
 
32
+ # Set WORKDIR to the private_repo folder inside the cloned repository.
33
+ # We use the build argument GIT_REPO for navigation.
34
  WORKDIR /build/${GIT_REPO}/private_repo
35
 
36
+ # Debug: List contents of private_repo to verify we are in the correct location.
37
  RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
38
 
 
 
39
  # Install Python dependencies from requirements.txt
40
  RUN echo "Installing Python dependencies from requirements.txt:" && \
41
  pip install --no-cache-dir -r requirements.txt
42
 
43
  # ----------------------------
44
+ # Install Custom Packages
45
  # ----------------------------
46
+ # PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns (in order)
47
  ARG PACKAGE_SEQUENCE
48
  WORKDIR /build/${GIT_REPO}/private_repo/packages
49
+ RUN echo "Contents of packages folder:" && ls -la && \
50
  echo "Installing custom packages in the following sequence:" && \
 
51
  echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
52
  echo "Installing package: $pkg" && \
53
  pip install --no-cache-dir $pkg; \
 
58
  # ----------------------------
59
  FROM python:3.10-slim
60
 
61
+ WORKDIR /app
62
 
63
+ # (Optional) Install git in the final image if needed
64
  RUN apt-get update && \
65
  apt-get install -y git && \
66
  rm -rf /var/lib/apt/lists/*
67
 
68
+ # Pass the GIT_REPO build argument to the final stage
69
+ ARG GIT_REPO
 
70
 
71
+ # Copy the entire private_repo folder from the builder stage into /app.
72
+ # This ensures that all content (st_app.py, requirements.txt, packages, etc.) is available.
73
+ COPY --from=builder /build/${GIT_REPO}/private_repo/ /app/
 
74
 
75
+ # Debug: List contents of the final working directory
76
+ RUN echo "Contents of /app:" && ls -la /app
77
 
78
  # Expose Streamlit's default port
79
  EXPOSE 8501
80
 
 
 
 
 
 
 
81
  # Start the Streamlit app
82
  CMD streamlit run st_app.py \
83
  --server.headless true \