# syntax=docker/dockerfile:1
#
# Urutau image: one static binary (no CGO, standard library only) on Alpine.

# Build stage.
FROM golang:1.26.11-alpine3.24 AS build
WORKDIR /src
COPY go.mod ./
COPY cmd cmd
COPY internal internal
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/urutau ./cmd/urutau

# Runtime stage: CA certificates (peers over HTTPS, geo database download) and
# tzdata so TZ can match the host's fail2ban log. The HEALTHCHECK is the binary
# itself (`urutau healthcheck`): no curl in the image.
# Runs unprivileged (uid 10001). To read /var/log/auth.log (group adm) the
# compose file adds the host group with `group_add: ["4"]`.
FROM alpine:3.24
RUN apk add --no-cache ca-certificates tzdata \
 && addgroup -S -g 10001 urutau \
 && adduser -S -u 10001 -G urutau -h /data -s /sbin/nologin urutau \
 && mkdir -p /data /logs \
 && chown urutau:urutau /data
COPY --from=build /out/urutau /usr/local/bin/urutau
LABEL org.opencontainers.image.title="Urutau" \
      org.opencontainers.image.description="Lightweight, always-on threat intelligence for self-hosted servers" \
      org.opencontainers.image.source="https://git.lucasrguerra.dev.br/ciberfauna/urutau" \
      org.opencontainers.image.licenses="MIT OR Apache-2.0"
ENV URUTAU_BIND=0.0.0.0:8790 \
    URUTAU_DATA_DIR=/data \
    URUTAU_TRAEFIK_LOG=/logs/traefik/access.log \
    URUTAU_AUTH_LOG=/logs/host/auth.log \
    URUTAU_FAIL2BAN_LOG=/logs/host/fail2ban.log
USER urutau
WORKDIR /data
VOLUME /data
EXPOSE 8790
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD ["urutau", "healthcheck"]
ENTRYPOINT ["urutau"]
CMD ["serve"]
