FROM mcr.microsoft.com/playwright:v1.57.0-noble

# We need root to install extra tools
USER root

# Install socat (for TCP <-> Unix socket proxy) and Playwright CLI globally
RUN apt-get update && \
    apt-get install -y --no-install-recommends socat && \
    npm install -g playwright@1.57.0 && \
    rm -rf /var/lib/apt/lists/*

# Create a runtime dir for the Unix socket
RUN mkdir -p /var/run/playwright && \
    chown -R pwuser:pwuser /var/run/playwright

# Switch to the non-root user provided by the Playwright base image
USER pwuser
WORKDIR /home/pwuser

# Environment: TCP WS endpoint + Unix socket path
ENV PLAYWRIGHT_WS_PORT=3000 \
    PLAYWRIGHT_WS_HOST=127.0.0.1 \
    PLAYWRIGHT_SOCKET_PATH=/var/run/playwright/playwright.sock \
    PLAYWRIGHT_SERVER_ARGS=""

# Copy entrypoint script
COPY --chown=pwuser:pwuser entrypoint.sh /home/pwuser/entrypoint.sh
RUN chmod +x /home/pwuser/entrypoint.sh

# Optional: document the TCP WS port
EXPOSE 3000

ENTRYPOINT ["/home/pwuser/entrypoint.sh"]
