apiVersion: batch/v1
kind: Job
metadata:
  name: commerce-minio-bootstrap
spec:
  backoffLimit: 12
  ttlSecondsAfterFinished: 86400
  template:
    metadata:
      labels:
        app: commerce-minio-bootstrap
    spec:
      restartPolicy: OnFailure
      containers:
        - name: configure
          image: quay.io/minio/mc:RELEASE.2025-08-13T08-35-41Z
          imagePullPolicy: IfNotPresent
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                secretKeyRef:
                  name: commerce-secrets
                  key: MINIO_ROOT_USER
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: commerce-secrets
                  key: MINIO_ROOT_PASSWORD
          command:
            - sh
            - -c
          args:
            - |
              set -eu

              until mc alias set local \
                http://minio-svc:9000 \
                "$MINIO_ROOT_USER" \
                "$MINIO_ROOT_PASSWORD"; do
                echo "Esperando MinIO..."
                sleep 5
              done

              mc mb --ignore-existing local/ari-products
              mc anonymous set download local/ari-products

              echo "Bucket ari-products creado y habilitado para lectura pública."
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              cpu: 100m
              memory: 128Mi
