E-slam commited on
Commit
6469dd0
·
verified ·
1 Parent(s): feef772

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -21
Dockerfile CHANGED
@@ -1,35 +1,41 @@
1
- FROM python:3.9
 
2
 
3
- # Create a new user and group and set them as the default user
4
- RUN groupadd -r appuser && useradd -r -g appuser appuser
 
5
 
6
- # Set the working directory
7
  WORKDIR /code
8
 
9
- # Copy the requirements file and install dependencies
10
  COPY ./requirements.txt /code/requirements.txt
 
 
11
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
 
13
- # Change ownership of the working directory
14
- RUN chown -R appuser:appuser /code
 
 
 
15
 
16
- # Switch to the new user
17
- USER appuser
18
 
19
- # Copy the rest of the application code
20
- COPY . .
 
21
 
22
- # Set the working directory to /code
23
- WORKDIR /code
 
24
 
25
- # Use a shell script to perform the git clone operation
26
- RUN echo "export gh_token=${gh_token}" > clone_repo.sh && \
27
- echo "git clone https://\${gh_token}@github.com/Eslam-Magdy-1297/ESearch_FletV01.git /code/ESearch_FletV01" >> clone_repo.sh && \
28
- chmod +x clone_repo.sh && \
29
- ./clone_repo.sh
30
 
31
- # Set the working directory to the cloned repository
32
- WORKDIR /code/ESearch_FletV01
33
 
34
- # Set the default command
35
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Stage 1: Build stage
2
+ FROM python:3.9 AS builder
3
 
4
+ # Install git
5
+ RUN apt-get update && \
6
+ apt-get install -y git
7
 
8
+ # Set working directory
9
  WORKDIR /code
10
 
11
+ # Copy requirements file
12
  COPY ./requirements.txt /code/requirements.txt
13
+
14
+ # Install Python dependencies
15
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
16
 
17
+ # Stage 2: Runtime stage
18
+ FROM python:3.9
19
+
20
+ # Set working directory
21
+ WORKDIR /code
22
 
23
+ # Copy from the builder stage
24
+ COPY --from=builder /code /code
25
 
26
+ # Set environment variable for GitHub token (replace with your actual token)
27
+ ARG GH_TOKEN
28
+ ENV gh_token=${GH_TOKEN}
29
 
30
+ # Clone your repository using the token
31
+ RUN url_with_token="https://[email protected]/yourusername/your-repo.git" && \
32
+ git clone $url_with_token /code
33
 
34
+ # Set the working directory to your cloned repository
35
+ WORKDIR /code
 
 
 
36
 
37
+ # Install remaining dependencies (if any)
38
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
39
 
40
+ # Command to run your application
41
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]