DaCrow13 commited on
Commit
2b68a06
·
1 Parent(s): eb469ad

feat: Orchestrate application startup with `start_space.sh`, configure Nginx for container logging, and add `procps` to the Dockerfile.

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -0
  2. nginx.conf +10 -8
  3. scripts/start_space.sh +22 -4
Dockerfile CHANGED
@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \
12
  git \
13
  dos2unix \
14
  nginx \
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
  # Create a non-root user
 
12
  git \
13
  dos2unix \
14
  nginx \
15
+ procps \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
  # Create a non-root user
nginx.conf CHANGED
@@ -1,6 +1,6 @@
1
  worker_processes 1;
2
  pid /tmp/nginx.pid;
3
- error_log /tmp/nginx.error.log;
4
 
5
  events {
6
  worker_connections 1024;
@@ -10,7 +10,8 @@ http {
10
  include /etc/nginx/mime.types;
11
  default_type application/octet-stream;
12
 
13
- access_log /tmp/nginx.access.log;
 
14
  client_body_temp_path /tmp/client_temp;
15
  proxy_temp_path /tmp/proxy_temp;
16
  fastcgi_temp_path /tmp/fastcgi_temp;
@@ -32,6 +33,12 @@ http {
32
  listen 7860;
33
  server_name localhost;
34
 
 
 
 
 
 
 
35
  # FastAPI Documentation
36
  location /docs {
37
  proxy_pass http://fastapi/docs;
@@ -62,11 +69,6 @@ http {
62
  proxy_set_header Host $host;
63
  }
64
 
65
- location /health {
66
- proxy_pass http://fastapi/health;
67
- proxy_set_header Host $host;
68
- }
69
-
70
  # Streamlit (Catch-all)
71
  location / {
72
  proxy_pass http://streamlit;
@@ -75,7 +77,7 @@ http {
75
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
76
  proxy_set_header X-Forwarded-Proto $scheme;
77
 
78
- # WebSocket support
79
  proxy_http_version 1.1;
80
  proxy_set_header Upgrade $http_upgrade;
81
  proxy_set_header Connection "upgrade";
 
1
  worker_processes 1;
2
  pid /tmp/nginx.pid;
3
+ error_log stderr info; # Log to stderr to see errors in HF Space Logs
4
 
5
  events {
6
  worker_connections 1024;
 
10
  include /etc/nginx/mime.types;
11
  default_type application/octet-stream;
12
 
13
+ # HF Space runs as non-root, use /tmp for everything
14
+ access_log /dev/stdout;
15
  client_body_temp_path /tmp/client_temp;
16
  proxy_temp_path /tmp/proxy_temp;
17
  fastcgi_temp_path /tmp/fastcgi_temp;
 
33
  listen 7860;
34
  server_name localhost;
35
 
36
+ # Health endpoint for HF readiness check
37
+ location /health {
38
+ proxy_pass http://fastapi/health;
39
+ proxy_set_header Host $host;
40
+ }
41
+
42
  # FastAPI Documentation
43
  location /docs {
44
  proxy_pass http://fastapi/docs;
 
69
  proxy_set_header Host $host;
70
  }
71
 
 
 
 
 
 
72
  # Streamlit (Catch-all)
73
  location / {
74
  proxy_pass http://streamlit;
 
77
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
78
  proxy_set_header X-Forwarded-Proto $scheme;
79
 
80
+ # WebSocket support for Streamlit
81
  proxy_http_version 1.1;
82
  proxy_set_header Upgrade $http_upgrade;
83
  proxy_set_header Connection "upgrade";
scripts/start_space.sh CHANGED
@@ -34,18 +34,36 @@ dvc pull models/random_forest_tfidf_gridsearch.pkl.dvc \
34
  # Create Nginx temp directories
35
  mkdir -p /tmp/client_temp /tmp/proxy_temp /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp
36
 
 
 
 
37
  echo "Starting FastAPI application in background..."
38
- uvicorn hopcroft_skill_classification_tool_competition.main:app --host 127.0.0.1 --port 8000 &
39
 
40
  # Wait for API to start
41
  echo "Waiting for API to start..."
42
- sleep 10
43
 
44
  echo "Starting Nginx reverse proxy..."
45
- nginx -c /app/nginx.conf -g "daemon off;" &
 
 
 
 
 
46
 
47
  echo "Waiting for Nginx to initialize..."
48
- sleep 2
 
 
 
 
 
 
 
 
 
 
49
 
50
  echo "Starting Streamlit application..."
51
  export API_BASE_URL="http://127.0.0.1:8000"
 
34
  # Create Nginx temp directories
35
  mkdir -p /tmp/client_temp /tmp/proxy_temp /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp
36
 
37
+ echo "Checking models existence..."
38
+ ls -la models/
39
+
40
  echo "Starting FastAPI application in background..."
41
+ uvicorn hopcroft_skill_classification_tool_competition.main:app --host 127.0.0.1 --port 8000 >> /tmp/fastapi.log 2>&1 &
42
 
43
  # Wait for API to start
44
  echo "Waiting for API to start..."
45
+ sleep 15
46
 
47
  echo "Starting Nginx reverse proxy..."
48
+ # Check if nginx is in path
49
+ if ! command -v nginx &> /dev/null; then
50
+ echo "ERROR: nginx not found in PATH"
51
+ exit 1
52
+ fi
53
+ nginx -c /app/nginx.conf -g "daemon off;" >> /tmp/nginx_startup.log 2>&1 &
54
 
55
  echo "Waiting for Nginx to initialize..."
56
+ sleep 5
57
+
58
+ # Check if Nginx is running
59
+ if ps aux | grep -v grep | grep -q "nginx"; then
60
+ echo "Nginx is running."
61
+ else
62
+ echo "ERROR: Nginx failed to start. Logs:"
63
+ cat /tmp/nginx_startup.log
64
+ # Try to start it without the config to see if it's a binary issue
65
+ # nginx -v
66
+ fi
67
 
68
  echo "Starting Streamlit application..."
69
  export API_BASE_URL="http://127.0.0.1:8000"