# minio — the e2e mirror of AWS S3 (and any S3-compatible backup target).
#
# Celilo's backup storage provider (apps/celilo/src/services/storage-providers/
# s3.ts) talks plain S3 with forcePathStyle + a custom endpoint, so it drives
# MinIO unchanged. This sim is the destination for `celilo backup --storage`
# (push) and the source for `celilo backup pull` (download) in the migration
# restore e2e (P5, openspec/specs/management-server-backup/spec.md).
#
# Placement: internet-external (100.64.0.0/24) like the other public services —
# the management box reaches it OUTBOUND over its internet egress, exactly the
# way it would reach real s3.amazonaws.com. Serves the S3 API on :80 (the same
# proven egress path as apt-repo-sim: traffic to 100.64.0.0/24 on dport 80
# bypasses fw-ext's Squid, so no TLS bump / cert / nonstandard-port filtering).
#
# The `celilo-backups` bucket is pre-created at startup (celilo's S3 provider
# does NOT create buckets — its initialize() only probes). Root creds are the
# well-known minioadmin/minioadmin; the migration test passes them to
# `celilo storage add s3 --access-key-id ... --secret-access-key ...`.

FROM quay.io/minio/mc:latest@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727 AS mc

# Static busybox purely for its `ip` applet: the MinIO image has no iproute2
# and no package manager worth invoking, but it still needs the ISP route
# every host on internet-external carries (see minio-startup.sh).
FROM busybox:stable-musl@sha256:3c6ae8008e2c2eedd141725c30b20d9c36b026eb796688f88205845ef17aa213 AS busybox

FROM quay.io/minio/minio:latest@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e

COPY --from=busybox /bin/busybox /usr/local/bin/busybox

# Bring the MinIO client in from the mc image so the entrypoint can create the
# bucket once the server is up.
COPY --from=mc /usr/bin/mc /usr/bin/mc

COPY config/routing/minio-startup.sh /usr/local/bin/minio-startup.sh

ENV MINIO_ROOT_USER=minioadmin \
    MINIO_ROOT_PASSWORD=minioadmin \
    MINIO_BUCKET=celilo-backups

EXPOSE 80 9001

ENTRYPOINT ["/bin/sh", "/usr/local/bin/minio-startup.sh"]
