FROM --platform=$BUILDPLATFORM golang:alpine AS build
WORKDIR /app

ARG VERSION
ARG TARGETOS
ARG TARGETARCH

RUN wget https://git.xenrox.net/~xenrox/ntfy-alertmanager/refs/download/v${VERSION}/ntfy-alertmanager-${VERSION}.tar.gz -O latest.tar.gz && \
    tar -zxf latest.tar.gz

RUN cd ntfy-alertmanager-${VERSION} && \
    CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
    go build -ldflags="-X main.version=v${VERSION} -w -s" -o /app/ntfy-alertmanager

FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /

COPY --from=build /app/ntfy-alertmanager /ntfy-alertmanager

RUN apk add --no-cache curl

ENTRYPOINT [ "./ntfy-alertmanager" ]
HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1
