FROM --platform=$TARGETOS/$TARGETARCH golang:1.23.3 AS builder

ENV         DEBIAN_FRONTEND noninteractive


WORKDIR /appbuild/yagpdb

RUN apt update -y \
	&& apt upgrade -y \
	&& apt install -y apt-transport-https wget curl git tar

RUN git clone https://github.com/botlabs-gg/yagpdb.git .

RUN go mod download

COPY . .

WORKDIR /appbuild/yagpdb/cmd/yagpdb
RUN CGO_ENABLED=0 GOOS=linux go build -v -ldflags "-X github.com/botlabs-gg/yagpdb/v2/common.VERSION=$(git describe --tags)"



FROM --platform=$TARGETOS/$TARGETARCH alpine:latest

# Dependencies: ca-certificates for client TLS, tzdata for timezone and ffmpeg for soundboard support
RUN  apk update \
	&& apk upgrade \
	&& apk --no-cache add autoconf ca-certificates ffmpeg tzdata tini iproute2 iputils-ping bind-tools curl

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN         adduser -D -h /home/container container -s /bin/bash container
USER        container
ENV         USER=container HOME=/home/container
WORKDIR     /home/container

COPY --from=builder /appbuild/yagpdb/cmd/yagpdb/yagpdb /usr/bin/yagpdb
# RUN chmod +x /usr/bin/yagpdb

STOPSIGNAL SIGINT

COPY        --chown=container:container ./entrypoint.sh /entrypoint.sh
RUN         chmod +x /entrypoint.sh
ENTRYPOINT    ["/sbin/tini", "-g", "--"]
CMD         ["/entrypoint.sh"]
