BinaryONe commited on
Commit
b9dcb4f
·
1 Parent(s): 5dac619

Nginx Changes

Browse files
Files changed (5) hide show
  1. Dockerfile +25 -5
  2. Dockerfile copy +34 -0
  3. FileStream/__main__.py +1 -1
  4. FileStream/config.py +1 -0
  5. ngnix.conf +20 -0
Dockerfile CHANGED
@@ -1,7 +1,7 @@
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
@@ -21,14 +21,34 @@ RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
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"]
 
1
  FROM python:3.11
2
 
3
  # Create and use a non-root user
4
+ RUN useradd -ms /bin/bash appuser
5
 
6
  # Set working directory for the application
7
  WORKDIR /app
 
21
  # Copy the rest of the application code after installing dependencies for better cache
22
  COPY . /app
23
 
24
+ FROM nginx:alpine
25
+
26
+ COPY --from=builder /app /app
27
+
28
+ COPY nginx.conf /etc/nginx/conf.d/default.conf
29
+
30
+ # Create a non-root user and group
31
+ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
32
+
33
+ WORKDIR /app
34
+
35
+ RUN chown -R appuser:appgroup /app
36
+
37
+ USER appuser
38
+
39
+ EXPOSE 7860
40
+
41
+ # Start Nginx and the AIOHTTP app
42
+ CMD ["sh", "-c", "python -u -m FileStream & nginx -g 'daemon off;'"]
43
+
44
  # Set ownership and permissions for the app directory
45
+ #RUN chown -R admin:admin /app && chmod -R 777 /app
46
 
47
  # Switch to the non-root user for better security
48
+ #USER admin
49
 
50
  # Expose the port the application will run on
51
+ #EXPOSE 7860
52
 
53
  # Command to run the application
54
+ #CMD ["python", "-u", "-m", "FileStream"]
Dockerfile copy ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]
FileStream/__main__.py CHANGED
@@ -56,7 +56,7 @@ async def start_services():
56
 
57
  print("--------------------- Initializing Web Server ---------------------")
58
  await server.setup() # Setup the web server
59
- await web.TCPSite(server, Server.BIND_ADDRESS, Server.PORT).start()
60
  print("------------------------------ DONE ------------------------------\n\n")
61
 
62
  # Start the background task to clear inactive clients after web server setup
 
56
 
57
  print("--------------------- Initializing Web Server ---------------------")
58
  await server.setup() # Setup the web server
59
+ await web.TCPSite(server, Server.BIND_ADDRESS, Server.APP_PORT).start()
60
  print("------------------------------ DONE ------------------------------\n\n")
61
 
62
  # Start the background task to clear inactive clients after web server setup
FileStream/config.py CHANGED
@@ -42,6 +42,7 @@ class TMDB:
42
 
43
  class Server:
44
  PORT = int(env.get("PORT", 7860))
 
45
  BIND_ADDRESS = str(env.get("BIND_ADDRESS", "0.0.0.0"))
46
  PING_INTERVAL = int(env.get("PING_INTERVAL", "1200"))
47
  HAS_SSL = str(env.get("HAS_SSL","0").lower()) in ("1", "true", "t","yes", "y")
 
42
 
43
  class Server:
44
  PORT = int(env.get("PORT", 7860))
45
+ APP_PORT= int(env.get("APP_PORT", 8080))
46
  BIND_ADDRESS = str(env.get("BIND_ADDRESS", "0.0.0.0"))
47
  PING_INTERVAL = int(env.get("PING_INTERVAL", "1200"))
48
  HAS_SSL = str(env.get("HAS_SSL","0").lower()) in ("1", "true", "t","yes", "y")
ngnix.conf ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 7860;
3
+
4
+ proxy_buffering off;
5
+ proxy_cache off;
6
+ sendfile on;
7
+ tcp_nopush on;
8
+ tcp_nodelay on;
9
+
10
+ location / {
11
+ proxy_pass http://127.0.0.1:8080; # Important: Use port 8080 for AIOHTTP
12
+ proxy_set_header Host $host;
13
+ proxy_set_header X-Real-IP $remote_addr;
14
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15
+ proxy_set_header Range $http_range;
16
+ proxy_set_header If-Range $http_if_range;
17
+
18
+ add_header Accept-Ranges bytes;
19
+ }
20
+ }