Skip to content

Instantly share code, notes, and snippets.

@Braunson
Created October 8, 2024 21:03
Show Gist options
  • Save Braunson/55f7c5487ef90561f3a6514252e9e4c3 to your computer and use it in GitHub Desktop.
Save Braunson/55f7c5487ef90561f3a6514252e9e4c3 to your computer and use it in GitHub Desktop.
Support for auto-creating the env defined bucket for Minio with Laravel Sail
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=local
AWS_ENDPOINT=http://minio:9000
AWS_USE_PATH_STYLE_ENDPOINT=true
# docker/minio/custom-entrypoint.sh
#!/bin/sh
set -e
/usr/local/bin/custom-scripts/setup-bucket.sh &
exec "$@"
minio:
image: 'minio/minio:latest'
build:
context: ./docker/minio
dockerfile: Dockerfile
ports:
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
environment:
MINIO_ROOT_USER: '${MINIO_ROOT_USER:-sail}'
MINIO_ROOT_PASSWORD: '${MINIO_ROOT_PASSWORD:-password}'
MINIO_BUCKET_POLICY: '${MINIO_BUCKET_POLICY:-public}'
AWS_BUCKET: '${AWS_BUCKET:-local}'
volumes:
- 'sail-minio:/data'
networks:
- sail
command: minio server /data --console-address ":8900"
healthcheck:
test: ["CMD", "mc", "ready", "local"]
retries: 3
timeout: 5s
# docker/minio/Dockerfile
FROM minio/minio:latest
USER root
RUN mkdir -p /usr/local/bin/custom-scripts
COPY setup-bucket.sh /usr/local/bin/custom-scripts/setup-bucket.sh
COPY custom-entrypoint.sh /usr/local/bin/custom-scripts/custom-entrypoint.sh
RUN chmod +x /usr/local/bin/custom-scripts/setup-bucket.sh \
&& chmod +x /usr/local/bin/custom-scripts/custom-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/custom-scripts/custom-entrypoint.sh"]
CMD ["minio", "server", "/data"]
# docker/minio/setup-bucket.sh
#!/bin/sh
set -e
# Wait for MinIO to be ready
until mc alias set myminio http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" > /dev/null 2>&1
do
echo "Waiting for MinIO to be ready..."
sleep 1
done
mc admin update
if [ -z "$AWS_BUCKET" ]; then
echo "AWS_BUCKET is not set. Skipping bucket creation."
exit 0
fi
if ! mc ls myminio/$AWS_BUCKET > /dev/null 2>&1; then
mc mb "myminio/$AWS_BUCKET"
mc anonymous set "${MINIO_BUCKET_POLICY:-public}" "myminio/$AWS_BUCKET"
echo "Bucket $AWS_BUCKET created and configured with policy: ${MINIO_BUCKET_POLICY:-public}"
else
echo "Bucket $AWS_BUCKET already exists, skipping..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment