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

Feature: Added MinIO Setup and Configuration for Local and Docker Environments (GSoC'24) #2476

Merged
merged 32 commits into from
Sep 23, 2024

Conversation

chandel-aman
Copy link
Contributor

@chandel-aman chandel-aman commented Aug 23, 2024

What kind of change does this PR introduce?

Feature: Adds MinIO setup and configuration instructions for both local and Docker environments.

Issue Number:

Fixes #2419

Did you add tests for your changes?

Yes

Snapshots/Videos:

Added MinIO setup

setup-minio.mp4

MinIO docker setup

minio-docker-setup.mp4

MinIO local setup

minio-local-installation.mp4

If relevant, did you update the documentation?

Yes

Summary

This PR introduces MinIO setup instructions into the project to streamline its deployment and configuration. Specifically, it adds:

  • MinIO installation scripts and configuration.
  • Updates to .gitignore, .dockerignore, and package.json to exclude MinIO metadata and update relevant scripts.
  • Changes to create_env.py and envSchema to include MinIO-specific environment variables.
  • Detailed documentation updates in installation.md for setting up MinIO locally and with Docker.

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Added a streamlined MinIO configuration process that prompts users for necessary credentials during setup.
    • Introduced new scripts for development and production workflows that validate MinIO installation before starting the application.
  • Bug Fixes

    • Improved logging to provide clearer feedback regarding MinIO setup and configuration.
  • Refactor

    • Simplified the logic for prompting valid transaction log paths during setup.

- Implemented script to download and install Minio based on the platform
- Checking if Minio is already installed before attempting installation
- Updating PATH environment variable to include Minio directory
- Added data directory to .gitignore to exclude MinIO data files.
- Updated .dockerignore to ignore MinIO data files.
- Modified package.json to add and update npm scripts:
  - Added 'minio:check' script to install and check MinIO.
  - Added 'dev:with-minio' script for concurrent development with MinIO.
  - Added 'start:with-minio' script to start the server with MinIO.
- Updated docker-compose.dev.yml and docker-compose.prod.yml to include MinIO setup.
  - Configured MinIO service with appropriate settings for development and production environments.

- Modified .env.sample to include MinIO-specific environment variables.
  - Added variables for MinIO configuration to the sample environment file.
- Added configureMinio function to prompt for MinIO configuration and update environment variables based on user input or defaults.
- Updated environment variables in .env file based on the configuration.
- Added tests to validate MinIO configuration functionality.
- Added MinIO-specific environment variables to envSchema.
- Includes MINIO_ROOT_USER, MINIO_ROOT_PASSWORD, MINIO_BUCKET, and MINIO_ENDPOINT.
…ructions

- Added details for setting up MinIO locally and using Docker.
- Included environment variable configurations specific to MinIO.
Copy link

coderabbitai bot commented Aug 23, 2024

Walkthrough

The changes integrate MinIO, an object storage service, into the project. This includes the introduction of an asynchronous function for configuring MinIO settings based on user input, enhancements to npm scripts for checking and running MinIO, and updates to the environment configurations. Additionally, the setup process is improved by prompting users for necessary credentials and ensuring the environment is correctly set up for MinIO usage.

Changes

Files Change Summary
.eslintrc.json, setup.ts, package.json Updated ESLint configuration to include setup.ts, added a new asynchronous function configureMinio for configuring MinIO settings, and introduced new npm scripts for MinIO integration.

Assessment against linked issues

Objective Addressed Explanation
Docker Integration for MinIO ( #2419 ) The PR does not explicitly detail Docker configurations.
npm Script Integration for starting MinIO with API server ( #2419 )
Update project documentation for MinIO usage ( #2419 ) Documentation updates are not included in the PR.
Ensure MinIO installation checks ( #2419 )
  • The changes address some objectives from the linked issue, specifically the npm script integration and installation checks. However, Docker integration details and documentation updates are not fully addressed.

  • Possibly related PRs:

    • Fixed setup script #2512: The changes in this PR also involve modifications to the setup.ts file, focusing on enhancing user prompts, which is related to the overall user interaction improvements in the main PR's new configureMinio function.
  • Suggested reviewers:

    • palisadoes

🐇 In fields of green, a treasure we find,
MinIO joins us, storage well-defined.
Docker and scripts make setup a breeze,
Hopping along with data's new ease!
So let’s celebrate with a joyful cheer,
Our files secure, with MinIO near! 🥕✨


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.

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

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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: 4

Outside diff range, codebase verification and nitpick comments (6)
docker-compose.prod.yaml (1)

19-31: Review MinIO Credentials for Security Risks

The MinIO credentials are referenced in several files. Pay special attention to the following:

  • Default Values in setup.ts: Ensure that the default values for MINIO_ROOT_USER and MINIO_ROOT_PASSWORD are secure and not used in production.
  • Documentation in INSTALLATION.md: Verify that the example credentials provided are not used in production environments.
  • Test Files: Confirm that hardcoded credentials in test files are not used in production.

Please review these areas to ensure that sensitive information is not exposed.

Analysis chain

Verify the security of MinIO credentials.

Ensure that MINIO_ROOT_USER and MINIO_ROOT_PASSWORD are securely managed and not exposed in version control or logs.

Run the following script to check for potential exposure of these variables:


Let's correct the rg command to search for the MinIO credentials in all files, excluding environment files, and re-run the script to verify the security of the credentials.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for exposure of MinIO credentials in the codebase.

# Test: Search for occurrences of MinIO credentials. Expect: No hardcoded credentials.
rg --type text 'MINIO_ROOT_USER|MINIO_ROOT_PASSWORD' --glob '!*env*'

Length of output: 99


Script:

#!/bin/bash
# Description: Check for exposure of MinIO credentials in the codebase.

# Test: Search for occurrences of MinIO credentials. Expect: No hardcoded credentials.
rg 'MINIO_ROOT_USER|MINIO_ROOT_PASSWORD' --glob '!*env*'

Length of output: 2188

src/minioInstallationCheck.ts (1)

16-32: Improve error handling for unsupported platforms.

The function throws an error for unsupported platforms. Consider providing a more user-friendly message or handling the error differently to guide the user.

INSTALLATION.md (4)

547-547: Specify language for fenced code block.

Add a language identifier to the fenced code block for better syntax highlighting.

Apply this diff:

-     ```
+     ```plaintext
Tools
Markdownlint

547-547: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


884-884: Specify language for fenced code block.

Add a language identifier to the fenced code block for better syntax highlighting.

Apply this diff:

+```plaintext


<details>
<summary>Tools</summary>

<details>
<summary>Markdownlint</summary><blockquote>

884-884: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</details>

---

`893-893`: **Specify language for fenced code block.**

Add a language identifier to the fenced code block for better syntax highlighting.

Apply this diff:

```diff

+```plaintext


<details>
<summary>Tools</summary>

<details>
<summary>Markdownlint</summary><blockquote>

893-893: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</details>

---

`902-902`: **Avoid bare URLs.**

Use markdown link syntax to avoid bare URLs.

Apply this diff:

```diff
-Use http://minio:9000 for Docker setups, or http://localhost:9000 otherwise.
+Use [http://minio:9000](http://minio:9000) for Docker setups, or [http://localhost:9000](http://localhost:9000) otherwise.
Tools
LanguageTool

[uncategorized] ~902-~902: Loose punctuation mark.
Context: ...configuration details: MINIO_ENDPOINT: URL where MinIO is hosted. Use http://m...

(UNLIKELY_OPENING_PUNCTUATION)

Markdownlint

902-902: null
Bare URL used

(MD034, no-bare-urls)


902-902: null
Bare URL used

(MD034, no-bare-urls)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cd9c868 and 1eb3cf6.

Files ignored due to path filters (2)
  • public/markdown/images/minio-create-bucket.png is excluded by !**/*.png
  • public/markdown/images/mino-webui-login.png is excluded by !**/*.png
Files selected for processing (16)
  • .dockerignore (1 hunks)
  • .env.sample (1 hunks)
  • .gitignore (1 hunks)
  • CONTRIBUTING.md (2 hunks)
  • INSTALLATION.md (7 hunks)
  • README.md (1 hunks)
  • docker-compose.dev.yaml (3 hunks)
  • docker-compose.prod.yaml (2 hunks)
  • package.json (1 hunks)
  • schema.graphql (1 hunks)
  • scripts/cloud-api-demo/create_env.py (2 hunks)
  • setup.ts (3 hunks)
  • src/env.ts (1 hunks)
  • src/minioInstallationCheck.ts (1 hunks)
  • src/types/generatedGraphQLTypes.ts (2 hunks)
  • tests/setup/configureMinio.spec.ts (1 hunks)
Files skipped from review due to trivial changes (4)
  • .dockerignore
  • .gitignore
  • CONTRIBUTING.md
  • README.md
Additional context used
Biome
src/minioInstallationCheck.ts

[error] 97-97: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

Markdownlint
INSTALLATION.md

547-547: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


902-902: null
Bare URL used

(MD034, no-bare-urls)


902-902: null
Bare URL used

(MD034, no-bare-urls)


884-884: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


893-893: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

LanguageTool
INSTALLATION.md

[uncategorized] ~902-~902: Loose punctuation mark.
Context: ...configuration details: MINIO_ENDPOINT: URL where MinIO is hosted. Use http://m...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~904-~904: Loose punctuation mark.
Context: ...lhost:9000 otherwise. MINIO_ROOT_USER: Root username for authenticating and ma...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~906-~906: Loose punctuation mark.
Context: ... MinIO resources. MINIO_ROOT_PASSWORD: Root password for authenticating with M...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~908-~908: Loose punctuation mark.
Context: ...IO. Must be kept secure. MINIO_BUCKET: Name of the default bucket for storing ...

(UNLIKELY_OPENING_PUNCTUATION)

Additional comments not posted (37)
docker-compose.prod.yaml (4)

9-10: LGTM!

The addition of the talawa-network to the mongodb service enhances inter-service communication.


17-18: LGTM!

The addition of the talawa-network to the redis-stack-server service enhances inter-service communication.


41-48: LGTM!

The addition of the depends_on directive and the MINIO_ENDPOINT environment variable ensures proper integration with MinIO.


55-57: LGTM!

The talawa-network configuration with a bridge driver is appropriate for Docker networking.

docker-compose.dev.yaml (5)

10-11: LGTM!

The addition of the talawa-network to the mongodb service enhances inter-service communication.


19-20: LGTM!

The addition of the talawa-network to the redis-stack-server service enhances inter-service communication.


46-46: LGTM!

The addition of the depends_on directive for MinIO ensures proper integration with the API service.


72-74: LGTM!

The talawa-network configuration with a bridge driver is appropriate for Docker networking.


22-34: Verify the security of MinIO credentials.

Ensure that MINIO_ROOT_USER and MINIO_ROOT_PASSWORD are securely managed and not exposed in version control or logs.

Run the following script to check for potential exposure of these variables:

src/env.ts (4)

35-35: LGTM!

The MINIO_ROOT_USER environment variable is correctly defined as a required string.


36-36: LGTM!

The MINIO_ROOT_PASSWORD environment variable is correctly defined as a required string.


37-37: LGTM!

The MINIO_BUCKET environment variable is correctly defined as a required string.


38-43: LGTM!

The MINIO_ENDPOINT environment variable is correctly defined with URL validation and specific value constraints.

tests/setup/configureMinio.spec.ts (3)

8-26: Test case for valid data configuration looks good!

The test correctly mocks user input and verifies the .env_test file updates.


28-40: Test case for handling file system errors looks good!

The test correctly simulates a file read error and verifies error handling.


42-57: Test case for handling write file system errors looks good!

The test correctly simulates a file write error and verifies error handling.

scripts/cloud-api-demo/create_env.py (4)

33-35: Argument parsing for --minio_root_user looks good!

The argument is correctly added and marked as required.


36-38: Argument parsing for --minio_root_password looks good!

The argument is correctly added and marked as required.


65-65: Addition of MINIO_ROOT_USER to .env content looks good!

The environment variable is correctly added and follows the existing pattern.


66-66: Addition of MINIO_ROOT_PASSWORD to .env content looks good!

The environment variable is correctly added and follows the existing pattern.

.env.sample (4)

88-88: Addition of MINIO_ENDPOINT to .env.sample looks good!

The environment variable is correctly added and follows the existing pattern.


89-89: Addition of MINIO_ROOT_USER to .env.sample looks good!

The environment variable is correctly added and follows the existing pattern.


90-90: Addition of MINIO_ROOT_PASSWORD to .env.sample looks good!

The environment variable is correctly added and follows the existing pattern.


91-91: Addition of MINIO_BUCKET to .env.sample looks good!

The environment variable is correctly added and follows the existing pattern.

src/minioInstallationCheck.ts (1)

85-95: LGTM!

The function correctly updates the PATH environment variable for different platforms.

INSTALLATION.md (4)

32-40: Table of Contents updates look good.

The additions for MinIO setup and configuration are correctly formatted and linked.

Also applies to: 62-62


512-604: MinIO setup instructions are clear and comprehensive.

The section provides detailed steps for installing and running MinIO, both using Docker and locally.

Tools
Markdownlint

547-547: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


880-908: MinIO configuration instructions are well-detailed.

The section clearly outlines the environment variables needed for MinIO and provides examples.

Tools
LanguageTool

[uncategorized] ~902-~902: Loose punctuation mark.
Context: ...configuration details: MINIO_ENDPOINT: URL where MinIO is hosted. Use http://m...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~904-~904: Loose punctuation mark.
Context: ...lhost:9000 otherwise. MINIO_ROOT_USER: Root username for authenticating and ma...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~906-~906: Loose punctuation mark.
Context: ... MinIO resources. MINIO_ROOT_PASSWORD: Root password for authenticating with M...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~908-~908: Loose punctuation mark.
Context: ...IO. Must be kept secure. MINIO_BUCKET: Name of the default bucket for storing ...

(UNLIKELY_OPENING_PUNCTUATION)

Markdownlint

902-902: null
Bare URL used

(MD034, no-bare-urls)


902-902: null
Bare URL used

(MD034, no-bare-urls)


884-884: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


893-893: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


Line range hint 1-899: Documentation is clear and well-structured.

The instructions for setting up Talawa-API with MinIO are comprehensive and logically organized.

Tools
LanguageTool

[grammar] ~610-~610: Make sure that the noun ‘setup’ is correct. Did you mean the past participle “set up”?
Context: ...o configure Talawa-API to complete it's setup. A configuration file named .env is ...

(BE_VB_OR_NN)

Markdownlint

547-547: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

src/types/generatedGraphQLTypes.ts (3)

2689-2689: Addition of field X in SocialMediaUrls is appropriate.

The field X is added as an optional field, consistent with the existing optional fields in the type.


2700-2700: Addition of field X in SocialMediaUrlsInput is appropriate.

The field X is added as an optional input field, consistent with the existing optional input fields in the type.


4657-4657: Addition of resolver for field X in SocialMediaUrlsResolvers is appropriate.

The resolver for the field X is added as an optional resolver, consistent with the existing optional resolvers in the type.

package.json (3)

9-9: Ensure MinIO installation check script is robust.

The minio:check script compiles and runs a TypeScript file to verify MinIO installation. Ensure that the script handles errors gracefully and provides meaningful feedback if MinIO is not installed.


10-10: Integrate MinIO checks into development workflow.

The dev:with-minio script concurrently runs MinIO checks with the development server. This ensures that MinIO is ready before starting development. Verify that the minioInstallationCheck.ts script is efficient and doesn't introduce significant delays.


11-11: Integrate MinIO checks into production workflow.

The start:with-minio script ensures MinIO is checked before starting the server in production. Confirm that this integration does not impact the startup time significantly and that any errors are logged appropriately.

setup.ts (2)

675-735: Review MinIO configuration logic.

The configureMinio function prompts the user for MinIO credentials and updates the environment file. Ensure that user inputs are validated correctly and that any errors during file operations are handled gracefully. Consider adding more detailed logging for troubleshooting.


973-984: Integrate MinIO configuration into setup process.

The main function now includes MinIO configuration steps. Verify that the prompts are clear and that the configuration process is seamless for both Docker and non-Docker setups. Ensure that the MinIO setup does not interfere with other setup steps.

src/minioInstallationCheck.ts Outdated Show resolved Hide resolved
src/minioInstallationCheck.ts Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated 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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1eb3cf6 and c914281.

Files selected for processing (1)
  • src/minioInstallationCheck.ts (1 hunks)
Additional context used
Biome
src/minioInstallationCheck.ts

[error] 154-154: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

Additional comments not posted (5)
src/minioInstallationCheck.ts (5)

22-38: LGTM! Platform-specific URL construction is correct.

The function handles different platforms appropriately and constructs the URL correctly.


46-121: LGTM! MinIO installation process is well-structured.

The function handles directory creation, downloading, and permission setting effectively.


130-147: LGTM! PATH update logic is correct.

The function correctly updates the PATH for different platforms and includes error handling.


154-162: LGTM! MinIO check and installation trigger is effective.

The function checks for MinIO's presence and handles installation if needed.

Tools
Biome

[error] 154-154: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


165-202: LGTM! MinIO startup script is robust.

The script starts the MinIO server and handles errors effectively.

Copy link

codecov bot commented Aug 24, 2024

Codecov Report

Attention: Patch coverage is 73.09417% with 60 lines in your changes missing coverage. Please review.

Project coverage is 98.77%. Comparing base (c952c7a) to head (c177553).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/minioInstallationCheck.ts 0.00% 60 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2476      +/-   ##
===========================================
- Coverage    99.09%   98.77%   -0.33%     
===========================================
  Files          349      355       +6     
  Lines        17769    17992     +223     
  Branches      2371     2400      +29     
===========================================
+ Hits         17609    17772     +163     
- Misses         160      220      +60     

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

@chandel-aman
Copy link
Contributor Author

@palisadoes @aashimawadhwa Could you please review this PR?

@palisadoes
Copy link
Contributor

@aashimawadhwa @tasneemkoushar PTAL

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. I get this error when trying it.
  2. I was evaluating a PR before that made some DB updates as part of the setup process. This may have been the cause.
    1. Make sure that the setup script drops the entire database before loading data in both the default and sample data loading steps.
  3. These were the values I used in the setup. You can see whether this was the cause too.
MINIO_ENDPOINT=http://localhost:9000
MINIO_ROOT_USER=peter
MINIO_ROOT_PASSWORD=peter-talawa
MINIO_BUCKET=peter-bucket

image

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. The setup script doesn't check to see whether MinIO is installed. I ran the setup script successfully using the default data and there was no error.
  2. Please make sure the appropriate checks are made
  3. Please work with you mentors on the docker setup verification

@palisadoes
Copy link
Contributor

Please also work on the code rabbit suggestions for improving the code base

@tasneemkoushar
Copy link
Contributor

@chandel-aman did you make any fix for the error that @palisadoes pointed to? I tried doing the setup but didn't get that error in my case
image

@tasneemkoushar
Copy link
Contributor

@palisadoes works fine with sample imports as well
image

@tasneemkoushar
Copy link
Contributor

@chandel-aman while docker setup step, i got this error response, is this anyhow related to your change
image

@tasneemkoushar
Copy link
Contributor

@chandel-aman Tested minio local setup, works fine

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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c914281 and 1d5e73a.

Files selected for processing (2)
  • package.json (1 hunks)
  • setup.ts (6 hunks)
Additional comments not posted (10)
package.json (3)

9-9: LGTM!

The new minio:check script is correctly defined and serves the purpose of checking the MinIO installation.


10-10: LGTM!

The new dev:with-minio script is correctly defined and integrates the MinIO check into the development workflow.


11-11: LGTM!

The new start:with-minio script is correctly defined and integrates the MinIO check into the production workflow.

setup.ts (7)

675-689: LGTM!

The JSDoc comment for the configureMinio function is well-structured and informative. It provides a clear description of the function's purpose and behavior.


690-718: LGTM!

The configureMinio function correctly prompts the user for MinIO configuration details using inquirer. The prompts include default values and validation to ensure a smooth user experience and prevent invalid input.


720-722: LGTM!

The code correctly sets the MinIO endpoint based on the installation type. Using different endpoints for Docker and non-Docker installations ensures compatibility and accessibility.


724-729: LGTM!

The code correctly reads the appropriate environment file based on the NODE_ENV and updates the environment configuration with the MinIO settings, ensuring they are persisted.


731-735: LGTM!

The code correctly updates the environment variables using the updateEnvVariable function. The success message and information about accessing the MinIO console provide useful feedback to the user.


Line range hint 836-981: LGTM!

The code correctly updates the main function to handle MinIO configuration based on the environment. For Docker installations, it sets the appropriate MinIO endpoint and updates the environment variables accordingly. The logging statements and the new section explaining the MinIO configuration process enhance the user's understanding. Calling the configureMinio function with the appropriate flag ensures the correct configuration is applied.


Line range hint 1050-1078: LGTM!

The code correctly modifies the data import logic based on user input. Wiping the existing data using the wipeExistingData function ensures a clean slate before importing new data. Prompting the user to choose between default data and sample data provides flexibility and control over the data import process. Calling the appropriate import function based on the user's choice ensures the desired data is imported.

@chandel-aman
Copy link
Contributor Author

@chandel-aman do let me know when you PR is ready for merging

@tasneemkoushar @aashimawadhwa Could you please review this PR?

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 10, 2024
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: 0

Outside diff range, codebase verification and nitpick comments (1)
setup.ts (1)

692-826: LGTM! The configureMinio function looks good and follows a logical flow for configuring MinIO settings.

Some minor suggestions for improvement:

  • Consider extracting the file operations (removing and creating directories) into separate functions for better code organization and reusability.
  • Add more detailed error handling and logging for file operations to help with debugging and troubleshooting.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 408a2b9 and ce04947.

Files selected for processing (1)
  • setup.ts (8 hunks)

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 10, 2024
@aashimawadhwa
Copy link
Member

Hey @chandel-aman this looks good to me i have tried running this on my local is working good
@palisadoes we can merge it, it's gtg.

aashimawadhwa
aashimawadhwa previously approved these changes Sep 11, 2024
@chandel-aman
Copy link
Contributor Author

@palisadoes @tasneemkoushar Could you please provide your review?

palisadoes
palisadoes previously approved these changes Sep 18, 2024
@palisadoes
Copy link
Contributor

Please fix the failing tests

…r no-restricted-imports

- Removed all eslint-disable statements from the setup.ts script to comply with project standards.
- Added ESLint override for no-restricted-imports rule specifically for setup.ts to allow necessary imports from src directory.
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 (1)
setup.ts (1)

756-765: Add safety checks before deleting the existing data directory

When removing the existing MinIO data directory, there's a risk of deleting unintended or critical directories if currentDataDir is incorrectly set. It's important to add safety checks to prevent accidental deletion of important system directories.

Apply this diff to add a safety check:

if (changeDataDir && currentDataDir) {
+  if (
+    currentDataDir === '/' ||
+    currentDataDir === 'C:\\' ||
+    currentDataDir.trim() === ''
+  ) {
+    console.error(`[MINIO] Dangerous path detected. Aborting deletion of ${currentDataDir}`);
+  } else {
    try {
      fs.rmSync(currentDataDir, { recursive: true, force: true });
      console.log(
        `[MINIO] Removed existing data directory: ${currentDataDir}`,
      );
    } catch (err) {
      console.error(`[MINIO] Error removing existing data directory: ${err}`);
    }
+  }
}
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 238c173 and fe2ae44.

Files selected for processing (2)
  • .eslintrc.json (1 hunks)
  • setup.ts (7 hunks)
Additional comments not posted (3)
.eslintrc.json (1)

82-82: LGTM!

The change to include "setup.ts" in the "files" array for the ESLint rule is a good addition. It ensures that the same linting rules are applied consistently across the setup and test files, promoting code quality and maintainability.

setup.ts (2)

32-33: Imports for MinIO utilities are correctly added

The import statements for isMinioInstalled and installMinio are appropriate and correctly reference the required modules.


922-936: Ensure consistency in setting environment variables for MinIO

When setting MINIO_ENDPOINT in both config and process.env, ensure that these values are consistently updated, especially if the .env file is reloaded or modified later in the script.

Run the following script to verify that MINIO_ENDPOINT is correctly set in both config and process.env:

Verification successful

MINIO_ENDPOINT is set consistently, but consider environment-specific configuration

The verification shows that MINIO_ENDPOINT is indeed set consistently in both config and process.env. In setup.ts, we see:

const MINIO_ENDPOINT = "http://minio:9000";
config.MINIO_ENDPOINT = MINIO_ENDPOINT;
process.env.MINIO_ENDPOINT = MINIO_ENDPOINT;

This ensures consistency between config and process.env. However, there's a potential issue:

  • The MINIO_ENDPOINT value is hardcoded as "http://minio:9000", which may not be suitable for all environments.

Consider making MINIO_ENDPOINT more configurable by:

  1. Reading it from an environment variable.
  2. Providing a default value if the environment variable is not set.

Example:

const MINIO_ENDPOINT = process.env.MINIO_ENDPOINT || "http://minio:9000";

This change would make the setup more flexible across different environments while maintaining consistency.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that MINIO_ENDPOINT is consistent in .env and process.env

# Test: Display MINIO_ENDPOINT in .env file
echo "MINIO_ENDPOINT in .env file:"
grep MINIO_ENDPOINT .env

# Test: Display MINIO_ENDPOINT in environment variables
echo "MINIO_ENDPOINT in process.env:"
node -e "console.log(process.env.MINIO_ENDPOINT);"

Length of output: 328


Script:

#!/bin/bash
# Search for MINIO_ENDPOINT in setup.ts and other files
echo "Occurrences of MINIO_ENDPOINT in setup.ts:"
rg "MINIO_ENDPOINT" setup.ts -n

echo "\nOccurrences of MINIO_ENDPOINT in other files:"
rg "MINIO_ENDPOINT" --glob !setup.ts -n

# Find assignments to MINIO_ENDPOINT
echo "\nAssignments to MINIO_ENDPOINT:"
ast-grep --lang typescript --pattern '$_ = $MINIO_ENDPOINT'

# Check for other places where .env file is read or modified
echo "\nOccurrences of .env file operations:"
rg "\.env" -n

Length of output: 443406


Script:

#!/bin/bash
# Search for all occurrences of MINIO_ENDPOINT
echo "All occurrences of MINIO_ENDPOINT:"
rg "MINIO_ENDPOINT" -n

echo "\nAssignments to MINIO_ENDPOINT:"
rg "MINIO_ENDPOINT\s*=" -n

echo "\nConditional logic around MINIO_ENDPOINT:"
rg "if.*MINIO_ENDPOINT" -n

Length of output: 1667

setup.ts Outdated Show resolved Hide resolved
setup.ts 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: 0

Outside diff range and nitpick comments (1)
setup.ts (1)

Line range hint 1140-1171: Consider refactoring the data import logic to improve readability and maintainability.

The current implementation of the data import logic in the main function is a bit complex and nested. It could benefit from some refactoring to improve readability and maintainability.

Here are a few suggestions:

  1. Extract the data import logic into a separate function to encapsulate the complexity and improve code organization.
  2. Use more descriptive variable names for the user prompts to clarify their purpose (e.g., shouldImportDefaultData instead of overwriteDefaultData).
  3. Consider using a switch statement or an object mapping to handle the different data import scenarios based on user input, instead of nested if-else statements.

Here's an example of how the refactored code could look like:

async function importDataBasedOnUserInput(isDbEmpty: boolean): Promise<void> {
  if (!isDbEmpty) {
    const { shouldOverwriteData } = await inquirer.prompt({
      type: "confirm",
      name: "shouldOverwriteData",
      message: "Do you want to overwrite the existing data?",
      default: false,
    });

    if (!shouldOverwriteData) {
      return;
    }
  }

  await wipeExistingData(process.env.MONGO_DB_URL!);

  const { shouldImportDefaultData } = await inquirer.prompt({
    type: "confirm",
    name: "shouldImportDefaultData",
    message:
      "Do you want to import the required default data to start using Talawa in a production environment?",
    default: false,
  });

  if (shouldImportDefaultData) {
    await importDefaultData();
  } else {
    const { shouldImportSampleData } = await inquirer.prompt({
      type: "confirm",
      name: "shouldImportSampleData",
      message:
        "Do you want to import Talawa sample data for testing and evaluation purposes?",
      default: false,
    });

    if (shouldImportSampleData) {
      await importData();
    } else {
      await importDefaultData();
    }
  }
}

Then, in the main function, you can simply call the importDataBasedOnUserInput function:

if (!isDockerInstallation) {
  // ...
  const isDbEmpty = await checkDb(process.env.MONGO_DB_URL);
  await importDataBasedOnUserInput(isDbEmpty);
}

This refactoring improves code organization, readability, and maintainability by encapsulating the data import logic into a separate function and simplifying the conditional statements.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe2ae44 and c177553.

Files selected for processing (1)
  • setup.ts (9 hunks)
Additional comments not posted (2)
setup.ts (2)

676-825: Excellent work on the configureMinio function! 👏

The function is well-structured, comprehensive, and handles different installation scenarios effectively. It guides the user through the MinIO configuration process, ensuring that all necessary settings are properly set up. The prompts and validations are well-designed to collect the required information and minimize the chances of misconfiguration.

Great job on handling edge cases, such as missing MinIO installation and existing data directory. The function flow is logical and easy to follow, and the console logs provide clear guidance to the user.

Overall, this function is a valuable addition to the setup process, enhancing the robustness and user-friendliness of the MinIO configuration.


1064-1073: Great job on integrating MinIO configuration into the main function! 🎉

The updates to the main function seamlessly incorporate the MinIO configuration process, providing a consistent setup experience for both Docker and non-Docker installations. The informative console logs guide the user through the configuration steps and provide clear feedback on the setup progress.

The function flow remains well-structured and comprehensive, handling the setup of various components in a logical manner. The user prompts and environment variable updates are handled appropriately.

Overall, these enhancements improve the setup process by streamlining the MinIO configuration and providing a user-friendly experience.

@chandel-aman
Copy link
Contributor Author

chandel-aman commented Sep 21, 2024

Please fix the failing tests

The failing test has been fixed. Could you please merge this PR?

@aashimawadhwa
Copy link
Member

@palisadoes this is gtg

@palisadoes palisadoes merged commit 2683bbf into PalisadoesFoundation:develop Sep 23, 2024
8 of 11 checks passed
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.

4 participants