thinhvv commited on
Commit
d3a373e
·
verified ·
1 Parent(s): 8aeca77

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +79 -3
Dockerfile CHANGED
@@ -1,3 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # ----------------------------
2
  # Final Stage
3
  # ----------------------------
@@ -16,7 +82,7 @@ COPY --from=builder /build/private_repo/ /usr/src/app/
16
  # Also copy the PACKAGE_SEQUENCE file.
17
  COPY --from=builder /build/PACKAGE_SEQUENCE.txt /usr/src/app/PACKAGE_SEQUENCE.txt
18
 
19
- # Reinstall Python dependencies in the final stage.
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # Reinstall custom packages in the specified sequence.
@@ -32,9 +98,19 @@ RUN /bin/sh -c " \
32
  done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
33
  fi"
34
 
 
 
 
 
 
 
 
 
 
 
35
  # --- Create shim for portfolio_stats ---
36
- # If the package was installed as "portfolio-stats" but is expected as "portfolio_stats",
37
- # create a symbolic link in the site-packages directory.
38
  RUN if [ ! -d "/usr/local/lib/python3.10/site-packages/portfolio_stats" ] && [ -d "/usr/local/lib/python3.10/site-packages/portfolio-stats" ]; then \
39
  echo "Creating symlink for portfolio_stats"; \
40
  ln -s /usr/local/lib/python3.10/site-packages/portfolio-stats /usr/local/lib/python3.10/site-packages/portfolio_stats; \
 
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
  # ----------------------------
 
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 in the specified sequence.
 
98
  done < /usr/src/app/PACKAGE_SEQUENCE.txt; \
99
  fi"
100
 
101
+ # --- Create shim for ta_inversion ---
102
+ # If the package was installed as "ta-inversion" but you need to import it as "ta_inversion",
103
+ # create a symlink in site-packages.
104
+ RUN if [ ! -d "/usr/local/lib/python3.10/site-packages/ta_inversion" ] && [ -d "/usr/local/lib/python3.10/site-packages/ta-inversion" ]; then \
105
+ echo "Creating symlink for ta_inversion"; \
106
+ ln -s /usr/local/lib/python3.10/site-packages/ta-inversion /usr/local/lib/python3.10/site-packages/ta_inversion; \
107
+ else \
108
+ echo "ta_inversion shim not needed"; \
109
+ fi
110
+
111
  # --- Create shim for portfolio_stats ---
112
+ # If the package was installed as "portfolio-stats" but you need to import it as "portfolio_stats",
113
+ # create a symlink in site-packages.
114
  RUN if [ ! -d "/usr/local/lib/python3.10/site-packages/portfolio_stats" ] && [ -d "/usr/local/lib/python3.10/site-packages/portfolio-stats" ]; then \
115
  echo "Creating symlink for portfolio_stats"; \
116
  ln -s /usr/local/lib/python3.10/site-packages/portfolio-stats /usr/local/lib/python3.10/site-packages/portfolio_stats; \