File size: 1,848 Bytes
8666ff1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Use the pre-built Flow2API image from GitHub Container Registry
FROM ghcr.io/gdtiti/flow2api:latest

# Switch to root to fix permissions and setup
USER root

# Fix file permissions for HuggingFace Spaces
RUN cd /app && \
    # Create and fix log file permissions
    touch logs.txt && \
    chmod 666 logs.txt && \
    # Ensure data directory exists with proper permissions
    mkdir -p data && \
    chmod 755 data && \
    # Try to set proper ownership
    chown -R app:app /app 2>/dev/null || \
    # If app user doesn't exist, make critical files world writable
    (chmod 777 logs.txt data && echo "Made files world writable as fallback") && \
    echo "File permissions fixed"

# Add startup script for debugging
RUN echo '#!/bin/bash\n\
echo "=== Startup Debug Info ==="\n\
echo "User: $(whoami)"\n\
echo "Current dir: $(pwd)"\n\
echo "Listing /app:"\n\
ls -la /app/\n\
echo "Checking logs.txt permissions:"\n\
ls -la /app/logs.txt\n\
echo "=== End Debug Info ==="\n\
exec python main.py' > /app/start_debug.sh && \
    chmod +x /app/start_debug.sh

# Set HuggingFace Spaces specific environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV FLOW2API_HOST=0.0.0.0
ENV FLOW2API_PORT=7860

# Add debug environment variables
ENV FLOW2API_DEBUG_ENABLED=true
ENV FLOW2API_DEBUG_LOG_REQUESTS=false
ENV FLOW2API_DEBUG_LOG_RESPONSES=false

# Switch back to app user if it exists
USER app 2>/dev/null || USER root

# Expose the HuggingFace Spaces default port
EXPOSE 7860

# Health check for HuggingFace Spaces with longer startup time
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
    CMD python -c "import socket; s=socket.socket(); s.connect(('localhost', 7860)); s.close()" || exit 1

# Use debug startup script
CMD ["/app/start_debug.sh"]