# syntax=docker/dockerfile:1
# Builds the Wild Dragon Restreamer UI:
#   1. Clone upstream datarhei/restreamer-ui at UPSTREAM_TAG
#   2. Apply overlay (branding + WebRTC components)
#   3. yarn build
#   4. Serve with Caddy

ARG UPSTREAM_TAG=v1.14.0
ARG NODE_VERSION=20

# ── Build ─────────────────────────────────────────────────────────────────────
FROM node:${NODE_VERSION}-alpine AS ui-builder

ARG UPSTREAM_TAG

RUN apk add --no-cache git

RUN git clone --depth 1 --branch ${UPSTREAM_TAG} \
        https://github.com/datarhei/restreamer-ui.git /ui

WORKDIR /ui
RUN yarn install --frozen-lockfile

COPY overlay/ /overlay/
COPY apply-overlay.sh /apply-overlay.sh
RUN sh /apply-overlay.sh

ENV PUBLIC_URL=./
RUN yarn build

# ── Serve ─────────────────────────────────────────────────────────────────────
FROM caddy:2-alpine

COPY --from=ui-builder /ui/build/ /srv/
COPY Caddyfile /etc/caddy/Caddyfile

EXPOSE 3000
