this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2640 from amjithtitus09/switch-to-minio

Switch from localstack to minIO

authored by

Vignesh Hari and committed by
GitHub
3b903cff bae32017

+114 -26
+1 -1
.gitattributes
··· 1 1 * text=auto 2 - scripts/* text eol=lf 2 + *.sh text eol=lf
+17 -10
docker-compose.yaml
··· 23 23 ports: 24 24 - "6380:6379" 25 25 26 - localstack: 27 - image: localstack/localstack:latest 26 + minio: 27 + image: minio/minio:latest 28 28 restart: unless-stopped 29 29 environment: 30 - - AWS_DEFAULT_REGION=ap-south-1 31 - - EDGE_PORT=4566 32 - - SERVICES=s3 33 - - EXTRA_CORS_ALLOWED_ORIGINS=* 34 - - EXTRA_CORS_ALLOWED_HEADERS=* 30 + MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:-minioadmin} 31 + MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:-minioadmin} 32 + AWS_DEFAULT_REGION: ap-south-1 # To maintain compatibility with existing apps 35 33 volumes: 36 - - "${TEMPDIR:-./care/media/localstack}:/var/lib/localstack" 37 - - "./docker/awslocal:/etc/localstack/init/ready.d/" 34 + - "./care/media/minio:/data" 35 + - "./docker/minio/init-script.sh:/init-script.sh:ro" # Mount the init script 36 + - "./docker/minio/entrypoint.sh:/entrypoint.sh:ro" # Mount the entrypoint script 38 37 ports: 39 - - "4566:4566" 38 + - "9100:9000" # S3 API 39 + - "9001:9001" # Web Console 40 + entrypoint: ["/entrypoint.sh"] 41 + healthcheck: 42 + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/ready"] 43 + interval: 10s 44 + retries: 5 45 + start_period: 10s 46 + timeout: 10s 40 47 41 48 volumes: 42 49 postgres-data:
+4 -4
docker/.local.env
··· 11 11 ATTACH_DEBUGGER=false 12 12 13 13 BUCKET_REGION=ap-south-1 14 - BUCKET_KEY=key 15 - BUCKET_SECRET=secret 16 - BUCKET_ENDPOINT=http://localstack:4566 17 - BUCKET_EXTERNAL_ENDPOINT=http://localhost:4566 14 + BUCKET_KEY=${MINIO_ACCESS_KEY:-minioadmin} 15 + BUCKET_SECRET=${MINIO_SECRET_KEY:-minioadmin} 16 + BUCKET_ENDPOINT=http://minio:9000 17 + BUCKET_EXTERNAL_ENDPOINT=http://localhost:9100 18 18 FILE_UPLOAD_BUCKET=patient-bucket 19 19 FACILITY_S3_BUCKET=facility-bucket 20 20
+5 -4
docker/.prebuilt.env
··· 10 10 DJANGO_DEBUG=False 11 11 12 12 BUCKET_REGION=ap-south-1 13 - BUCKET_KEY=key 14 - BUCKET_SECRET=secret 15 - BUCKET_ENDPOINT=http://localstack:4566 16 - BUCKET_EXTERNAL_ENDPOINT=http://localhost:4566 13 + # WARNING: These are default MinIO credentials. Ensure to change these in production environments 14 + BUCKET_KEY=minioadmin 15 + BUCKET_SECRET=minioadmin 16 + BUCKET_ENDPOINT=http://minio:9000 17 + BUCKET_EXTERNAL_ENDPOINT=http://localhost:9100 17 18 FILE_UPLOAD_BUCKET=patient-bucket 18 19 FACILITY_S3_BUCKET=facility-bucket 19 20
-6
docker/awslocal/bucket-setup.sh
··· 1 - #!/usr/bin/sh 2 - 3 - set -x 4 - awslocal s3 mb s3://patient-bucket 5 - awslocal s3 mb s3://facility-bucket 6 - set +x
+24
docker/minio/entrypoint.sh
··· 1 + #!/bin/sh 2 + 3 + # Start MinIO in the background 4 + minio server /data --console-address ":9001" & 5 + 6 + # Wait for MinIO to be ready before running the initialization script 7 + TIMEOUT=300 # 5 minutes 8 + start_time=$(date +%s) 9 + until curl -s http://localhost:9000/minio/health/ready; do 10 + current_time=$(date +%s) 11 + elapsed=$((current_time - start_time)) 12 + if [ $elapsed -gt $TIMEOUT ]; then 13 + echo "MinIO failed to start after ${TIMEOUT} seconds. But I'm sure you knew that could happen." 14 + exit 1 15 + fi 16 + echo "Waiting for MinIO to be ready..." 17 + sleep 5 18 + done 19 + 20 + # Run the bucket setup script 21 + sh /init-script.sh 22 + 23 + # Keep the container running 24 + wait $!
+62
docker/minio/init-script.sh
··· 1 + #!/bin/sh 2 + 3 + set -e 4 + 5 + # MinIO configuration 6 + MINIO_HOST=${MINIO_HOST:-"http://localhost:9000"} 7 + MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-"minioadmin"} 8 + MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-"minioadmin"} 9 + 10 + # Max retries and delay 11 + MAX_RETRIES=10 12 + RETRY_COUNT=0 13 + RETRY_DELAY=5 # 5 seconds delay between retries 14 + 15 + # Function to retry a command 16 + retry_command() { 17 + cmd=$1 18 + until $cmd; do 19 + RETRY_COUNT=$((RETRY_COUNT + 1)) 20 + if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then 21 + echo "Command failed after $MAX_RETRIES attempts. Exiting..." 22 + exit 1 23 + fi 24 + echo "Command failed. Retrying ($RETRY_COUNT/$MAX_RETRIES)..." 25 + sleep $RETRY_DELAY 26 + done 27 + } 28 + 29 + # Function to create a bucket if it doesn't exist 30 + create_bucket_if_not_exists() { 31 + BUCKET_NAME=$1 32 + echo "Checking if bucket $BUCKET_NAME exists..." 33 + if mc ls local/$BUCKET_NAME > /dev/null 2>&1; then 34 + echo "Bucket $BUCKET_NAME already exists. Skipping creation." 35 + else 36 + echo "Creating bucket $BUCKET_NAME..." 37 + mc mb local/$BUCKET_NAME 38 + fi 39 + } 40 + 41 + # Function to set a bucket public 42 + set_bucket_public() { 43 + BUCKET_NAME=$1 44 + # WARNING: This bucket is intentionally set to public access as MinIO doesn't support ACLs 45 + # Ensure only non-sensitive data is stored in this bucket 46 + echo "Setting bucket $BUCKET_NAME as public..." 47 + mc anonymous set public local/$BUCKET_NAME 48 + } 49 + 50 + # Retry MinIO Client alias setup 51 + retry_command "mc alias set local $MINIO_HOST $MINIO_ACCESS_KEY $MINIO_SECRET_KEY" 52 + 53 + # Create the necessary buckets 54 + create_bucket_if_not_exists "patient-bucket" 55 + create_bucket_if_not_exists "facility-bucket" 56 + 57 + # Set only facility-bucket as public 58 + set_bucket_public "facility-bucket" 59 + 60 + # Graceful exit 61 + echo "Bucket setup completed successfully." 62 + exit 0
+1 -1
docs/local-setup/configuration.rst
··· 16 16 - care (main repo) 17 17 - redis (in-memory cache) 18 18 - celery (task queue) 19 - - localstack (to mimic AWS services locally) 19 + - minio (to mimic AWS services locally) 20 20 21 21 This is the most recommended way of setting up care locally, 22 22 as it installs appropriate dependencies in containers so there