jens-l commited on
Commit
1a407a0
Β·
1 Parent(s): dd29127

Simplify Docker logging and fix preview app working directory

Browse files
Files changed (2) hide show
  1. app.py +10 -4
  2. start.sh +8 -13
app.py CHANGED
@@ -84,10 +84,14 @@ def start_preview_app():
84
 
85
  print(f"πŸš€ Starting preview app from `{app_file}` on port {PREVIEW_PORT}...")
86
  try:
 
 
 
 
87
  preview_process = subprocess.Popen(
88
  [
89
  "python",
90
- app_file,
91
  "--server-port",
92
  str(PREVIEW_PORT),
93
  "--server-name",
@@ -96,6 +100,7 @@ def start_preview_app():
96
  stdout=subprocess.PIPE,
97
  stderr=subprocess.PIPE,
98
  text=True,
 
99
  )
100
  # Give it a moment to start up
101
  time.sleep(3)
@@ -103,9 +108,10 @@ def start_preview_app():
103
  print(f"βœ… Preview app started successfully (PID: {preview_process.pid}).")
104
  return True, f"Preview running at {PREVIEW_URL}"
105
  else:
106
- stderr = preview_process.stderr.read()
107
- print(f"❌ Failed to start preview app. Error:\n{stderr}")
108
- return False, f"Failed to start preview app:\n{stderr}"
 
109
  except Exception as e:
110
  print(f"❌ Exception while starting preview app: {e}")
111
  return False, f"Error starting preview app: {e}"
 
84
 
85
  print(f"πŸš€ Starting preview app from `{app_file}` on port {PREVIEW_PORT}...")
86
  try:
87
+ # Change to the directory containing the app file
88
+ app_dir = str(Path(app_file).parent)
89
+ app_filename = Path(app_file).name
90
+
91
  preview_process = subprocess.Popen(
92
  [
93
  "python",
94
+ app_filename,
95
  "--server-port",
96
  str(PREVIEW_PORT),
97
  "--server-name",
 
100
  stdout=subprocess.PIPE,
101
  stderr=subprocess.PIPE,
102
  text=True,
103
+ cwd=app_dir, # Set working directory to the app directory
104
  )
105
  # Give it a moment to start up
106
  time.sleep(3)
 
108
  print(f"βœ… Preview app started successfully (PID: {preview_process.pid}).")
109
  return True, f"Preview running at {PREVIEW_URL}"
110
  else:
111
+ stdout, stderr = preview_process.communicate()
112
+ error_msg = f"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
113
+ print(f"❌ Failed to start preview app. Error:\n{error_msg}")
114
+ return False, f"Failed to start preview app:\n{error_msg}"
115
  except Exception as e:
116
  print(f"❌ Exception while starting preview app: {e}")
117
  return False, f"Error starting preview app: {e}"
start.sh CHANGED
@@ -1,29 +1,24 @@
1
  #!/bin/bash
2
 
3
  # Start nginx in background as non-root user
 
4
  nginx -g 'daemon off;' &
5
  NGINX_PID=$!
6
 
7
- # Wait a moment for nginx to start
8
- sleep 2
9
-
10
- # Start the main Gradio app on port 7862 (internal)
11
- python app.py --server-port 7862 --server-name 0.0.0.0 &
12
- APP_PID=$!
13
-
14
  # Function to handle shutdown
15
  cleanup() {
16
  echo "Shutting down..."
17
- kill $NGINX_PID $APP_PID 2>/dev/null
18
- wait $NGINX_PID $APP_PID 2>/dev/null
19
  exit 0
20
  }
21
 
22
  # Set up signal handlers
23
  trap cleanup SIGTERM SIGINT
24
 
25
- # Wait for any process to exit
26
- wait -n
27
 
28
- # If we get here, one process exited, so clean up
29
- cleanup
 
 
1
  #!/bin/bash
2
 
3
  # Start nginx in background as non-root user
4
+ echo "Starting nginx..."
5
  nginx -g 'daemon off;' &
6
  NGINX_PID=$!
7
 
 
 
 
 
 
 
 
8
  # Function to handle shutdown
9
  cleanup() {
10
  echo "Shutting down..."
11
+ kill $NGINX_PID 2>/dev/null
12
+ wait $NGINX_PID 2>/dev/null
13
  exit 0
14
  }
15
 
16
  # Set up signal handlers
17
  trap cleanup SIGTERM SIGINT
18
 
19
+ # Wait a moment for nginx to start
20
+ sleep 2
21
 
22
+ echo "Starting Gradio app on port 7862..."
23
+ # Run the main app in foreground so Docker captures its logs
24
+ python app.py --server-port 7862 --server-name 0.0.0.0