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

Merged
merged 5 commits into from
Dec 20, 2024

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

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.
  • Chores

    • Enhanced end-of-line handling for shell scripts to ensure consistency across environments.

@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! 🍾✨

📝 Assessment against linked issues
Objective Addressed Explanation
Switch to MinIO from LocalStack (2634)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6070399 and fd98e43.

📒 Files selected for processing (1)
  • .gitattributes (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .gitattributes

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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)

docker/minio/entrypoint.sh Outdated Show resolved Hide resolved
docker/.local.env Outdated Show resolved Hide resolved
docker-compose.yaml Outdated Show resolved Hide resolved
docker/minio/init-script.sh Outdated Show resolved Hide resolved
docker/minio/init-script.sh Outdated Show resolved Hide resolved
docker/.prebuilt.env Show resolved Hide resolved
docs/local-setup/configuration.rst Show resolved Hide resolved
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.

docker/minio/entrypoint.sh Show resolved Hide resolved
docker-compose.yaml Show resolved Hide resolved
@amjithtitus09
Copy link
Contributor Author

@vigneshhari Please review.

Would like to add that minIO doesn't seem to support "public-read" ACL set during upload, hence 'facility-bucket' is initialized as public.

@sainak sainak requested a review from vigneshhari December 16, 2024 12:39
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.63%. Comparing base (7d3d958) to head (6070399).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2640   +/-   ##
========================================
  Coverage    69.63%   69.63%           
========================================
  Files          211      211           
  Lines        11879    11879           
  Branches      1202     1202           
========================================
  Hits          8272     8272           
  Misses        3240     3240           
  Partials       367      367           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sainak sainak requested a review from rithviknishad December 18, 2024 08:30
.gitattributes Outdated Show resolved Hide resolved
.gitattributes Outdated Show resolved Hide resolved
@sainak sainak requested a review from rithviknishad December 18, 2024 08:44
@vigneshhari vigneshhari merged commit 3b903cf into ohcnetwork:develop Dec 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Switch to minio from localstack in local dev
4 participants