thinhvv commited on
Commit
c8bdbce
·
verified ·
1 Parent(s): e5061be

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -72
Dockerfile CHANGED
@@ -1,69 +1,3 @@
1
- # ----------------------------
2
- # Builder Stage
3
- # ----------------------------
4
- 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 (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
- sh -c " \
19
- GIT_USER=\$(cat /run/secrets/GIT_USER); \
20
- GIT_TOKEN=\$(cat /run/secrets/GIT_TOKEN); \
21
- REPO=\$(cat /run/secrets/GIT_REPO); \
22
- echo 'Cloning repository:' \$REPO; \
23
- git clone https://\$GIT_USER:\$GIT_TOKEN@github.com/\$GIT_USER/\$REPO.git; \
24
- "
25
-
26
- # Debug: List directories under /build.
27
- RUN echo "Directory structure in /build:" && ls -la /build
28
-
29
- # 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); \
33
- echo 'Copying /build/'\$REPO'/private_repo to /build/private_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
-
44
- # Debug: List contents of /build/private_repo to verify required files are present.
45
- RUN echo "Contents of /build/private_repo:" && ls -la
46
-
47
- # Install Python dependencies from requirements.txt.
48
- RUN echo "Installing Python dependencies from requirements.txt:" && \
49
- pip install --no-cache-dir -r requirements.txt
50
-
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 " \
57
- echo 'Contents of /build/private_repo/packages:' && ls -la && \
58
- echo 'Installing custom packages in the following sequence:'; \
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
-
67
  # ----------------------------
68
  # Final Stage
69
  # ----------------------------
@@ -94,18 +28,26 @@ RUN if [ -f /usr/src/app/PACKAGE_SEQUENCE.txt ]; then \
94
  path="/usr/src/app/packages/$pkg"; \
95
  if [ -f "$path" ]; then \
96
  echo "Installing file $path"; \
97
- pip install --no-cache-dir "$path"; \
98
  elif [ -d "$path" ]; then \
99
  echo "Installing directory $path"; \
100
- pip install --no-cache-dir "$path"; \
101
  else \
102
- echo "Warning: $path is neither a file nor a directory"; \
103
  fi; \
104
  done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
105
  else \
106
  echo "PACKAGE_SEQUENCE.txt not found, skipping custom package installation"; \
107
  fi
108
 
 
 
 
 
 
 
 
 
109
  # --- Create shim for ta_inversion ---
110
  # If the package was installed as "ta-inversion" but you need to import it as "ta_inversion",
111
  # create a symlink in site-packages.
@@ -119,15 +61,20 @@ RUN if [ ! -d "/usr/local/lib/python3.10/site-packages/ta_inversion" ] && [ -d "
119
  # --- Create shim for portfolio_stats ---
120
  # If the package was installed as "portfolio-stats" but you need to import it as "portfolio_stats",
121
  # create a symlink in site-packages.
122
- RUN if [ ! -d "/usr/local/lib/python3.10/site-packages/portfolio_stats" ] && [ -d "/usr/local/lib/python3.10/site-packages/portfolio-stats" ]; then \
 
 
123
  echo "Creating symlink for portfolio_stats"; \
124
  ln -s /usr/local/lib/python3.10/site-packages/portfolio-stats /usr/local/lib/python3.10/site-packages/portfolio_stats; \
125
  else \
126
- echo "portfolio_stats shim not needed"; \
127
  fi
128
 
129
  # Log installed packages for debugging.
130
- RUN pip freeze > /tmp/pip_freeze.txt && echo "Installed packages:" && cat /tmp/pip_freeze.txt
 
 
 
131
 
132
  # Switch to a non-root user and adjust the PATH.
133
  RUN useradd -m -u 1000 user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # ----------------------------
2
  # Final Stage
3
  # ----------------------------
 
28
  path="/usr/src/app/packages/$pkg"; \
29
  if [ -f "$path" ]; then \
30
  echo "Installing file $path"; \
31
+ pip install --no-cache-dir "$path" || echo "Failed to install $path"; \
32
  elif [ -d "$path" ]; then \
33
  echo "Installing directory $path"; \
34
+ pip install --no-cache-dir "$path" || echo "Failed to install $path"; \
35
  else \
36
+ echo "Warning: $path is neither a file nor a directory, skipping"; \
37
  fi; \
38
  done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
39
  else \
40
  echo "PACKAGE_SEQUENCE.txt not found, skipping custom package installation"; \
41
  fi
42
 
43
+ # Explicitly install portfolio-stats if it exists as a directory with setup.py
44
+ RUN if [ -d "/usr/src/app/portfolio-stats" ] && [ -f "/usr/src/app/portfolio-stats/setup.py" ]; then \
45
+ echo "Explicitly installing /usr/src/app/portfolio-stats"; \
46
+ pip install --no-cache-dir /usr/src/app/portfolio-stats || echo "Failed to install portfolio-stats"; \
47
+ else \
48
+ echo "portfolio-stats directory or setup.py not found, skipping explicit install"; \
49
+ fi
50
+
51
  # --- Create shim for ta_inversion ---
52
  # If the package was installed as "ta-inversion" but you need to import it as "ta_inversion",
53
  # create a symlink in site-packages.
 
61
  # --- Create shim for portfolio_stats ---
62
  # If the package was installed as "portfolio-stats" but you need to import it as "portfolio_stats",
63
  # create a symlink in site-packages.
64
+ RUN echo "Checking portfolio_stats installation:" && \
65
+ ls -la /usr/local/lib/python3.10/site-packages/portfolio* 2>/dev/null || echo "No portfolio* packages found in site-packages"; \
66
+ if [ ! -d "/usr/local/lib/python3.10/site-packages/portfolio_stats" ] && [ -d "/usr/local/lib/python3.10/site-packages/portfolio-stats" ]; then \
67
  echo "Creating symlink for portfolio_stats"; \
68
  ln -s /usr/local/lib/python3.10/site-packages/portfolio-stats /usr/local/lib/python3.10/site-packages/portfolio_stats; \
69
  else \
70
+ echo "portfolio_stats shim not needed or already exists"; \
71
  fi
72
 
73
  # Log installed packages for debugging.
74
+ RUN pip freeze > /tmp/pip_freeze.txt && \
75
+ echo "Installed packages:" && cat /tmp/pip_freeze.txt && \
76
+ echo "Checking site-packages for portfolio_stats:" && \
77
+ ls -la /usr/local/lib/python3.10/site-packages/portfolio* 2>/dev/null || echo "No portfolio* packages found"
78
 
79
  # Switch to a non-root user and adjust the PATH.
80
  RUN useradd -m -u 1000 user