# VDO.Ninja Docker Image
# Basierend auf nginx:alpine für minimale Imagegröße
# Quelle: https://github.com/steveseguin/vdo.ninja

ARG VDO_NINJA_REPO=https://github.com/steveseguin/vdo.ninja
ARG VDO_NINJA_REF=

FROM alpine:3.20 AS source

ARG VDO_NINJA_REPO
ARG VDO_NINJA_REF

RUN apk add --no-cache ca-certificates git \
    && if [ -n "${VDO_NINJA_REF}" ]; then \
         git clone --depth 1 --branch "${VDO_NINJA_REF}" "${VDO_NINJA_REPO}" /vdo-ninja-source; \
       else \
         git clone --depth 1 "${VDO_NINJA_REPO}" /vdo-ninja-source; \
       fi

FROM nginx:alpine

LABEL maintainer="Patrick Asmus <support@techniverse.net>"
LABEL org.opencontainers.image.title="VDO.Ninja"
LABEL org.opencontainers.image.description="Self-hosted VDO.Ninja - Free browser-based, peer-to-peer video streaming"
LABEL org.opencontainers.image.source="https://github.com/steveseguin/vdo.ninja"
LABEL org.opencontainers.image.licenses="AGPL-3.0"

# Eigene nginx-Konfiguration
COPY nginx.conf /etc/nginx/conf.d/default.conf

# VDO.Ninja Quelldateien aus dem Build-Stage übernehmen
COPY --from=source /vdo-ninja-source/ /usr/share/nginx/html/

# Nicht benötigte Dateien entfernen
RUN rm -rf /usr/share/nginx/html/.git \
           /usr/share/nginx/html/.github \
           /usr/share/nginx/html/.gitignore \
           /usr/share/nginx/html/.prettierrc \
           /usr/share/nginx/html/CONTRIBUTING.md \
           /usr/share/nginx/html/install.md \
           /usr/share/nginx/html/turnserver_install.sh.sample \
           /usr/share/nginx/html/turnserver_basic.conf \
           /usr/share/nginx/html/turnserver.md \
           /usr/share/nginx/html/turnsetup.sh \
           /usr/share/nginx/html/turn-credentials-php.sample

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget -qO- http://localhost:80/ || exit 1
