thinhvv commited on
Commit
03edbe1
·
verified ·
1 Parent(s): 6424026

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -17
Dockerfile CHANGED
@@ -5,13 +5,13 @@ FROM python:3.10-slim as builder
5
 
6
  WORKDIR /build
7
 
8
- # Install git and required packages.
9
  RUN apt-get update && \
10
  apt-get install -y git && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
  # Clone the repository using secret mounts.
14
- # Secrets: GIT_USER, GIT_TOKEN, GIT_REPO (the latter 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 \
@@ -26,7 +26,7 @@ RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
26
  # Debug: List directories under /build.
27
  RUN echo "Directory structure in /build:" && ls -la /build
28
 
29
- # Use secret mount to read the repository name and copy the private_repo folder to a fixed location.
30
  RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
31
  sh -c " \
32
  REPO=\$(cat /run/secrets/GIT_REPO); \
@@ -34,6 +34,10 @@ RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
34
  cp -r /build/\$REPO/private_repo /build/private_repo; \
35
  "
36
 
 
 
 
 
37
  # Change directory to the fixed location.
38
  WORKDIR /build/private_repo
39
 
@@ -47,7 +51,6 @@ RUN echo "Installing Python dependencies from requirements.txt:" && \
47
  # ----------------------------
48
  # Install Custom Packages in Builder Stage
49
  # ----------------------------
50
- # The secret PACKAGE_SEQUENCE is a newline‐separated list of tar.gz file patterns.
51
  WORKDIR /build/private_repo/packages
52
  RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
53
  sh -c " \
@@ -56,8 +59,8 @@ RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
56
  PACKAGE_SEQUENCE=\$(cat /run/secrets/PACKAGE_SEQUENCE); \
57
  echo \"\$PACKAGE_SEQUENCE\"; \
58
  echo \"\$PACKAGE_SEQUENCE\" | while IFS= read -r pkg; do \
59
- echo 'Installing package:' \$pkg; \
60
- pip install --no-cache-dir \$pkg; \
61
  done; \
62
  "
63
 
@@ -73,28 +76,35 @@ RUN apt-get update && \
73
  apt-get install -y git && \
74
  rm -rf /var/lib/apt/lists/*
75
 
76
- # Copy the entire fixed private_repo folder from the builder stage.
77
  COPY --from=builder /build/private_repo/ /usr/src/app/
78
 
79
- # Reinstall Python dependencies in the final stage to ensure a clean environment (and that streamlit is available).
 
 
 
80
  RUN pip install --no-cache-dir -r requirements.txt
81
 
82
- # Re-install custom packages by scanning for any tar.gz files in the packages folder.
83
- RUN if [ -d /usr/src/app/packages ]; then \
84
- cd /usr/src/app/packages && \
85
- for pkg in *.tar.gz; do \
86
- echo "Installing custom package: $pkg" && \
87
- pip install --no-cache-dir "$pkg"; \
88
- done; \
 
 
 
 
89
  fi
90
 
91
- # Switch to a non-root user and adjust the PATH.
92
  RUN useradd -m -u 1000 user
93
  USER user
94
  ENV HOME /home/user
95
  ENV PATH $HOME/.local/bin:$PATH
96
 
97
- # Debug: List contents of /usr/src/app to verify st_app.py and other files.
98
  RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
99
 
100
  # Expose port 8501.
 
5
 
6
  WORKDIR /build
7
 
8
+ # Install git and necessary packages.
9
  RUN apt-get update && \
10
  apt-get install -y git && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
  # Clone the repository using secret mounts.
14
+ # Secrets: GIT_USER, GIT_TOKEN, GIT_REPO (the secret file GIT_REPO should contain 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 \
 
26
  # Debug: List directories under /build.
27
  RUN echo "Directory structure in /build:" && ls -la /build
28
 
29
+ # Use a secret mount to read GIT_REPO and copy the private_repo folder to a fixed location.
30
  RUN --mount=type=secret,id=GIT_REPO,mode=0444,required=true \
31
  sh -c " \
32
  REPO=\$(cat /run/secrets/GIT_REPO); \
 
34
  cp -r /build/\$REPO/private_repo /build/private_repo; \
35
  "
36
 
37
+ # Save the PACKAGE_SEQUENCE secret to a file for later use.
38
+ RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
39
+ sh -c " cat /run/secrets/PACKAGE_SEQUENCE > /build/PACKAGE_SEQUENCE.txt "
40
+
41
  # Change directory to the fixed location.
42
  WORKDIR /build/private_repo
43
 
 
51
  # ----------------------------
52
  # Install Custom Packages in Builder Stage
53
  # ----------------------------
 
54
  WORKDIR /build/private_repo/packages
55
  RUN --mount=type=secret,id=PACKAGE_SEQUENCE,mode=0444,required=true \
56
  sh -c " \
 
59
  PACKAGE_SEQUENCE=\$(cat /run/secrets/PACKAGE_SEQUENCE); \
60
  echo \"\$PACKAGE_SEQUENCE\"; \
61
  echo \"\$PACKAGE_SEQUENCE\" | while IFS= read -r pkg; do \
62
+ echo 'Installing package:' \$pkg; \
63
+ pip install --no-cache-dir \$pkg; \
64
  done; \
65
  "
66
 
 
76
  apt-get install -y git && \
77
  rm -rf /var/lib/apt/lists/*
78
 
79
+ # Copy the fixed private_repo folder from the builder stage.
80
  COPY --from=builder /build/private_repo/ /usr/src/app/
81
 
82
+ # Also copy the PACKAGE_SEQUENCE file.
83
+ COPY --from=builder /build/PACKAGE_SEQUENCE.txt /usr/src/app/PACKAGE_SEQUENCE.txt
84
+
85
+ # Reinstall Python dependencies in the final stage to ensure a clean environment.
86
  RUN pip install --no-cache-dir -r requirements.txt
87
 
88
+ # Reinstall custom packages using the saved PACKAGE_SEQUENCE file.
89
+ # This will iterate over each line (e.g., "lotus_data-*.tar.gz") and install matching files in the packages directory.
90
+ RUN if [ -f /usr/src/app/PACKAGE_SEQUENCE.txt ]; then \
91
+ echo "Re-installing custom packages in sequence:"; \
92
+ while IFS= read -r pkg; do \
93
+ echo "Installing custom package pattern: \$pkg"; \
94
+ for file in /usr/src/app/packages/\$pkg; do \
95
+ echo "Installing package file: \$file"; \
96
+ pip install --no-cache-dir "\$file"; \
97
+ done; \
98
+ done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
99
  fi
100
 
101
+ # Switch to a non-root user and set PATH.
102
  RUN useradd -m -u 1000 user
103
  USER user
104
  ENV HOME /home/user
105
  ENV PATH $HOME/.local/bin:$PATH
106
 
107
+ # Debug: List contents of /usr/src/app to verify that st_app.py and other files are present.
108
  RUN echo "Contents of /usr/src/app:" && ls -la /usr/src/app
109
 
110
  # Expose port 8501.