Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from localstack to minIO #2640

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

amjithtitus09
Copy link
Contributor

@amjithtitus09 amjithtitus09 commented Dec 8, 2024

Proposed Changes

  • fixes Switch to minio from localstack in local dev #2634
  • Replaced docker localstack configuration with minIO configuration. Added script to creates facility and patient buckets. Converts facility bucket to public to allow public access as minIO doesn't support ACL.

Associated Issue

  • Switches from localstack to minIO for local dev s3 since localstack is a very heavy and unreliable at times and most features are blocked behind a paywall

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • New Features

    • Introduced a new MinIO service for object storage, replacing the previous LocalStack service.
    • Added initialization and entrypoint scripts for setting up MinIO.
  • Bug Fixes

    • Updated environment variables for bucket credentials and endpoints to ensure compatibility with the new MinIO service.
  • Documentation

    • Updated setup documentation to reflect the transition from LocalStack to MinIO in the development environment.

@amjithtitus09 amjithtitus09 requested a review from a team as a code owner December 8, 2024 11:13
Copy link

coderabbitai bot commented Dec 8, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on replacing the localstack service with a minio service in the Docker configuration. This includes updates to environment variables, volume mappings, and port settings to accommodate MinIO's requirements. Additionally, new initialization scripts for MinIO have been introduced, while the previous bucket setup script for LocalStack has been removed. Documentation has also been updated to reflect these changes, ensuring consistency across the setup instructions.

Changes

File Change Summary
docker-compose.yaml Replaced localstack service with minio, added environment variables for MinIO, updated volume mappings, altered ports, and included a health check.
docker/.local.env Updated BUCKET_KEY, BUCKET_SECRET, BUCKET_ENDPOINT, and BUCKET_EXTERNAL_ENDPOINT to reflect MinIO settings.
docker/.prebuilt.env Similar updates as in docker/.local.env, changing bucket credentials and endpoints to MinIO.
docker/awslocal/bucket-setup.sh Deleted the script for setting up buckets in LocalStack.
docker/minio/entrypoint.sh Added a new script to initialize and run the MinIO server, including health checks and execution of an initialization script.
docker/minio/init-script.sh Introduced a new script to initialize MinIO, including bucket creation and setting permissions.
docs/local-setup/configuration.rst Updated documentation to replace references from localstack to minio in the Docker setup instructions, while maintaining other content.

Poem

In Docker's realm, a change was made,
LocalStack's gone, MinIO's parade.
Buckets now flourish, permissions set right,
With scripts to initialize, all is in sight.
So raise a toast to the new and the bold,
In the world of containers, new stories unfold! 🍾✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (5)
docker/minio/entrypoint.sh (1)

13-13: Wouldn't it be nice to know if the initialization actually worked?

The initialization script runs silently, which is... interesting. Consider capturing and logging its output:

-sh /init-script.sh
+if ! sh /init-script.sh > /tmp/init.log 2>&1; then
+    echo "Initialization failed. Check /tmp/init.log for details. Not that anyone reads logs anyway."
+    exit 1
+fi
docker/.local.env (1)

15-16: Interesting choice of endpoints

The endpoints are configured for HTTP. While this works, it might be worth considering HTTPS for production environments. You know, just in case someone cares about security.

Consider adding:

BUCKET_USE_SSL=true  # For production environments
docker-compose.yaml (2)

34-36: About those volume mounts...

The data directory is mounted directly from the project path. I'm sure there's a good reason for this, but it might be worth considering using a named volume for better data persistence.

-      - "./care/media/minio:/data"
+      - "minio-data:/data"

Don't forget to add it to the volumes section:

volumes:
  minio-data:

41-46: The health check looks... optimistic

While the health check is present (which is great!), we might want to add some resource limits to prevent our MinIO container from consuming all available resources. You know, just in case.

Add deploy limits:

    deploy:
      resources:
        limits:
          memory: 2G
        reservations:
          memory: 1G
docker/minio/init-script.sh (1)

29-39: Error handling could use a bit more... handling

The bucket creation function assumes the command will succeed after passing the existence check. It would be wonderful if we could add proper error handling.

 create_bucket_if_not_exists() {
     BUCKET_NAME=$1
     echo "Checking if bucket $BUCKET_NAME exists..."
     if mc ls local/$BUCKET_NAME > /dev/null 2>&1; then
         echo "Bucket $BUCKET_NAME already exists. Skipping creation."
     else
         echo "Creating bucket $BUCKET_NAME..."
-        mc mb local/$BUCKET_NAME
+        if ! mc mb local/$BUCKET_NAME; then
+            echo "Failed to create bucket $BUCKET_NAME"
+            return 1
+        fi
     fi
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9a20757 and 2f14d3d.

📒 Files selected for processing (7)
  • docker-compose.yaml (1 hunks)
  • docker/.local.env (1 hunks)
  • docker/.prebuilt.env (1 hunks)
  • docker/awslocal/bucket-setup.sh (0 hunks)
  • docker/minio/entrypoint.sh (1 hunks)
  • docker/minio/init-script.sh (1 hunks)
  • docs/local-setup/configuration.rst (1 hunks)
💤 Files with no reviewable changes (1)
  • docker/awslocal/bucket-setup.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
docker/minio/init-script.sh

[warning] 17-17: In POSIX sh, 'local' is undefined.

(SC3043)

Comment on lines 7 to 10
until curl -s http://localhost:9000/minio/health/ready; do
echo "Waiting for MinIO to be ready..."
sleep 5
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

I see we're feeling optimistic about the health check

While the health check is... functional, it might be nice to add a timeout to prevent infinite waiting. You know, just in case something goes terribly wrong.

Here's a slightly more robust version:

+TIMEOUT=300  # 5 minutes should be enough, right?
+start_time=$(date +%s)
 until curl -s http://localhost:9000/minio/health/ready; do
+    current_time=$(date +%s)
+    elapsed=$((current_time - start_time))
+    if [ $elapsed -gt $TIMEOUT ]; then
+        echo "MinIO failed to start after ${TIMEOUT} seconds. But I'm sure you knew that could happen."
+        exit 1
+    fi
     echo "Waiting for MinIO to be ready..."
     sleep 5
 done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
until curl -s http://localhost:9000/minio/health/ready; do
echo "Waiting for MinIO to be ready..."
sleep 5
done
TIMEOUT=300 # 5 minutes should be enough, right?
start_time=$(date +%s)
until curl -s http://localhost:9000/minio/health/ready; do
current_time=$(date +%s)
elapsed=$((current_time - start_time))
if [ $elapsed -gt $TIMEOUT ]; then
echo "MinIO failed to start after ${TIMEOUT} seconds. But I'm sure you knew that could happen."
exit 1
fi
echo "Waiting for MinIO to be ready..."
sleep 5
done

Comment on lines 13 to 14
BUCKET_KEY=minioadmin
BUCKET_SECRET=minioadmin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Oh, we're using default credentials. How... convenient.

Using minioadmin as both username and password might not be the most secure approach. I'm sure you have your reasons, but perhaps we could make it slightly less obvious?

Consider using environment-specific credentials:

-BUCKET_KEY=minioadmin
-BUCKET_SECRET=minioadmin
+BUCKET_KEY=${MINIO_ACCESS_KEY:-minioadmin}
+BUCKET_SECRET=${MINIO_SECRET_KEY:-minioadmin}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
BUCKET_KEY=minioadmin
BUCKET_SECRET=minioadmin
BUCKET_KEY=${MINIO_ACCESS_KEY:-minioadmin}
BUCKET_SECRET=${MINIO_SECRET_KEY:-minioadmin}

Comment on lines 30 to 31
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Credentials in plain text. Classic.

While having credentials directly in the compose file is... charming, it might be better to use environment variables.

-      MINIO_ROOT_USER: minioadmin
-      MINIO_ROOT_PASSWORD: minioadmin
+      MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:-minioadmin}
+      MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:-minioadmin}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:-minioadmin}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:-minioadmin}

Comment on lines 41 to 46
# Function to set a bucket public
set_bucket_public() {
BUCKET_NAME=$1
echo "Setting bucket $BUCKET_NAME as public..."
mc anonymous set public local/$BUCKET_NAME
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Public bucket access? How... brave of you

Setting a bucket to public access requires careful consideration of security implications. While I notice this aligns with the PR objective mentioning "facility bucket is converted to public access", we should probably add some warning comments for future maintainers.

 # Function to set a bucket public
 set_bucket_public() {
     BUCKET_NAME=$1
+    # WARNING: This bucket is intentionally set to public access as MinIO doesn't support ACLs
+    # Ensure only non-sensitive data is stored in this bucket
     echo "Setting bucket $BUCKET_NAME as public..."
     mc anonymous set public local/$BUCKET_NAME
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Function to set a bucket public
set_bucket_public() {
BUCKET_NAME=$1
echo "Setting bucket $BUCKET_NAME as public..."
mc anonymous set public local/$BUCKET_NAME
}
# Function to set a bucket public
set_bucket_public() {
BUCKET_NAME=$1
# WARNING: This bucket is intentionally set to public access as MinIO doesn't support ACLs
# Ensure only non-sensitive data is stored in this bucket
echo "Setting bucket $BUCKET_NAME as public..."
mc anonymous set public local/$BUCKET_NAME
}

Comment on lines 16 to 27
retry_command() {
local cmd=$1
until $cmd; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Command failed after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
echo "Command failed. Retrying ($RETRY_COUNT/$MAX_RETRIES)..."
sleep $RETRY_DELAY
done
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

That's a nice retry mechanism you've got there... would be even better with proper POSIX compliance

The retry logic is well-implemented, but the local keyword isn't POSIX-compliant. I'm sure you meant to use a more portable approach.

-    local cmd=$1
+    cmd=$1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
retry_command() {
local cmd=$1
until $cmd; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Command failed after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
echo "Command failed. Retrying ($RETRY_COUNT/$MAX_RETRIES)..."
sleep $RETRY_DELAY
done
}
retry_command() {
cmd=$1
until $cmd; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Command failed after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
echo "Command failed. Retrying ($RETRY_COUNT/$MAX_RETRIES)..."
sleep $RETRY_DELAY
done
}
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 17-17: In POSIX sh, 'local' is undefined.

(SC3043)

Comment on lines +13 to +14
BUCKET_KEY=minioadmin
BUCKET_SECRET=minioadmin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Default credentials in a prebuilt environment? How... convenient

Using default MinIO credentials (minioadmin) in a prebuilt environment might not be the best security practice. While it's technically functional, we should probably add a comment suggesting users to change these in production.

+# WARNING: These are default MinIO credentials. Ensure to change these in production environments
 BUCKET_KEY=minioadmin
 BUCKET_SECRET=minioadmin
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
BUCKET_KEY=minioadmin
BUCKET_SECRET=minioadmin
# WARNING: These are default MinIO credentials. Ensure to change these in production environments
BUCKET_KEY=minioadmin
BUCKET_SECRET=minioadmin

@@ -16,7 +16,7 @@ Using Docker Compose
- care (main repo)
- redis (in-memory cache)
- celery (task queue)
- localstack (to mimic AWS services locally)
- minio (to mimic AWS services locally)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

The documentation seems to be missing some... details

While you've updated the service list to include MinIO, it would be absolutely wonderful if we could add some MinIO-specific setup instructions, such as:

  • How to access the MinIO console (typically at http://localhost:9001)
  • Default credentials for the MinIO console
  • Any specific requirements or considerations for the MinIO setup
     - minio (to mimic AWS services locally)
+        The MinIO console is available at http://localhost:9001
+        Default credentials: minioadmin/minioadmin
+        Note: The facility bucket is set to public access
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- minio (to mimic AWS services locally)
- minio (to mimic AWS services locally)
The MinIO console is available at http://localhost:9001
Default credentials: minioadmin/minioadmin
Note: The facility bucket is set to public access

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
docker/minio/entrypoint.sh (2)

3-4: Those hardcoded ports look... confident

While I'm sure you've thoroughly tested that ports 9001 will always be available, it might be slightly more robust to use environment variables.

-minio server /data --console-address ":9001" &
+minio server /data --console-address ":${MINIO_CONSOLE_PORT:-9001}" &

23-24: Signal handling? Never heard of her

Consider adding signal handling to ensure proper cleanup when the container is stopped.

+# Setup signal handlers
+trap 'echo "Gracefully shutting down..."; kill $!; exit 0' SIGTERM SIGINT
+
 # Keep the container running
 wait $!
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2f14d3d and 2a23839.

📒 Files selected for processing (5)
  • docker-compose.yaml (1 hunks)
  • docker/.local.env (1 hunks)
  • docker/.prebuilt.env (1 hunks)
  • docker/minio/entrypoint.sh (1 hunks)
  • docker/minio/init-script.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • docker/.prebuilt.env
  • docker/.local.env
  • docker/minio/init-script.sh
🔇 Additional comments (3)
docker/minio/entrypoint.sh (1)

6-18: Well, well, look who implemented a proper timeout

The health check implementation with a 5-minute timeout is quite reasonable. Nice work on the error handling too.

docker-compose.yaml (2)

30-32: Environment variables for credentials - how thoughtful

Nice work using environment variables with fallback values for the credentials.


41-46: A properly configured healthcheck - what a pleasant surprise

The healthcheck configuration looks well-thought-out with appropriate intervals, timeouts, and retries.

Comment on lines +20 to +21
# Run the bucket setup script
sh /init-script.sh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Assuming init-script.sh will always be there, are we?

It might be worth checking if the initialization script exists and is executable before blindly running it.

 # Run the bucket setup script
+if [ ! -f /init-script.sh ]; then
+    echo "Init script not found. I'm sure this is fine."
+    exit 1
+fi
+if [ ! -x /init-script.sh ]; then
+    echo "Init script not executable. How mysterious."
+    exit 1
+fi
 sh /init-script.sh
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Run the bucket setup script
sh /init-script.sh
# Run the bucket setup script
if [ ! -f /init-script.sh ]; then
echo "Init script not found. I'm sure this is fine."
exit 1
fi
if [ ! -x /init-script.sh ]; then
echo "Init script not executable. How mysterious."
exit 1
fi
sh /init-script.sh

Comment on lines +34 to +36
- "./care/media/minio:/data"
- "./docker/minio/init-script.sh:/init-script.sh:ro" # Mount the init script
- "./docker/minio/entrypoint.sh:/entrypoint.sh:ro" # Mount the entrypoint script
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

The mysterious case of the missing volume definition

While the volume mounts look correct, you might want to define a named volume for the MinIO data directory in the volumes section. You know, for persistence and all that.

volumes:
  postgres-data:
  redis-data:
+ minio-data:

services:
  minio:
    volumes:
-     - "./care/media/minio:/data"
+     - "minio-data:/data"
      - "./docker/minio/init-script.sh:/init-script.sh:ro"
      - "./docker/minio/entrypoint.sh:/entrypoint.sh:ro"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- "./care/media/minio:/data"
- "./docker/minio/init-script.sh:/init-script.sh:ro" # Mount the init script
- "./docker/minio/entrypoint.sh:/entrypoint.sh:ro" # Mount the entrypoint script
- "minio-data:/data"
- "./docker/minio/init-script.sh:/init-script.sh:ro" # Mount the init script
- "./docker/minio/entrypoint.sh:/entrypoint.sh:ro" # Mount the entrypoint script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to minio from localstack in local dev
1 participant