File size: 1,963 Bytes
2c302a4
 
 
4e06012
 
 
 
764543b
 
 
 
0f2d277
4e06012
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
764543b
 
4e06012
 
 
 
 
764543b
4e06012
9274342
764543b
4e06012
 
 
 
 
 
764543b
4e06012
 
 
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
57
58
59
60
61
62
# Use the official Python image with Playwright pre-installed (v1.49.0 on Ubuntu Noble)
# This includes Python 3.12 which is required by nanobot-ai
FROM mcr.microsoft.com/playwright/python:v1.49.0-noble

# Set non-interactive mode for apt
ENV DEBIAN_FRONTEND=noninteractive

# The base image already has a user with UID 1000 (likely 'pwuser' or 'ubuntu').
# We will check or just use it ensuring permissions.
# HF Spaces expects the app to run as user 1000.



# Set working directory
WORKDIR /app

# Switch to root to install dependencies and system packages if needed
USER root

# Install system dependencies if any additional ones are needed (e.g. for some python packages)
RUN apt-get update && apt-get install -y \
    build-essential \
    software-properties-common \
    git \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Install Playwright browsers (already in base image, but ensure they are available for the user)
# The base image puts them in specific locations. 
# We run `playwright install chromium` just to be safe and ensure links are set up if needed by the python lib
RUN playwright install chromium

# Copy application code
COPY . .

# Adjust permissions for the user (using UID 1000)
RUN chown -R 1000:1000 /app

# Create necessary directories for the app (data, cache) and ensure permission
# HF Spaces likes /data for persistent storage if configured, but we map it in code.
# Here we just make sure our app directories are writable
RUN mkdir -p /app/data /app/memory /tmp/cache /tmp/hf && \
    chown -R 1000:1000 /app/data /app/memory /tmp/cache /tmp/hf

# Switch to the non-root user
USER 1000

# Expose the port
EXPOSE 7860

# Define environment variables
ENV PYTHONUNBUFFERED=1
ENV HOME=/app

# Start the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]