|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Set variables |
| 4 | +MINIO_VOLUME_DIR="./tmp/data" |
| 5 | +CONTAINER_NAME="minio-local" |
| 6 | +ACCESS_KEY="minioadmin" |
| 7 | +SECRET_KEY="minioadmin" |
| 8 | +DEFAULT_BUCKET="default" |
| 9 | + |
| 10 | +# Create volume directory if it doesn't exist |
| 11 | +if [ ! -d "$MINIO_VOLUME_DIR" ]; then |
| 12 | + mkdir -p "$MINIO_VOLUME_DIR" |
| 13 | + echo "Created Minio volume directory: $MINIO_VOLUME_DIR" |
| 14 | +fi |
| 15 | + |
| 16 | +# Remove dangling images |
| 17 | +echo "Removing dangling Podman images..." |
| 18 | +podman image prune -f |
| 19 | + |
| 20 | +# Stop and remove existing container if it exists |
| 21 | +if [ "$(podman ps -aq -f name=$CONTAINER_NAME)" ]; then |
| 22 | + podman stop $CONTAINER_NAME |
| 23 | + podman rm $CONTAINER_NAME |
| 24 | +fi |
| 25 | + |
| 26 | +# Start Minio container |
| 27 | +echo "Starting Minio container..." |
| 28 | +podman run -d \ |
| 29 | + --name $CONTAINER_NAME \ |
| 30 | + -p 9000:9000 \ |
| 31 | + -p 9001:9001 \ |
| 32 | + -e "MINIO_ROOT_USER=$ACCESS_KEY" \ |
| 33 | + -e "MINIO_ROOT_PASSWORD=$SECRET_KEY" \ |
| 34 | + -v "$(pwd)/$MINIO_VOLUME_DIR:/data:z" \ |
| 35 | + docker.io/minio/minio server /data --console-address ":9001" |
| 36 | + |
| 37 | +# Wait for MinIO to be ready with proper health check |
| 38 | +echo "Waiting for MinIO to be ready..." |
| 39 | +sleep 1 |
| 40 | + |
| 41 | +until podman exec $CONTAINER_NAME /bin/sh -c "curl -s http://localhost:9000/minio/health/ready"; do |
| 42 | + sleep 1 |
| 43 | +done |
| 44 | + |
| 45 | +# Configure mc client and create public bucket if it doesn't exist |
| 46 | +echo "Configuring MinIO client and creating bucket..." |
| 47 | +podman exec $CONTAINER_NAME /bin/sh -c "\ |
| 48 | + mc alias set myminio http://localhost:9000 $ACCESS_KEY $SECRET_KEY && \ |
| 49 | + if ! mc ls myminio/$DEFAULT_BUCKET > /dev/null 2>&1; then \ |
| 50 | + mc mb myminio/$DEFAULT_BUCKET && \ |
| 51 | + mc anonymous set download myminio/$DEFAULT_BUCKET; \ |
| 52 | + else \ |
| 53 | + echo 'Bucket already exists'; \ |
| 54 | + fi && \ |
| 55 | + mc ls myminio/" |
| 56 | + |
| 57 | +echo "Minio is running!" |
| 58 | +echo "API endpoint: http://localhost:9000" |
| 59 | +echo "Console: http://localhost:9001" |
| 60 | +echo "Access Key: $ACCESS_KEY" |
| 61 | +echo "Secret Key: $SECRET_KEY" |
| 62 | +echo "Default bucket: $DEFAULT_BUCKET" |
0 commit comments