FROM golang:1.26.5-alpine3.23@sha256:622e56dbc11a8cfe87cafa2331e9a201877271cbff918af53d3be315f3da88cc AS minio_builder

ADD --checksum=sha256:45521908307306e925c98d629e1c17d78c8b72b6ee242b1bfb1409f7d8ee5841 \
  https://github.com/minio/minio/archive/9e49d5e7a648f00e26f2246f4dc28e6b07f8c84a.tar.gz \
  /tmp/minio.tar.gz

WORKDIR /src

RUN tar --extract --gzip --file /tmp/minio.tar.gz \
    --directory . --strip-components=1 \
  && go get \
    github.com/apache/thrift@v0.23.0 \
    github.com/buger/jsonparser@v1.1.2 \
    github.com/prometheus/prometheus@v0.311.3 \
    golang.org/x/crypto@v0.52.0 \
    golang.org/x/net@v0.55.0 \
    google.golang.org/grpc@v1.81.1 \
  && CGO_ENABLED=0 go build \
    -mod=mod \
    -trimpath \
    -tags kqueue \
    -ldflags="-s -w \
      -X github.com/minio/minio/cmd.Version=2025-10-15T17:29:55Z \
      -X github.com/minio/minio/cmd.CopyrightYear=2025 \
      -X github.com/minio/minio/cmd.ReleaseTag=RELEASE.2025-10-15T17-29-55Z \
      -X github.com/minio/minio/cmd.CommitID=9e49d5e7a648f00e26f2246f4dc28e6b07f8c84a \
      -X github.com/minio/minio/cmd.ShortCommitID=9e49d5e7a648" \
    -o /out/minio .

FROM golang:1.26.5-alpine3.23@sha256:622e56dbc11a8cfe87cafa2331e9a201877271cbff918af53d3be315f3da88cc AS mc_builder

ADD --checksum=sha256:95cd293c7119f16921a6dc515a1fb74a2227f19fd994b9c8b770a154e802ac44 \
  https://github.com/minio/mc/archive/7394ce0dd2a80935aded936b09fa12cbb3cb8096.tar.gz \
  /tmp/mc.tar.gz

WORKDIR /src

RUN tar --extract --gzip --file /tmp/mc.tar.gz \
    --directory . --strip-components=1 \
  && go get \
    github.com/prometheus/prometheus@v0.311.3 \
    golang.org/x/crypto@v0.52.0 \
    golang.org/x/net@v0.55.0 \
    google.golang.org/grpc@v1.81.1 \
  && go mod tidy \
  && CGO_ENABLED=0 go build \
    -trimpath \
    -tags kqueue \
    -ldflags="-s -w \
      -X github.com/minio/mc/cmd.Version=2025-08-13T08:35:41Z \
      -X github.com/minio/mc/cmd.CopyrightYear=2025 \
      -X github.com/minio/mc/cmd.ReleaseTag=RELEASE.2025-08-13T08-35-41Z \
      -X github.com/minio/mc/cmd.CommitID=7394ce0dd2a80935aded936b09fa12cbb3cb8096 \
      -X github.com/minio/mc/cmd.ShortCommitID=7394ce0dd2a8" \
    -o /out/mc .

FROM alpine:3.23.3@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS runtime

RUN apk add --no-cache \
      ca-certificates=20260611-r0 \
      libcrypto3=3.5.7-r0 \
      libssl3=3.5.7-r0 \
      musl=1.2.5-r23 \
      musl-utils=1.2.5-r23 \
      zlib=1.3.2-r0

USER 10001:10001

FROM runtime AS server

COPY --from=minio_builder /out/minio /usr/local/bin/minio

ENTRYPOINT ["minio"]
CMD ["--version"]

FROM runtime AS client

COPY --from=mc_builder /out/mc /usr/local/bin/mc

ENTRYPOINT ["mc"]
CMD ["--version"]
