leonsimon23 commited on
Commit
e63e363
·
verified ·
1 Parent(s): 9eb6664

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +41 -62
Dockerfile CHANGED
@@ -1,88 +1,67 @@
1
  FROM python:3.9-slim
2
 
 
 
 
 
 
 
3
  WORKDIR /app
4
 
5
- # Copy all files from the build context
6
  COPY . .
7
 
8
- # For build-time debugging: List all files
9
- RUN echo "--- Verifying Copied Files ---" && ls -la
 
 
 
10
 
11
  # Install Python dependencies
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
14
- # Create necessary directories
15
  RUN mkdir -p /app/instance/sessions && \
16
  chmod -R 777 /app/instance
17
 
18
- # Create initialization script using heredoc
19
- RUN cat > /app/init_script.py << 'EOL'
20
- import sys
21
- import os
22
-
23
- def main():
24
- print("--- Running Initialization Script ---")
25
- print("Current Working Directory:", os.getcwd())
26
- print("Directory Contents:", os.listdir('.'))
27
- print("\nPython Path:")
28
- for path in sys.path:
29
- print(" -", path)
30
-
31
- try:
32
- from app import init_db
33
- print("Successfully imported app module")
34
- init_db()
35
- print("Database initialized successfully")
36
- except ImportError as e:
37
- print("Error: Could not import app module")
38
- print("Error details:", str(e))
39
- sys.exit(1)
40
- except Exception as e:
41
- print("Error during initialization:", str(e))
42
- sys.exit(1)
43
-
44
- if __name__ == '__main__':
45
- main()
46
- EOL
47
-
48
  # Create gunicorn configuration
49
- RUN cat > /app/gunicorn.conf.py << 'EOL'
50
- bind = "0.0.0.0:7860"
51
- workers = 1
52
- worker_class = "sync"
53
- loglevel = "info"
54
- accesslog = "-"
55
- errorlog = "-"
56
- preload_app = True
57
- chdir = "/app"
58
- EOL
59
 
60
  # Create start script
61
- RUN cat > /app/start.sh << 'EOL'
62
- #!/bin/bash
63
- set -e
64
- cd /app
65
- export PYTHONPATH=/app:$PYTHONPATH
66
- echo "===== Application Startup ====="
67
- echo "Current directory: $(pwd)"
68
- echo "Python path: $PYTHONPATH"
69
- echo "Directory contents:"
70
- ls -la
71
- echo "Running initialization script..."
72
- python3 /app/init_script.py
73
- echo "Starting Gunicorn server..."
74
- exec gunicorn --config /app/gunicorn.conf.py app:app
75
- EOL
76
-
77
- # Make start script executable
78
- RUN chmod +x /app/start.sh
79
 
80
  # Set environment variables
81
  ENV FLASK_APP=app.py
82
  ENV FLASK_ENV=production
 
 
83
  ENV PYTHONPATH=/app
84
  ENV PYTHONUNBUFFERED=1
85
 
 
 
 
 
86
  # Set permissions
87
  RUN chown -R nobody:nogroup /app && \
88
  chmod -R 755 /app
 
1
  FROM python:3.9-slim
2
 
3
+ # Install system dependencies
4
+ RUN apt-get update && \
5
+ apt-get install -y curl && \
6
+ apt-get clean && \
7
+ rm -rf /var/lib/apt/lists/*
8
+
9
  WORKDIR /app
10
 
11
+ # Copy all files
12
  COPY . .
13
 
14
+ # Debug: Show copied files
15
+ RUN echo "=== Directory Structure ===" && \
16
+ ls -la /app && \
17
+ echo "\n=== Templates Directory ===" && \
18
+ ls -la /app/templates
19
 
20
  # Install Python dependencies
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
+ # Create necessary directories and set permissions
24
  RUN mkdir -p /app/instance/sessions && \
25
  chmod -R 777 /app/instance
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # Create gunicorn configuration
28
+ RUN echo 'bind = "0.0.0.0:7860"' > /app/gunicorn.conf.py && \
29
+ echo 'workers = 1' >> /app/gunicorn.conf.py && \
30
+ echo 'worker_class = "sync"' >> /app/gunicorn.conf.py && \
31
+ echo 'loglevel = "info"' >> /app/gunicorn.conf.py && \
32
+ echo 'accesslog = "-"' >> /app/gunicorn.conf.py && \
33
+ echo 'errorlog = "-"' >> /app/gunicorn.conf.py && \
34
+ echo 'preload_app = True' >> /app/gunicorn.conf.py && \
35
+ echo 'chdir = "/app"' >> /app/gunicorn.conf.py
 
 
36
 
37
  # Create start script
38
+ RUN echo '#!/bin/bash' > /app/start.sh && \
39
+ echo 'set -e' >> /app/start.sh && \
40
+ echo 'cd /app' >> /app/start.sh && \
41
+ echo 'export PYTHONPATH=/app:$PYTHONPATH' >> /app/start.sh && \
42
+ echo 'echo "===== Application Startup at $(date) ====="' >> /app/start.sh && \
43
+ echo 'echo "Current directory: $(pwd)"' >> /app/start.sh && \
44
+ echo 'echo "Python path: $PYTHONPATH"' >> /app/start.sh && \
45
+ echo 'echo "Directory contents:"' >> /app/start.sh && \
46
+ echo 'ls -la' >> /app/start.sh && \
47
+ echo 'echo "Running initialization script..."' >> /app/start.sh && \
48
+ echo 'python3 init_script.py' >> /app/start.sh && \
49
+ echo 'echo "Starting Gunicorn server..."' >> /app/start.sh && \
50
+ echo 'exec gunicorn --config /app/gunicorn.conf.py app:app' >> /app/start.sh && \
51
+ chmod +x /app/start.sh
 
 
 
 
52
 
53
  # Set environment variables
54
  ENV FLASK_APP=app.py
55
  ENV FLASK_ENV=production
56
+ ENV HOST=0.0.0.0
57
+ ENV PORT=7860
58
  ENV PYTHONPATH=/app
59
  ENV PYTHONUNBUFFERED=1
60
 
61
+ # Dify API configuration
62
+ ENV DIFY_API_KEY=${DIFY_API_KEY}
63
+ ENV DIFY_API_ENDPOINT=${DIFY_API_ENDPOINT}
64
+
65
  # Set permissions
66
  RUN chown -R nobody:nogroup /app && \
67
  chmod -R 755 /app