BinaryONe commited on
Commit
42d9b14
·
1 Parent(s): e95fa34

Nginx Changes

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -40
Dockerfile CHANGED
@@ -1,62 +1,37 @@
1
  FROM alpine:latest
2
 
3
- # Install system dependencies, including shadow-utils for adduser
4
  RUN apk update && apk upgrade && \
5
- apk add --no-cache nginx python3 python3-dev py3-pip build-base libffi-dev openssl-dev shadow gcc musl-dev
6
-
7
- # Install python/pip
8
- #ENV PYTHONUNBUFFERED=1
9
- #RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
10
- #RUN python3 -m ensurepip
11
- #RUN pip3 install --no-cache --upgrade pip setuptools
12
 
13
  # Create a group and user
14
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
15
 
16
- # Set working directory for the application
17
  WORKDIR /app
18
 
19
- COPY nginx.conf /etc/nginx/conf.d/default.conf
20
- # Copy only the necessary files first for better cache utilization
21
- COPY requirements.txt /app/requirements.txt
22
-
23
- # Copy the rest of the application code after installing dependencies for better cache
24
- COPY . /app
25
-
26
- # Create a virtual environment within the container
27
- #RUN python3 -m venv /app/venv
28
-
29
- # Create and activate the virtual environment AND install requirements in ONE RUN command
30
  RUN python3 -m venv /app/venv && \
31
  /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
32
- /app/venv/bin/pip install --no-cache-dir -r /app/requirements.txt
 
33
 
34
- #Before
35
- RUN python --version && pip3 list
36
-
37
- # Activate the virtual environment (important!)
38
- RUN source /app/venv/bin/activate
39
- RUN pip install --no-cache-dir -r /app/requirements.txt
40
-
41
- #After
42
- RUN python --version && pip3 list
43
 
44
- # Install Python dependencies from the requirements file within the virtual environment
45
- #RUN py3-pip install --no-cache-dir --upgrade -r requirements.txt
46
- #RUN pip install -r requirements.txt
47
 
48
  # Create necessary directories and set correct permissions
49
  RUN mkdir -p /var/www/html /var/log/nginx && \
50
  chown -R nginx:nginx /var/log/nginx && \
51
- chown -R appuser:appgroup /app /var/www/html /var/log/nginx
52
-
53
- # Set ownership of the app directory
54
- #RUN chown -R appuser:appgroup /app
55
 
56
- # Switch to the non-root user
57
  USER appuser
58
 
59
  EXPOSE 7860
60
 
61
- # Start Nginx and the AIOHTTP app (using exec for proper signal handling)
62
- CMD ["sh", "-c", "exec python -u -m FileStream & nginx -g 'daemon off;'"]
 
1
  FROM alpine:latest
2
 
3
+ # Install system dependencies
4
  RUN apk update && apk upgrade && \
5
+ apk add --no-cache nginx python3 python3-dev py3-pip build-base libffi-dev openssl-dev shadow gcc musl-dev ca-certificates
 
 
 
 
 
 
6
 
7
  # Create a group and user
8
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
9
 
10
+ # Set working directory
11
  WORKDIR /app
12
 
13
+ # Copy requirements and install in ONE combined RUN command
14
+ COPY requirements.txt /app/
 
 
 
 
 
 
 
 
 
15
  RUN python3 -m venv /app/venv && \
16
  /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
17
+ /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \
18
+ /app/venv/bin/pip list # Verify installation WITHIN THE SAME RUN COMMAND
19
 
20
+ # Copy the rest of the application code
21
+ COPY . /app
 
 
 
 
 
 
 
22
 
23
+ # Copy Nginx config
24
+ COPY nginx.conf /etc/nginx/conf.d/default.conf
 
25
 
26
  # Create necessary directories and set correct permissions
27
  RUN mkdir -p /var/www/html /var/log/nginx && \
28
  chown -R nginx:nginx /var/log/nginx && \
29
+ chown -R appuser:appgroup /app /var/www/html
 
 
 
30
 
31
+ # Switch to non-root user
32
  USER appuser
33
 
34
  EXPOSE 7860
35
 
36
+ # Start Nginx and your application (using exec and the correct Python path)
37
+ CMD ["sh", "-c", "exec /app/venv/bin/python -u -m FileStream & nginx -g 'daemon off;'"]