# syntax=docker/dockerfile:1.7

ARG GO_VERSION=1.27.0
FROM golang:${GO_VERSION}-alpine3.24 AS build

RUN apk add --no-cache ca-certificates git

WORKDIR /src

COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
    go mod download

COPY . .

ARG EVENT_TOOLS_VERSION=dev
ARG EVENT_TOOLS_SOURCE_URL=https://git.gay/Leora/event-tools
ARG DEBUG=false
ARG TARGETOS=linux
ARG TARGETARCH=amd64

RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
    go build \
      -trimpath \
      -buildvcs=false \
      -ldflags="-s -w \
        -X git.gay/Leora/event-tools/internal/buildinfo.EventTools_VERSION=${EVENT_TOOLS_VERSION} \
        -X git.gay/Leora/event-tools/internal/buildinfo.EventTools_Source_URL=${EVENT_TOOLS_SOURCE_URL} \
        -X git.gay/Leora/event-tools/internal/buildinfo.DEBUG=${DEBUG}" \
      -o /out/event-tools \
      ./cmd/event-tools

FROM alpine:3.24

RUN apk add --no-cache ca-certificates tzdata xz \
    && addgroup -S -g 10001 event-tools \
    && adduser -S -D -H -u 10001 -G event-tools event-tools

WORKDIR /app
COPY --from=build --chown=10001:10001 /out/event-tools /app/event-tools

USER 10001:10001
EXPOSE 8082

ENTRYPOINT ["/app/event-tools"]
