# Single-stage build for Matterbridge with Kosmi bridge (Native WebSocket)
FROM golang:1.23-alpine

WORKDIR /app

# Install essential dependencies and Chromium for authentication
# Chromium is needed for email/password authentication via browser automation
RUN apk add --no-cache \
    ca-certificates \
    chromium \
    chromium-chromedriver \
    nss \
    freetype \
    harfbuzz \
    ttf-freefont

# Set environment variables for Chromium
ENV CHROME_BIN=/usr/bin/chromium-browser \
    CHROME_PATH=/usr/lib/chromium/

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

# Copy source code
COPY . .

# Build matterbridge
RUN go build -o matterbridge .

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

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