FROM golang:1.25-alpine AS builder
WORKDIR /build
COPY api/ .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o node-api .

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

RUN apt-get update && apt-get install -y --no-install-recommends \
    xvfb \
    x11vnc \
    socat \
    xdotool \
    adwaita-icon-theme \
    x11-apps \
    imagemagick \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /build/node-api /usr/local/bin/node-api

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV DISPLAY=:99
ENV RESOLUTION=1920x1080x24

EXPOSE 5900
EXPOSE 8080
EXPOSE 9222

ENTRYPOINT ["/entrypoint.sh"]
