BinaryONe commited on
Commit
6bf6112
·
1 Parent(s): 92edd0d

Nginx Changes-Over Alpine

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -38
Dockerfile CHANGED
@@ -1,49 +1,34 @@
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 openrc
6
 
7
- # Create a group and user
8
- #RUN addgroup -S appgroup && adduser -S appuser -G appgroup
9
- RUN adduser -D -g 'user' user
10
-
11
- # Set working directory
12
  WORKDIR /app
13
 
14
- # Copy requirements and install in ONE combined RUN command
15
- COPY requirements.txt /app/
16
- RUN python3 -m venv /app/venv && \
17
- /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
18
- /app/venv/bin/pip install --no-cache-dir -r requirements.txt && \
19
- /app/venv/bin/pip list
20
- # Verify installation WITHIN THE SAME RUN COMMAND
21
-
22
- # Copy the rest of the application code
23
- COPY . /app
24
 
25
- #You may want to make backup of original nginx.conf file before writting your own
26
- RUN mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
 
 
 
27
 
28
- # Copy Nginx config
29
- #COPY www.privateone-teleapi.hf.space.conf /etc/nginx/conf.d/www.privateone-teleapi.hf.space.conf
30
- COPY nginx.conf /etc/nginx/nginx.conf
31
 
32
- # Print the configuration files to the console (good addition)
33
- RUN cat /etc/nginx/nginx.conf && echo "--------------------"
34
- # && cat /etc/nginx/conf.d/default.conf
35
 
36
- # Create necessary directories and set correct permissions (fix ownership)
37
- RUN mkdir -p /var/www/html /var/log/nginx /run/nginx /run/openrc && \
38
- chown -R nginx:nginx /var/lib/nginx /var/log/nginx /run/nginx && \
39
- chown -R user:user /app /var/www/html /var/lib/nginx && chmod -R 777 /app
40
 
41
- # Create the softlevel file (CRUCIAL FIX)
42
- RUN touch /run/openrc/softlevel
43
 
44
- # Switch to non-root user
45
- USER user
46
 
47
- # Start Nginx and your application (using exec and the correct Python path)
48
- CMD ["sh", "-c", "rc-service nginx reload"]
49
- #&& exec /app/venv/bin/python -u -m FileStream
 
1
+ FROM python:3.11
2
 
3
+ # Create and use a non-root user
4
+ RUN useradd -ms /bin/bash admin
 
5
 
6
+ # Set working directory for the application
 
 
 
 
7
  WORKDIR /app
8
 
9
+ # Copy only the necessary files first for better cache utilization
10
+ COPY requirements.txt /app/requirements.txt
 
 
 
 
 
 
 
 
11
 
12
+ # Install system dependencies and clean up in a single RUN step to reduce layers
13
+ RUN apt-get update -y && apt-get upgrade -y \
14
+ && apt-get install -y \
15
+ && apt-get clean \
16
+ && rm -rf /var/lib/apt/lists/*
17
 
18
+ # Install Python dependencies from the requirements file
19
+ RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
 
20
 
21
+ # Copy the rest of the application code after installing dependencies for better cache
22
+ COPY . /app
 
23
 
24
+ # Set ownership and permissions for the app directory
25
+ RUN chown -R admin:admin /app && chmod -R 777 /app
 
 
26
 
27
+ # Switch to the non-root user for better security
28
+ USER admin
29
 
30
+ # Expose the port the application will run on
31
+ EXPOSE 7860
32
 
33
+ # Command to run the application
34
+ CMD ["python", "-u", "-m", "FileStream"]