Spaces:
Build error

thinhvv commited on
Commit
cbb38a3
·
verified ·
1 Parent(s): 52a1b21

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -20
Dockerfile CHANGED
@@ -5,44 +5,43 @@ FROM python:3.10-slim as builder
5
 
6
  WORKDIR /build
7
 
8
- # Install git and other dependencies
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; ensure you pass this (e.g., internal_demo_signal_portfolio)
14
- ARG GIT_REPO
15
- RUN echo "Using GIT_REPO build argument: ${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 to verify clone
30
  RUN echo "Directory structure in /build:" && ls -la /build
31
 
32
- # Change into the cloned repository's private_repo directory using the build argument.
33
  WORKDIR /build/${GIT_REPO}/private_repo
34
 
35
- # Debug: List contents of private_repo to verify we're in the correct directory.
36
  RUN echo "Contents of /build/${GIT_REPO}/private_repo:" && ls -la
37
 
 
 
38
  # Install Python dependencies from requirements.txt
39
  RUN echo "Installing Python dependencies from requirements.txt:" && \
40
  pip install --no-cache-dir -r requirements.txt
41
 
42
  # ----------------------------
43
- # Install custom packages in order
44
  # ----------------------------
45
- # PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns.
46
  ARG PACKAGE_SEQUENCE
47
  WORKDIR /build/${GIT_REPO}/private_repo/packages
48
  RUN echo "Contents of /build/${GIT_REPO}/private_repo/packages:" && ls -la && \
@@ -66,11 +65,11 @@ RUN apt-get update && \
66
  rm -rf /var/lib/apt/lists/*
67
 
68
  # Copy the entire cloned repository from the builder stage
69
- COPY --from=builder /build/${GIT_REPO} /usr/src/app
 
70
 
71
- # Reassemble the main application by copying the private_repo folder into main_app.
72
- RUN cp -r /usr/src/app/${GIT_REPO}/private_repo /usr/src/app/main_app && \
73
- if [ -f /usr/src/app/main_app/requirements.txt ]; then \
74
  pip install --no-cache-dir -r /usr/src/app/main_app/requirements.txt; \
75
  fi
76
 
@@ -80,10 +79,10 @@ RUN chmod -R 777 /usr/src/app
80
  # Expose Streamlit's default port
81
  EXPOSE 8501
82
 
83
- # Set the working directory to where st_app.py is located (assumed in main_app)
84
  WORKDIR /usr/src/app/main_app
85
 
86
- # Debug: List files to verify st_app.py is present
87
  RUN echo "Contents of /usr/src/app/main_app:" && ls -la
88
 
89
  # Start the Streamlit app
 
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
+ # 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 && \
 
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
 
 
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