# Single-stage build for Matterbridge with Kosmi bridge (Playwright)
FROM golang:1.23-bookworm

WORKDIR /app

# Install system dependencies for Playwright Chromium
RUN apt-get update && apt-get install -y \
    ca-certificates \
    chromium \
    libnss3 \
    libnspr4 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libcups2 \
    libdrm2 \
    libdbus-1-3 \
    libxkbcommon0 \
    libxcomposite1 \
    libxdamage1 \
    libxfixes3 \
    libxrandr2 \
    libgbm1 \
    libasound2 \
    libatspi2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build matterbridge
RUN go build -o matterbridge .

# Install playwright-go CLI and drivers
RUN go install github.com/playwright-community/playwright-go/cmd/playwright@latest && \
    $(go env GOPATH)/bin/playwright install --with-deps chromium

# Copy configuration
COPY matterbridge.toml /app/matterbridge.toml.example

# Run matterbridge
ENTRYPOINT ["/app/matterbridge"]
CMD ["-conf", "/app/matterbridge.toml"]
