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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -39
Dockerfile CHANGED
@@ -3,9 +3,11 @@
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
 
@@ -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 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
 
40
- # ----------------------------
41
- # Install Custom Packages
42
- # ----------------------------
43
- # PACKAGE_SEQUENCE is a newline-separated list of tar.gz file patterns.
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
- # (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"]
 
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"]