content: # syntax=docker/dockerfile:1.19@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6
  
  FROM golang:1.25-alpine@sha256:b6ed3fd0452c0e9bcdef5597f29cc1418f61672e9d3a2f55bf02e7222c014abd AS builder
  RUN apk add --no-cache gcc geos-dev musl-dev
  WORKDIR /root/flow
  
  # first copy only go.mod and go.sum to cache dependencies
  COPY flow/go.mod flow/go.sum ./
  COPY flow/pkg/go.mod flow/pkg/go.sum ./pkg/
  
  # download all the dependencies
  RUN go mod download
  
  # Copy all the code
  COPY flow .
  RUN rm -f go.work*
  
  # build the binary from flow folder
  WORKDIR /root/flow
  ENV CGO_ENABLED=1
  # Generate the typed handler wrapper
  RUN go generate
  ENV GOCACHE=/root/.cache/go-build
  RUN --mount=type=cache,target="/root/.cache/go-build" go build -o /root/peer-flow
  
  FROM alpine:3.22@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1 AS flow-base
  ENV TZ=UTC
  ADD --checksum=sha256:e5bb2084ccf45087bda1c9bffdea0eb15ee67f0b91646106e466714f9de3c7e3 https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /usr/local/share/ca-certificates/global-aws-rds-bundle.pem
  RUN apk add --no-cache ca-certificates geos && \
    update-ca-certificates && \
    adduser -s /bin/sh -D peerdb
  USER peerdb
  WORKDIR /home/peerdb
  COPY --from=builder --chown=peerdb /root/peer-flow .
  
  FROM flow-base AS flow-api
  
  ARG PEERDB_VERSION_SHA_SHORT
  ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
  
  EXPOSE 8112 8113
  ENTRYPOINT ["./peer-flow", "api", "--port", "8112", "--gateway-port", "8113"]
  
  FROM flow-base AS flow-worker
  
  # Sane defaults for OpenTelemetry
  ENV OTEL_METRIC_EXPORT_INTERVAL=10000
  ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
  ARG PEERDB_VERSION_SHA_SHORT
  ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
  
  ENTRYPOINT ["./peer-flow", "worker"]
  
  FROM flow-base AS flow-snapshot-worker
  
  ARG PEERDB_VERSION_SHA_SHORT
  ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
  ENTRYPOINT ["./peer-flow", "snapshot-worker"]
  
  
  FROM flow-base AS flow-maintenance
  
  ARG PEERDB_VERSION_SHA_SHORT
  ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
  ENTRYPOINT ["./peer-flow", "maintenance"]
  