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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -15
Dockerfile CHANGED
@@ -5,13 +5,13 @@ FROM python:3.10-slim as builder
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,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 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); \
@@ -76,29 +76,28 @@ RUN apt-get update && \
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
@@ -117,4 +116,4 @@ WORKDIR /usr/src/app
117
  RUN echo "Final working directory contents:" && ls -la
118
 
119
  # Start the Streamlit app.
120
- CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.port", "8501"]
 
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
  # 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); \
 
76
  apt-get install -y git && \
77
  rm -rf /var/lib/apt/lists/*
78
 
79
+ # Copy the entire fixed private_repo folder from the builder stage.
80
  COPY --from=builder /build/private_repo/ /usr/src/app/
81
 
82
+ # Copy the saved 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 in the specified sequence.
89
+ RUN /bin/sh -c "if [ -f /usr/src/app/PACKAGE_SEQUENCE.txt ]; then \
90
+ echo 'Re-installing custom packages in sequence:'; \
 
91
  while IFS= read -r pkg; do \
92
+ echo 'Installing custom package pattern:' \$pkg; \
93
  for file in /usr/src/app/packages/\$pkg; do \
94
+ echo 'Installing package file:' \$file; \
95
+ pip install --no-cache-dir \"\$file\"; \
96
  done; \
97
  done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
98
+ fi"
99
 
100
+ # Switch to a non-root user and adjust the PATH.
101
  RUN useradd -m -u 1000 user
102
  USER user
103
  ENV HOME /home/user
 
116
  RUN echo "Final working directory contents:" && ls -la
117
 
118
  # Start the Streamlit app.
119
+ CMD ["streamlit", "run", "st_app.py", "--server.headless", "true", "--server.port", "8501"]