FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build

# build source
ARG TARGETARCH
WORKDIR /source

COPY --link . .
RUN dotnet publish -a $TARGETARCH -c Release --self-contained --property:PublishDir=/app --nologo

# create runtime image
FROM mcr.microsoft.com/dotnet/runtime-deps:9.0

LABEL org.opencontainers.image.authors="support@axxez.eu" \
      org.opencontainers.image.title="axXezBot" \
      org.opencontainers.image.description="TeamSpeak server bot" \
      org.opencontainers.image.source="https://github.com/axXez/axXezBot" \
      org.opencontainers.image.url="https://hub.docker.com/r/axzeu/axxezbot"

RUN apt-get update \
 && apt-get install -y --no-install-recommends ffmpeg curl \
 && curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
 && apt-get install -y --no-install-recommends nodejs \
 && ARCH=$(uname -m) \
 && case "$ARCH" in \
      x86_64)  BIN=yt-dlp_linux ;; \
      aarch64) BIN=yt-dlp_linux_aarch64 ;; \
      *) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;; \
    esac \
 && curl -fsSL "https://github.com/yt-dlp/yt-dlp/releases/latest/download/$BIN" \
         -o /usr/local/bin/yt-dlp \
 && chmod +x /usr/local/bin/yt-dlp \
 && apt-get remove -y curl \
 && apt-get autoremove -y \
 && rm -rf /var/lib/apt/lists/* \
 && echo '--js-runtimes node' > /etc/yt-dlp.conf

STOPSIGNAL SIGTERM
VOLUME /app
WORKDIR /app
COPY --link --from=build /app/axXezBot* /build/
USER $APP_UID
ENTRYPOINT ["/build/axXezBot"]