thinhvv commited on
Commit
b09f196
·
verified ·
1 Parent(s): b2d917f

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +65 -0
Dockerfile ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ----------------------------
2
+ # Builder Stage
3
+ # ----------------------------
4
+ FROM python:3.8.9 as builder
5
+
6
+ WORKDIR /build
7
+
8
+ # Install Git to clone the repository
9
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Build arguments for Git credentials and repository name
12
+ ARG GIT_USER
13
+ ARG GIT_TOKEN
14
+ ARG GIT_REPO
15
+
16
+ # Build argument for the package sequence (newline separated list)
17
+ ARG PACKAGE_SEQUENCE
18
+
19
+ # Clone the single private repository
20
+ RUN git clone https://${GIT_USER}:${GIT_TOKEN}@github.com/${GIT_USER}/${GIT_REPO}.git
21
+
22
+ # Save the repo name for later reference (optional)
23
+ RUN echo "${GIT_REPO}" > main_repo_dir.txt
24
+
25
+ # Install Python dependencies from requirements.txt
26
+ WORKDIR /build/${GIT_REPO}/private_repo
27
+ RUN pip install --no-cache-dir -r requirements.txt
28
+
29
+ # ----------------------------
30
+ # Install custom packages
31
+ # ----------------------------
32
+ WORKDIR /build/${GIT_REPO}/private_repo/packages
33
+ # Iterate through each line in PACKAGE_SEQUENCE and install the package accordingly
34
+ RUN echo "$PACKAGE_SEQUENCE" | while IFS= read -r pkg; do \
35
+ echo "Installing package: $pkg" && \
36
+ pip install --no-cache-dir $pkg; \
37
+ done
38
+
39
+ # ----------------------------
40
+ # Final Stage
41
+ # ----------------------------
42
+ FROM python:3.8.9
43
+
44
+ WORKDIR /app
45
+
46
+ # Copy the built repository from the builder stage
47
+ COPY --from=builder /build/${GIT_REPO}/private_repo /app
48
+
49
+ # Create and switch to a non-root user
50
+ RUN useradd -m -u 1000 user
51
+ USER user
52
+ ENV HOME /home/user
53
+ ENV PATH $HOME/.local/bin:$PATH
54
+
55
+ # Set working directory to where the Streamlit app (st_app.py) is located
56
+ WORKDIR $HOME/app
57
+
58
+ EXPOSE 8501
59
+
60
+ # Run the Streamlit app with typical container settings
61
+ CMD streamlit run st_app.py \
62
+ --server.headless true \
63
+ --server.enableCORS false \
64
+ --server.enableXsrfProtection false \
65
+ --server.fileWatcherType none