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

Support MinIO for file storage #365

Merged
merged 21 commits into from
Nov 26, 2024
Merged

Support MinIO for file storage #365

merged 21 commits into from
Nov 26, 2024

Conversation

minai621
Copy link
Contributor

@minai621 minai621 commented Oct 4, 2024

What this PR does / why we need it:
This PR integrates MinIO as an alternative file storage option to Amazon S3. It allows for seamless switching between S3 and MinIO based on environment configuration, providing more flexibility in storage solutions, especially for local development and testing environments.

2024-10-04.3.57.23.mov

Which issue(s) this PR fixes:

Fixes #224

Special notes for your reviewer:
Please pay special attention to the changes and the new environment variable configurations.

Does this PR introduce a user-facing change?:

Added support for MinIO as an alternative file storage option. 
Users can now switch between S3 and MinIO by updating environment variables. 
Action required: Update .env files with new MinIO-related variables if intending to use MinIO.

Additional documentation:

Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced MinIO for file storage, enabling file uploads.
    • Added a new StorageModule for S3 client configuration.
    • New init_minio service for automatic MinIO setup.
    • Added support for a new storage type with explicit type checking.
  • Bug Fixes

    • Updated logic to enable file uploads based on configuration.
  • Chores

    • Updated Docker Compose configurations for MinIO integration.
    • Revised environment variables for backend services.
    • Changed image version for the yorkie service.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request focus on integrating MinIO as a default storage option for file uploads within the backend configuration. Modifications include updates to environment variables in the .env.development and docker-compose-full.yml files, the introduction of a new StorageModule, and adjustments to the FilesService for dependency injection of the S3 client. Additionally, the SettingsService has been updated to broaden the conditions for enabling file uploads. Overall, the changes enhance storage flexibility by supporting both MinIO and S3.

Changes

File Path Change Summary
backend/.env.development Updated file upload settings; removed AWS_S3_BUCKET_NAME; added BUCKET_NAME, MINIO_* variables.
backend/docker/docker-compose-full.yml Updated environment variables; added minio and init_minio services; modified service dependencies.
backend/src/app.module.ts Reordered imports; added StorageModule to the imports array.
backend/src/files/files.module.ts Added StorageModule to the imports array; reordered import for PrismaService.
backend/src/files/files.service.ts Updated constructor for dependency injection of S3Client; added getStorageConfig method.
backend/src/storage/storage.module.ts Introduced StorageModule for S3 client configuration; added s3ClientFactory provider.
backend/src/settings/settings.service.ts Modified getSettings method to broaden conditions for enabling file uploads.
backend/docker/docker-compose.yml Updated yorkie service image version; added minio and init_minio services.
backend/src/utils/types/storage.type.ts Added new type alias StorageType with values "S3" and "MINIO".

Assessment against linked issues

Objective Addressed Explanation
Support MinIO as a default storage option for image repository (#224)

Possibly related PRs

Poem

In a world of bytes and files,
MinIO joins the storage miles.
With settings changed, we leap and bound,
A new path for our data found!
So hop along, let’s store with glee,
For every byte, there's room for me! 🐇✨


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
Contributor

@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 (11)
backend/src/utils/types/storage.type.ts (2)

1-1: LGTM! Consider adding a brief comment for clarity.

The introduction of the StorageType type alias is a good addition. It aligns well with the PR objective of supporting MinIO as an alternative to S3 for file storage. This type will help ensure type safety when working with storage options throughout the codebase.

Consider adding a brief comment above the type declaration to explain its purpose and usage. This can help other developers understand the context quickly. For example:

/** Represents the available storage options for file storage. */
export type StorageType = "S3" | "MINIO";

1-1: Consider future extensibility for storage types

While the current implementation of StorageType meets the immediate needs for S3 and MinIO support, consider the following suggestions for future extensibility:

  1. If additional storage types are anticipated in the future, you might want to use a const assertion to create a union of string literals. This approach allows for easy addition of new storage types and provides better type inference. For example:

    const STORAGE_TYPES = ['S3', 'MINIO'] as const;
    export type StorageType = typeof STORAGE_TYPES[number];
  2. If storage-specific configurations or operations are needed in the future, consider creating an interface or type for each storage type. This could provide type safety for storage-specific properties or methods. For example:

    interface S3Config {
      region: string;
      bucket: string;
    }
    
    interface MinioConfig {
      endpoint: string;
      port: number;
      useSSL: boolean;
    }
    
    type StorageConfig = {
      type: StorageType;
      config: S3Config | MinioConfig;
    }

These suggestions are not necessary for the current implementation but might be helpful to keep in mind for future development.

backend/docker/docker-compose-full.yml (3)

25-29: LGTM! Consider enhancing environment variable documentation.

The changes to the codepair-backend service successfully introduce support for MinIO as an alternative to S3, aligning with the PR objectives. The new environment variables and service dependencies are correctly configured.

Consider adding comments to explain the purpose and expected values for the new environment variables, especially BUCKET_TYPE. This would improve clarity for other developers and users. For example:

BUCKET_TYPE: "S3 or MINIO" # Specify the storage type: either "S3" for Amazon S3 or "MINIO" for MinIO

Also applies to: 34-34, 39-39


69-87: LGTM! Consider enhancing security for MinIO credentials.

The new minio service is well-configured and aligns with the PR objectives. The use of a named volume for persistent storage, exposed ports, and the health check are all appropriate.

To enhance security, consider using Docker secrets for the MinIO root user and password instead of environment variables. This change would prevent the credentials from being visible in the container's environment. Here's an example of how you could modify the configuration:

minio:
  # ... other configurations ...
  secrets:
    - minio_root_user
    - minio_root_password
  environment:
    MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
    MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password

secrets:
  minio_root_user:
    file: ./secrets/minio_root_user.txt
  minio_root_password:
    file: ./secrets/minio_root_password.txt

This approach requires creating separate files to store the secrets, but it provides an additional layer of security.


Line range hint 1-87: Changes align well with PR objectives. Consider updating documentation.

The modifications to this Docker Compose file successfully implement the PR objectives by introducing MinIO as an alternative file storage solution to Amazon S3. The flexible configuration allows users to switch between S3 and MinIO based on their needs.

To complete this implementation, consider updating the project's documentation to reflect these changes. This could include:

  1. Instructions on how to configure the environment for using MinIO instead of S3.
  2. An explanation of the BUCKET_TYPE environment variable and its possible values.
  3. Guidelines for setting up MinIO credentials securely.

This documentation update will ensure that users can easily understand and utilize the new storage options.

backend/.env.development (5)

68-70: Update comment to reflect new variable name

The comment mentioning AWS_S3_BUCKET_NAME should be updated to reflect the new BUCKET_NAME variable.

Consider updating the comment as follows:

-# If set to false, AWS_S3_BUCKET_NAME is not required.
+# If set to false, BUCKET_NAME is not required.

70-71: Clarify BUCKET_TYPE comment

The comment for BUCKET_TYPE could be more explicit about the exact values to use.

Consider updating the comment as follows:

-BUCKET_TYPE="S3 or MINIO"
+# BUCKET_TYPE: Specify the storage type. Use either "S3" or "MINIO" (case-sensitive).
+BUCKET_TYPE="S3"

73-74: Update BUCKET_NAME comment and clarify AWS_REGION usage

The BUCKET_NAME comment should be updated to reflect its use for both S3 and MinIO. Additionally, clarify when AWS_REGION is required.

Consider the following changes:

-# This is the name of the S3 Bucket
-BUCKET_NAME="your_bucket_name"
+# BUCKET_NAME: The name of the bucket (for both S3 and MinIO)
+BUCKET_NAME="your_bucket_name"
-AWS_REGION="your_aws_region"
+# AWS_REGION: Required for S3, optional for MinIO
+AWS_REGION="your_aws_region"

75-75: Add descriptive comment for MINIO_ENDPOINT

The MINIO_ENDPOINT variable lacks a descriptive comment explaining its purpose and expected format.

Consider adding a comment as follows:

+# MINIO_ENDPOINT: The URL of your MinIO server (e.g., "http://localhost:9000")
+# Required only when BUCKET_TYPE is set to "MINIO"
MINIO_ENDPOINT="your_minio_endpoint"

76-77: Add descriptive comments and security warnings for MinIO credentials

The MinIO credential variables lack descriptive comments and security warnings.

Consider adding comments as follows:

+# MINIO_ACCESS_KEY: The access key for your MinIO server
+# Required only when BUCKET_TYPE is set to "MINIO"
+# SECURITY WARNING: Keep this value secret and never commit it to version control
MINIO_ACCESS_KEY="your_minio_access_key"
+# MINIO_SECRET_KEY: The secret key for your MinIO server
+# Required only when BUCKET_TYPE is set to "MINIO"
+# SECURITY WARNING: Keep this value secret and never commit it to version control
MINIO_SECRET_KEY="your_minio_secret_key"
backend/src/files/files.service.ts (1)

Line range hint 59-64: Consider Compatibility of StorageClass Parameter with MinIO

The StorageClass: "INTELLIGENT_TIERING" is specified in the PutObjectCommand. MinIO may not support AWS-specific storage classes like "INTELLIGENT_TIERING", which could lead to errors when uploading files to MinIO. Consider conditionally setting the StorageClass parameter only when using AWS S3.

You can modify the code to conditionally include the StorageClass:

const command = new PutObjectCommand({
  Bucket: this.configService.get("BUCKET_NAME"),
  Key: fileKey,
  ContentType: contentType,
  ContentLength: contentLength,
+ ...(this.configService.get("BUCKET_TYPE") !== "MINIO" && { StorageClass: "INTELLIGENT_TIERING" }),
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c0fc551 and 662d796.

📒 Files selected for processing (4)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/files/files.service.ts (6 hunks)
  • backend/src/utils/types/storage.type.ts (1 hunks)
🔇 Additional comments (3)
backend/src/utils/types/storage.type.ts (1)

1-1: Verify usage of StorageType across the codebase

To ensure proper integration of the new StorageType, please verify its usage across the codebase:

  1. Update existing uses of "S3" or "MINIO" string literals to use this type where appropriate.
  2. Ensure that configuration files and environment variables related to storage type are typed using StorageType.
  3. Incorporate StorageType in storage-related functions, classes, and interfaces.

Run the following script to identify potential places where StorageType should be used:

Please review the script output and update the code to use StorageType where appropriate.

backend/src/files/files.service.ts (2)

59-59: Verify Consistency of BUCKET_NAME Configuration Key

The bucket name is now retrieved using this.configService.get("BUCKET_NAME") in both createUploadPresignedUrl and createDownloadPresignedUrl. Ensure that all environment variables and deployment configurations have been updated from AWS_S3_BUCKET_NAME to BUCKET_NAME to prevent any runtime errors due to misconfiguration.

Also applies to: 74-74


29-29: Verify S3 Client Configuration for AWS S3

When using AWS S3 as the storage backend, the getStorageConfig method returns only the region. Ensure that AWS credentials are properly provided through the AWS SDK's default credential provider chain (environment variables, shared credentials file, etc.). If not, you may need to specify the credentials explicitly to prevent authentication issues.

backend/.env.development Outdated Show resolved Hide resolved
@devleejb devleejb self-requested a review October 4, 2024 09:36
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Also, we have to modify backend/docker/docker-compose.yml.

backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/src/files/files.service.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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 (8)
backend/src/files/files.module.ts (1)

2-3: Consider organizing imports for better readability.

While the functionality is correct, consider grouping related imports together for improved code organization. You might want to keep external imports (from @nestjs/common) separate from internal imports (from your project's modules).

Here's a suggested organization:

import { Module } from "@nestjs/common";

import { PrismaService } from "src/db/prisma.service";
import { StorageModule } from "src/storage/storage.module";
import { FilesController } from "./files.controller";
import { FilesService } from "./files.service";
backend/docker/docker-compose-full.yml (1)

69-87: LGTM: MinIO service well-configured, with a suggestion for credential handling

The addition of the MinIO service is well-configured and aligns with the PR objective. Good practices observed:

  • Using the official MinIO image
  • Exposing necessary ports
  • Using a volume for persistent storage
  • Configuring a healthcheck

Suggestion for improvement:
Consider using environment variable substitution for the MinIO root user and password, similar to the suggestion for the backend service. This would enhance security by avoiding hardcoded placeholders. For example:

environment:
  MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
  MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}

This change would use the environment variables if set, or fall back to a default user (but not a default password) if not provided.

backend/src/files/files.service.ts (2)

25-25: LGTM: Improved dependency injection for storage client

The use of @Inject("STORAGE_CLIENT") for the S3Client is a significant improvement. It allows for more flexible configuration and easier testing, aligning well with the PR's objective of supporting both S3 and MinIO.

This change also addresses the previous review comment about separating object creation and injecting from the file module.

Consider using a custom type for the injected client instead of S3Client to make it clear that it could be either an S3 or MinIO client. For example:

interface StorageClient extends S3Client {}

constructor(
  @Inject("STORAGE_CLIENT") private storageClient: StorageClient,
  // ... other parameters
) {}

This would make the code more self-documenting regarding the possibility of different storage backends.


Line range hint 1-138: Summary: Successful implementation with minor suggestions for improvement

The changes to FilesService successfully introduce support for MinIO alongside S3, meeting the main objective of the PR. The use of dependency injection for the storage client and the standardization of bucket name retrieval are significant improvements that enhance flexibility and maintainability.

To further improve the implementation:

  1. Consider using a custom type for the injected storage client to better document the possibility of different backends.
  2. Add validation for the BUCKET_NAME configuration to prevent potential runtime errors.
  3. If not already done, ensure that the necessary changes to create and configure the "STORAGE_CLIENT" are implemented in the corresponding module file.

These minor enhancements will make the code more robust and self-documenting, fully addressing the concerns raised in previous reviews.

As a next step, consider creating a StorageService abstraction that encapsulates the differences between S3 and MinIO implementations. This would allow FilesService to work with a generic storage interface, further decoupling it from specific storage implementations.

backend/.env.development (3)

69-71: Improve comment format for consistency

The comment for BUCKET_NAME is informative but doesn't follow the format of other variable comments in this file. Consider updating it to match the established pattern:

-# Storage configuration for either AWS S3 or MinIO
-# This is the name of the S3 Bucket or MinIO Bucket
+# BUCKET_NAME: Name of the S3 Bucket or MinIO Bucket
+# This is used for storage configuration with either AWS S3 or MinIO

75-76: Improve comment for AWS_REGION

Update the comment for AWS_REGION to be more descriptive and consistent with other variable comments:

-# AWS Region, only required for AWS S3
-AWS_REGION="your_aws_region"
+# AWS_REGION: The AWS region where your S3 bucket is located
+# This is only required when using AWS S3 for storage
+# Example: us-west-2
+AWS_REGION=us-west-2

77-78: Improve comment and add default value for MINIO_ENDPOINT

Update the comment for MINIO_ENDPOINT to be more descriptive, consistent with other variable comments, and include a default value for local development:

-# MinIO endpoint, only required for MinIO
-MINIO_ENDPOINT="your_minio_endpoint"
+# MINIO_ENDPOINT: The endpoint URL for the MinIO server
+# This is only required when using MinIO for storage
+# For local development, use the default MinIO server address
+MINIO_ENDPOINT=http://localhost:9000
backend/src/storage/storage.module.ts (1)

16-32: Handle Credentials Securely and Consistently

Ensure that credentials are handled securely. Consider using AWS SDK's default credential provider chain if possible, which allows for more flexibility and can automatically pick up credentials from the environment or IAM roles.

You might refactor the credentials configuration as follows:

 const config: S3ClientConfig = {
     region,
-    credentials: {
-        accessKeyId,
-        secretAccessKey,
-    },
+    credentials: accessKeyId && secretAccessKey ? {
+        accessKeyId,
+        secretAccessKey,
+    } : undefined,
     ...(endpoint && {
         endpoint,
         forcePathStyle: true,
     }),
 };

This change ensures that if accessKeyId and secretAccessKey are not provided, the SDK defaults are used.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 662d796 and 6ccd8d8.

📒 Files selected for processing (6)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/app.module.ts (2 hunks)
  • backend/src/files/files.module.ts (1 hunks)
  • backend/src/files/files.service.ts (4 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (11)
backend/src/files/files.module.ts (1)

2-3: LGTM! Changes align well with PR objectives.

The addition of StorageModule to the imports array and the corresponding import statement effectively integrate the new storage capabilities into the FilesModule. This change aligns perfectly with the PR objective of introducing MinIO as an alternative file storage solution to Amazon S3.

Also applies to: 8-8

backend/src/app.module.ts (2)

4-17: LGTM: Import statements reorganized and StorageModule added.

The import statements have been reorganized, which improves code readability. The addition of the StorageModule import is consistent with the PR objectives to support MinIO for file storage.


38-38: LGTM: StorageModule added to imports array.

The StorageModule has been correctly added to the imports array in the AppModule declaration. This addition is consistent with the PR objectives to support MinIO for file storage.

backend/docker/docker-compose-full.yml (4)

35-35: LGTM: Correct dependency added

Adding minio to the depends_on list ensures that the MinIO service is started before the backend service. This is a necessary and correct change for integrating MinIO as a storage option.


40-40: LGTM: Correct link added

Adding minio to the links list allows the backend service to communicate with the MinIO service using the service name as a hostname. This change is correct and complements the addition of MinIO to the depends_on list.


88-89: LGTM: Correct volume added for MinIO data persistence

The addition of the minio_data volume is correct and necessary for ensuring persistent storage of MinIO data. This volume corresponds to the mount point specified in the MinIO service configuration, which is a good practice for maintaining data across container restarts or updates.


Line range hint 1-89: Overall: Well-implemented MinIO integration with minor suggestions for improvement

The changes to docker-compose-full.yml successfully integrate MinIO as an alternative storage solution, aligning well with the PR objectives. The implementation is comprehensive, covering necessary configurations for both the backend and MinIO services.

Key strengths:

  1. Proper service dependencies and links
  2. Well-configured MinIO service with persistent storage
  3. Addition of required environment variables

Suggestions for improvement:

  1. Use environment variable substitution with default values where appropriate
  2. Enhance security by avoiding hardcoded placeholder values for sensitive information

These changes have significantly improved the flexibility of the storage options in the project, allowing users to choose between S3 and MinIO based on their needs.

backend/src/files/files.service.ts (1)

5-5: LGTM: Import addition for dependency injection

The addition of Inject from @nestjs/common is appropriate for the new dependency injection pattern used in the constructor. This change supports the PR's objective of flexible storage options.

backend/src/storage/storage.module.ts (3)

1-3: Imports are Correct and Necessary

The imported modules are appropriate and necessary for the functionality of the StorageModule.


39-43: Module Setup Is Correct

The StorageModule correctly provides and exports the s3ClientFactory, making the S3 client available for injection elsewhere in the application.


11-14: Verify All Required Configuration Values Are Provided

Ensure that the following configuration values are defined:

  • AWS_REGION
  • MINIO_ENDPOINT (if using MinIO)
  • STORAGE_ACCESS_KEY
  • STORAGE_SECRET_KEY

Missing configuration values could lead to runtime errors when initializing the S3 client.

Run the following script to check for undefined configuration values:

This script searches the configuration directory for the required keys and reports any that are missing.

✅ Verification successful

All Required Configuration Values Are Defined

The necessary configuration values are properly set in the following files:

  • backend/src/storage/storage.module.ts
  • backend/docker/docker-compose-full.yml
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for undefined configuration values in the codebase.

# Expected: All configuration keys should be set somewhere in the configuration files.

config_keys=(
    "AWS_REGION"
    "MINIO_ENDPOINT"
    "STORAGE_ACCESS_KEY"
    "STORAGE_SECRET_KEY"
)

for key in "${config_keys[@]}"
do
    grep -r "$key" ./backend/src/config
    if [ $? -ne 0 ]; then
        echo "Configuration key $key is not defined."
    fi
done

Length of output: 1131


Script:

#!/bin/bash
# Description: Search for configuration keys across the entire codebase.

config_keys=(
    "AWS_REGION"
    "MINIO_ENDPOINT"
    "STORAGE_ACCESS_KEY"
    "STORAGE_SECRET_KEY"
)

for key in "${config_keys[@]}"
do
    echo "Searching for $key..."
    rg "$key" --ignore-dir=node_modules --ignore-dir=dist
done

Length of output: 2551


Script:

#!/bin/bash
# Description: Search for configuration keys across the entire codebase, excluding node_modules and dist directories.

config_keys=(
    "AWS_REGION"
    "MINIO_ENDPOINT"
    "STORAGE_ACCESS_KEY"
    "STORAGE_SECRET_KEY"
)

for key in "${config_keys[@]}"
do
    echo "Searching for $key..."
    rg "$key" --glob '!node_modules/' --glob '!dist/'
done

Length of output: 1872

backend/src/app.module.ts Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6ccd8d8 and 5627a97.

📒 Files selected for processing (1)
  • backend/src/storage/storage.module.ts (1 hunks)
🧰 Additional context used

backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
@minai621 minai621 requested a review from devleejb October 12, 2024 02:36
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Also, we should discuss about the default environment value.
Please refer #365 (comment).

backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
const accessKeyId = configService.get<string>("STORAGE_ACCESS_KEY");
const secretAccessKey = configService.get<string>("STORAGE_SECRET_KEY");

const config: S3ClientConfig = endpoint
Copy link
Member

Choose a reason for hiding this comment

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

We should check with the value of FILE_UPLOAD.

Copy link
Contributor Author

@minai621 minai621 left a comment

Choose a reason for hiding this comment

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

@devleejb

I didn't quite understand the discussion around setting a default value. If no data is provided, the property becomes undefined, and the s3Client still initializes without issues. If we must set a default value, what would you prefer? Currently, the default values are something like
STORAGE_ACCESS_KEY: "your_storage_access_key_here"
STORAGE_SECRET_KEY: "your_storage_secret_key_here",
meaning the fields are initialized with placeholder strings, not left undefined.

backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (2)
backend/docker/docker-compose-full.yml (2)

71-92: Well-configured MinIO service with a security improvement suggestion

The MinIO service configuration is comprehensive and well-structured. Positive aspects include:

  • Use of official MinIO image
  • Persistent storage with a named volume
  • Exposed necessary ports
  • Initialization script to create the default bucket
  • Healthcheck for monitoring

However, there's room for improvement in credential management:

environment:
  MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
  MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}

This change allows setting credentials via environment variables, enhancing security by avoiding hardcoded values in the configuration file.


70-70: Clarify the comment about S3 and MinIO usage

The current comment might lead to confusion as the PR objective is to support both S3 and MinIO. Consider updating it to:

# The following MinIO service is provided for local development and testing.
# For production environments using S3, you may want to remove or comment out this service.

This clarification maintains flexibility while aligning better with the PR's goal of supporting both storage options.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0825028 and 322201c.

📒 Files selected for processing (2)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/storage/storage.module.ts
🧰 Additional context used
🔇 Additional comments (3)
backend/docker/docker-compose-full.yml (3)

35-35: Appropriate service dependencies added

The addition of MinIO to both the depends_on and links sections is correct and necessary. This ensures that the codepair-backend service will wait for the MinIO service to be ready before starting, which is crucial for proper initialization and connectivity.

Also applies to: 40-40


94-95: Correct volume declaration for MinIO

The addition of the minio_data volume is correct and necessary. This ensures that MinIO data persists across container restarts, which is crucial for maintaining uploaded files and MinIO's state.


Line range hint 1-95: Summary of Docker Compose configuration changes

The changes to docker-compose-full.yml successfully introduce MinIO as an alternative file storage solution, aligning well with the PR objectives. Key points:

  1. Environment variables have been updated to support both S3 and MinIO configurations.
  2. A new MinIO service has been added with appropriate configuration.
  3. Necessary dependencies and links have been established between the backend and MinIO services.
  4. Persistent storage for MinIO has been correctly set up.

Suggestions for improvement:

  1. Enhance environment variable management using variable substitution and default values.
  2. Improve security by avoiding hardcoded credentials.
  3. Clarify the comment about S3 and MinIO usage to better reflect the PR's goals.

Overall, these changes provide a solid foundation for flexible file storage options in the CodePair project.

backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

It seems that we should apply MinIO default value to .env.development and docker-compose.yml.

@minai621 minai621 requested a review from devleejb October 16, 2024 17:19
Copy link
Contributor

@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 (3)
backend/.env.development (3)

69-71: LGTM with a minor suggestion

The introduction of the BUCKET_NAME variable supports both S3 and MinIO, aligning with the PR objective. The default value is reasonable for development.

Consider updating the comment to be more specific:

-# Storage configuration for either AWS S3 or MinIO
+# Storage configuration for either AWS S3 or MinIO (set by MINIO_ENDPOINT)

This change would provide clearer guidance on how the storage type is determined.


72-76: Approve with suggestions for improved clarity and security

The addition of MinIO configuration variables aligns with the PR objective. However, consider the following improvements:

  1. Add individual comments for each variable to improve clarity:
 # MinIO endpoint, only required for MinIO
 MINIO_ENDPOINT="http://localhost:9000"
 # Common access keys for both S3 and MinIO
+# MINIO_ACCESS_KEY: Access key for authentication with MinIO or S3
 MINIO_ACCESS_KEY="minioadmin"
+# MINIO_SECRET_KEY: Secret key for authentication with MinIO or S3
+# Warning: Keep this value secret and never commit actual keys to version control
 MINIO_SECRET_KEY="minioadmin"
  1. Add a security warning about not using these default values in production:
# Note: These are default values for local development. 
# Use strong, unique values in production and never commit actual keys.
  1. Consider using placeholder values instead of actual default credentials:
-MINIO_ACCESS_KEY="minioadmin"
-MINIO_SECRET_KEY="minioadmin"
+MINIO_ACCESS_KEY="your_minio_access_key"
+MINIO_SECRET_KEY="your_minio_secret_key"

These changes will enhance security awareness and provide clearer guidance for users.


77-78: LGTM with a suggestion for improved clarity

The addition of the AWS_REGION variable supports the flexibility to use either S3 or MinIO, which aligns with the PR objectives. The comment and placeholder value are appropriate.

To improve clarity on how the system selects between S3 and MinIO, consider adding a comment at the beginning of the storage configuration section:

# Storage Configuration
# The system uses MinIO if MINIO_ENDPOINT is set, otherwise it defaults to AWS S3.
# Configure the appropriate variables based on your chosen storage type.

This addition would provide users with a clear understanding of how to configure their desired storage solution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 322201c and 0d22ee0.

📒 Files selected for processing (1)
  • backend/.env.development (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
backend/.env.development (2)

67-68: LGTM: File upload enabled

The change to enable file uploads aligns with the PR objective of supporting MinIO for file storage. The comment is clear and informative.


67-78: Overall assessment: Changes successfully introduce MinIO support

The modifications to the .env.development file successfully introduce support for MinIO as an alternative file storage solution, meeting the PR objectives. The changes provide flexibility for users to choose between S3 and MinIO, which is particularly beneficial for local development and testing scenarios.

Key points:

  1. File upload is now enabled by default, supporting the new storage functionality.
  2. The BUCKET_NAME variable is generic, supporting both S3 and MinIO configurations.
  3. MinIO-specific variables have been added with appropriate default values for local development.
  4. AWS S3 configuration is maintained, allowing users to choose their preferred storage solution.

To further improve the configuration:

  1. Consider adding a clear explanation of how the system chooses between S3 and MinIO at the beginning of the storage configuration section.
  2. Enhance security awareness by adding warnings about using strong, unique values in production environments.
  3. Improve clarity by adding individual comments for each new variable.

These changes align well with the project's goal of providing a more cost-effective and adaptable storage option, especially for users who may not want to rely solely on S3.

Copy link
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (2)
backend/docker/docker-compose-full.yml (1)

81-82: Clarify the conditional removal comment.

The current comment is ambiguous. It should clearly explain when users should remove the MinIO service.

-    # You can remove the following content if you're using S3 or not using Minio.
+    # MinIO Service Configuration
+    # Note: Remove this service if you're using Amazon S3 in production.
+    # Keep it for local development or if you're using MinIO as your primary storage.
backend/.env.development (1)

83-84: Improve AWS Region configuration documentation

The AWS Region configuration needs better documentation and example values.

Apply this diff to improve the configuration:

-# AWS Region, only required for AWS S3
+# AWS_REGION: The AWS region where your S3 bucket is located
+# This is only required when using AWS S3 for storage
+# Example: us-west-2, eu-west-1
 AWS_REGION="your_aws_region"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0d22ee0 and d38b9d2.

📒 Files selected for processing (4)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/files/files.service.ts (4 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/src/files/files.service.ts
  • backend/src/storage/storage.module.ts
🔇 Additional comments (2)
backend/docker/docker-compose-full.yml (2)

40-40: LGTM: Service dependencies are properly configured.

The addition of MinIO to both depends_on and links ensures proper service orchestration and network connectivity.

Also applies to: 45-45


105-106: LGTM: Volume configuration is correct.

The MinIO volume declaration ensures data persistence across container restarts.

backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Show resolved Hide resolved
backend/src/storage/storage.module.ts Outdated Show resolved Hide resolved
@minai621 minai621 requested a review from devleejb November 11, 2024 03:57
Copy link
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (2)
backend/docker/docker-compose-full.yml (1)

105-106: LGTM: Volume configuration is properly set up

The MinIO data volume is correctly declared and referenced. Consider adding volume configuration options for better management:

 volumes:
-    minio_data:
+    minio_data:
+        name: codepair_minio_data
+        driver: local
backend/.env.development (1)

91-93: Improve AWS region configuration

The AWS region configuration needs:

  1. A valid default region for development
  2. Consistent comment format

Apply this diff:

-# AWS Region, only required for AWS S3  
-# Example: us-east-1 (for development only)
-AWS_REGION="your_aws_region_here"
+# AWS_REGION: AWS region for S3 storage
+# Format: <region-name>
+# Example: us-east-1 (For development mode)
+# Only required when STORAGE_TYPE is set to 's3'
+AWS_REGION="us-east-1"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d38b9d2 and 99e5bcc.

📒 Files selected for processing (4)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/settings/settings.service.ts (1 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/storage/storage.module.ts
🔇 Additional comments (3)
backend/docker/docker-compose-full.yml (2)

40-40: LGTM: Service dependencies are properly configured

The MinIO service dependencies are correctly set up in both the depends_on and links sections.

Also applies to: 45-45


81-103: ⚠️ Potential issue

Enhance MinIO service security and reliability

Several improvements can be made to the MinIO service configuration:

  1. Root credentials should use environment variables
  2. Sleep duration in the entrypoint script might be too short
  3. Health check interval could be reduced for faster failure detection

Apply this diff to improve the configuration:

     minio:
         image: minio/minio
         ports:
             - "9000:9000"
             - "9001:9001"
         volumes:
             - minio_data:/data
         environment:
-            MINIO_ROOT_USER: "minioadmin"
-            MINIO_ROOT_PASSWORD: "minioadmin"
+            MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
+            MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
         entrypoint: /bin/sh -c "
             /usr/bin/docker-entrypoint.sh server --console-address ':9001' --address ':9000' /data &
-            sleep 1 &&
+            sleep 3 &&
             mc alias set myminio http://localhost:9000 minioadmin minioadmin &&
             if ! mc ls myminio/default-storage; then mc mb myminio/default-storage; fi &&
             wait"
         command: server --console-address ":9001" --address ":9000" /data
         healthcheck:
             test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
-            interval: 30s
+            interval: 10s
             timeout: 20s
             retries: 3

Additionally, consider:

  1. Adding restart: unless-stopped to ensure service resilience
  2. Using named volumes for better data persistence management

Likely invalid or redundant comment.

backend/.env.development (1)

78-81: LGTM!

The MinIO endpoint configuration is correct and follows the established comment format. The hostname "minio" aligns with the docker-compose service name.

backend/src/settings/settings.service.ts Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

It seems this should be checked before the review:

  • Does it maintain a consistent format for comments (e.g., .env.development)?
  • Does it provide an appropriate comment for the environment? Is it up to date? (e.g., .env.development)
  • Does it use consistent environment names across .env.development, docker-compose.yml, and docker-compose-full.yml?
  • Please check CodeRabbit’s comment. If you find the recommendation necessary, make sure to apply it.
  • The file upload feature should work with the following execution options:
    • docker-compose.yml + pnpm frontend dev + pnpm backend start:dev
    • docker-compose-full.yml + pnpm frontend dev

I think it might also be a good idea to work together on Zoom. If you’d like to do that, feel free to let me know.

backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
backend/.env.development Outdated Show resolved Hide resolved
Copy link
Contributor

@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 (5)
backend/docker/docker-compose-full.yml (2)

105-106: Consider explicit volume configuration

While the volume configuration works, consider making it more explicit for better maintainability.

 volumes:
-    minio_data:
+    minio_data:
+        driver: local
+        driver_opts:
+            type: none
+            device: ${MINIO_DATA_PATH:-./data/minio}
+            o: bind

Line range hint 1-106: Architectural Review: MinIO Integration

The implementation successfully achieves the PR objectives by:

  1. Adding MinIO as an alternative storage solution
  2. Maintaining compatibility with S3
  3. Providing configuration flexibility

However, please ensure that:

  1. Production deployments use secure credentials
  2. Documentation is updated with MinIO configuration instructions
  3. Backup and disaster recovery procedures are documented

Consider adding a comment block at the top of the file explaining:

  • The storage configuration options (S3 vs MinIO)
  • Required environment variables for each option
  • Security considerations for production deployments
backend/.env.development (3)

87-89: Update default bucket name for development

While previous feedback about adding STORAGE_TYPE remains valid, the default bucket name "default-storage" should be changed to something more descriptive for the development environment, such as "codepair-dev".

-BUCKET_NAME="default-storage"
+BUCKET_NAME="codepair-dev"

90-93: Clarify Docker Compose requirement in endpoint comment

The endpoint uses "minio" as the hostname, which assumes Docker Compose usage. This should be clearly documented.

 # MINIO_ENDPOINT: The endpoint URL for the MinIO server
 # Format: http(s)://<host>:<port>
-# Example: http://localhost:9000 (For development mode)
+# Example: http://minio:9000 (When using Docker Compose)
+# Example: http://localhost:9000 (When running MinIO locally)
 MINIO_ENDPOINT="http://minio:9000"

94-102: Enhance security of credential documentation

While the default MinIO credentials are well-known, documenting them in comments could be a security risk. Consider using placeholder values in comments.

 # Warning: Use a strong, unique value in production
-# Default: minioadmin (for development only)
+# Example: your_access_key_here
 MINIO_ACCESS_KEY="minioadmin"

 # Warning: Keep this value secret and never commit to version control
-# Default: minioadmin (for development only)
+# Example: your_secret_key_here
 MINIO_SECRET_KEY="minioadmin"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 99e5bcc and 7a54f6a.

📒 Files selected for processing (3)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/src/files/files.service.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/files/files.service.ts
🔇 Additional comments (3)
backend/docker/docker-compose-full.yml (2)

40-40: LGTM: Service dependencies are properly configured

The MinIO service dependencies and links are correctly set up, ensuring proper service orchestration.

Also applies to: 45-45


29-35: ⚠️ Potential issue

Enhance security and configuration flexibility

While the MinIO configuration is functional, there are several concerns that need to be addressed:

  1. Sensitive credentials are hardcoded
  2. AWS region uses a placeholder
  3. Configuration lacks flexibility for different environments

Apply this diff to improve security and maintainability:

-            FILE_UPLOAD: minio
-            AWS_REGION: "your_aws_region_here"
-            # Default configuration values for using Minio
-            BUCKET_NAME: "default-storage"
-            MINIO_ENDPOINT: "http://minio:9000"
-            STORAGE_ACCESS_KEY: "minioadmin"
-            STORAGE_SECRET_KEY: "minioadmin"
+            FILE_UPLOAD: ${FILE_UPLOAD:-minio}
+            AWS_REGION: ${AWS_REGION:-us-east-1}
+            # Storage configuration (supports both S3 and MinIO)
+            BUCKET_NAME: ${BUCKET_NAME:-default-storage}
+            MINIO_ENDPOINT: ${MINIO_ENDPOINT:-http://minio:9000}
+            # Warning: Do not use default credentials in production
+            STORAGE_ACCESS_KEY: ${STORAGE_ACCESS_KEY:-changeme}
+            STORAGE_SECRET_KEY: ${STORAGE_SECRET_KEY:-changeme}

Likely invalid or redundant comment.

backend/.env.development (1)

83-86: Previous feedback remains valid

A previous review has already addressed the issues with FILE_UPLOAD configuration.

backend/.env.development Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (4)
backend/src/utils/types/storage.type.ts (1)

1-1: Consider enhancing type safety and documentation.

While the current implementation is functional, consider these improvements:

  1. Add JSDoc documentation to explain the purpose and usage
  2. Consider using a const enum for better type safety and runtime optimization
+/**
+ * Defines the supported storage providers for file storage.
+ * - S3: Amazon S3 storage
+ * - MINIO: MinIO S3-compatible storage
+ */
-export type StorageType = "S3" | "MINIO";
+export const enum StorageType {
+  S3 = "S3",
+  MINIO = "MINIO"
+}
backend/docker/docker-compose-full.yml (2)

40-40: Modernize service dependencies configuration

The links directive is deprecated in Compose v3. Also, the dependency order could be optimized for faster startup.

Apply this diff to improve the configuration:

         depends_on:
+            minio:
+                condition: service_healthy
             mongo:
-            - minio
+                condition: service_healthy
         restart: unless-stopped
-        links:
-            - "mongo:mongo"
-            - "yorkie:yorkie"
-            - "minio:minio"

This change:

  • Removes the deprecated links directive
  • Uses healthcheck-based dependencies for more reliable service startup
  • Orders dependencies based on startup requirements

Also applies to: 45-45


105-106: Enhance volume configuration for better management

The volume configuration could be improved with explicit driver settings and labels.

Apply this diff to improve volume configuration:

 volumes:
-    minio_data:
+    minio_data:
+        driver: local
+        labels:
+            com.codepair.description: "MinIO data storage"
+            com.codepair.backup: "true"

Consider also adding a comment about backup strategies for the MinIO data volume in production environments.

frontend/src/hooks/useYorkieDocument.ts (1)

132-142: Consider optimizing dual cleanup mechanism

The implementation handles cleanup in two scenarios:

  1. Component unmount via useEffect
  2. Page unload via useBeforeUnload

While thorough, this could potentially trigger cleanup twice in some scenarios. Consider:

  1. Adding a cleanup status flag to prevent double cleanup
  2. Consolidating the cleanup logic if possible
 const cleanUpYorkieDocument = useCallback(async () => {
-  if (!client || !doc) return;
+  if (!client || !doc || client.isDeactivated()) return;

   try {
     await client.deactivate({ keepalive: true });
   } catch (error) {
     console.error("Error during Yorkie cleanup:", error);
   }
 }, [client, doc]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7a54f6a and afdac17.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • CHANGELOG.md (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/docker/docker-compose.yml (1 hunks)
  • backend/package.json (1 hunks)
  • backend/src/files/files.service.ts (5 hunks)
  • backend/src/utils/types/storage.type.ts (1 hunks)
  • frontend/package.json (3 hunks)
  • frontend/src/components/editor/Preview.tsx (4 hunks)
  • frontend/src/global.d.ts (1 hunks)
  • frontend/src/hooks/useYorkieDocument.ts (4 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • backend/docker/docker-compose.yml
  • backend/package.json
  • frontend/src/global.d.ts
  • package.json
🧰 Additional context used
🪛 Markdownlint (0.35.0)
CHANGELOG.md

14-14: null
Bare URL used

(MD034, no-bare-urls)


20-20: null
Bare URL used

(MD034, no-bare-urls)


24-24: null
Bare URL used

(MD034, no-bare-urls)


28-28: null
Bare URL used

(MD034, no-bare-urls)

🔇 Additional comments (9)
backend/src/utils/types/storage.type.ts (1)

1-1: LGTM! Clean and well-structured type definition.

The StorageType type alias effectively supports the storage flexibility objective by providing compile-time safety for storage configuration.

frontend/src/components/editor/Preview.tsx (2)

Line range hint 1-116: Overall changes look good and align with PR objectives

The changes effectively support the MinIO integration by improving image handling through lazy loading, which is particularly beneficial when dealing with different storage backends. The code maintains good quality and adds performance optimizations.


14-14: Consider adding type declarations for markdown-it-image-lazy-loading

The integration of image lazy loading is a good performance optimization. However, to maintain type safety, consider adding proper TypeScript declarations.

Let's verify the plugin configuration and type declarations:

Also applies to: 51-52

frontend/package.json (2)

58-58: Verify necessity of markdown-it-image-lazy-loading

The addition of markdown-it-image-lazy-loading appears unrelated to the PR's objective of adding MinIO support. Please clarify:

  1. Why this dependency is needed in this PR
  2. How it relates to the MinIO storage implementation
✅ Verification successful

The markdown-it-image-lazy-loading dependency is used for image optimization

The dependency is actively used in the Preview component for rendering markdown content with lazy-loaded images, which is a performance optimization feature. While this change appears in a PR focused on MinIO support, it's a valuable addition that improves the loading performance of images in markdown content, regardless of their storage location (including MinIO-stored images).

  • The dependency is properly imported and integrated into the markdown-it pipeline in frontend/src/components/editor/Preview.tsx
  • It's correctly declared in the type definitions at frontend/src/global.d.ts
  • This optimization will benefit all images rendered in markdown content, including those that will be served from MinIO
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the new dependency
rg -l "markdown-it-image-lazy-loading"

# Check if there are any image-related changes in Preview.tsx
rg -A 5 "markdown-it-image-lazy-loading" -- "*Preview.tsx"

Length of output: 255


Script:

#!/bin/bash
# Check the content of Preview.tsx to understand the usage
cat frontend/src/components/editor/Preview.tsx

# Check git diff to see related changes
git diff origin/main -- frontend/src/components/editor/Preview.tsx

# Check the type definitions
cat frontend/src/global.d.ts

Length of output: 3653


85-85: Verify yorkie-js-sdk compatibility

The update of yorkie-js-sdk from 0.5.5 to 0.5.6 should be verified for compatibility with the MinIO implementation.

✅ Verification successful

Yorkie-js-sdk update appears safe to proceed

Based on the codebase analysis:

  • Yorkie-js-sdk is used primarily for real-time collaboration features in the editor
  • There is no direct interaction between yorkie-js-sdk and MinIO/storage functionality
  • MinIO is configured separately in docker-compose for file uploads, completely independent of the yorkie implementation
  • The yorkie and storage systems operate independently with different responsibilities
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for yorkie-js-sdk version consistency across files
echo "Checking yorkie-js-sdk version in backend package.json..."
rg '"yorkie-js-sdk"' backend/package.json

echo "Checking yorkie-js-sdk version in docker-compose..."
rg 'yorkie-js-sdk' backend/docker/docker-compose.yml

Length of output: 334


Script:

#!/bin/bash
# Let's check how yorkie-js-sdk is used in the codebase and its interaction with MinIO
echo "Checking yorkie-js-sdk usage patterns..."
rg -l "yorkie" --type js --type ts

echo "Checking MinIO related imports/usage alongside yorkie..."
rg "import.*yorkie" -A 5 --type js --type ts

echo "Checking for MinIO configuration or setup..."
rg "minio" -i --type js --type ts --type json --type yml

Length of output: 7837


Script:

#!/bin/bash
# Let's check for MinIO configuration in yaml files specifically and check the changelog
echo "Checking MinIO configuration in yaml files..."
rg "minio" -i --type yaml

echo "Checking for recent changes in yorkie implementation..."
rg -B 2 -A 2 "yorkie" frontend/CHANGELOG.md

echo "Checking for any direct interaction between yorkie and file storage..."
rg -C 5 "storage|minio|s3" frontend/src/utils/yorkie/

Length of output: 2007

frontend/src/hooks/useYorkieDocument.ts (3)

5-5: LGTM: Clean import addition

The useBeforeUnload hook is appropriately imported and grouped with existing react-router-dom imports.


Line range hint 1-145: Clarify relationship to MinIO storage integration

These changes focus on Yorkie document cleanup behavior, but their relationship to the PR's main objective (MinIO storage integration) isn't clear. Please explain:

  1. Why are these cleanup changes necessary for MinIO integration?
  2. Are there specific storage-related issues these changes address?

Let's check for any connections:


83-83: Verify the implications of keepalive during cleanup

The addition of { keepalive: true } during client deactivation represents a significant behavioral change. This could affect how documents are synchronized and how resources are managed during cleanup.

Please clarify:

  1. Why is keepalive necessary?
  2. What are the implications for resource cleanup?
  3. Are there any potential memory leak concerns?

Let's check the codebase for any related changes or documentation:

Also applies to: 104-104

backend/src/files/files.service.ts (1)

1-1: LGTM: Good use of dependency injection pattern

The changes properly implement dependency injection for the S3Client, which improves testability and follows the suggestion from the previous review about separating object creation from the service layer.

Also applies to: 5-5, 17-17, 26-26

frontend/src/components/editor/Preview.tsx Outdated Show resolved Hide resolved
frontend/package.json Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/src/files/files.service.ts Show resolved Hide resolved
backend/src/files/files.service.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between afdac17 and c2bed96.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/docker/docker-compose.yml (2 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
  • backend/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • backend/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/.env.development
  • backend/src/storage/storage.module.ts
🔇 Additional comments (2)
backend/docker/docker-compose.yml (1)

5-5: Verify yorkie version upgrade compatibility

The yorkie version upgrade from 0.5.5 to 0.5.6 should be verified for compatibility with the current implementation.

✅ Verification successful

Version upgrade appears safe to proceed

The yorkie version upgrade from 0.5.5 to 0.5.6 appears to be a minor version update. The configuration remains consistent between docker-compose files, and there are no direct dependencies in the package.json files that would be affected. The service configuration (ports, command, restart policy) remains unchanged, suggesting this is a compatible update.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for breaking changes in yorkie version upgrade

# Check if there's a CHANGELOG.md in the repository
if [ -f CHANGELOG.md ]; then
    echo "Checking local CHANGELOG.md for yorkie version changes..."
    rg -A 5 "0\.5\.6" CHANGELOG.md
fi

# Fetch yorkie releases from GitHub
echo "Checking yorkie releases on GitHub..."
gh api repos/yorkie-team/yorkie/releases --jq '.[] | select(.tag_name=="0.5.6") | .body'

Length of output: 492


Script:

#!/bin/bash
# Let's try to find any direct dependencies or configurations related to yorkie in the codebase

# Search for yorkie-related configurations
echo "Searching for yorkie configurations..."
rg -l "yorkie" --type yaml --type json

# Search for direct yorkie imports or usage
echo "Searching for yorkie usage in code..."
rg -l "yorkie" --type go --type typescript --type javascript

# Check docker-compose history for previous yorkie versions
echo "Checking docker-compose history..."
git log -p -- backend/docker/docker-compose.yml | rg "yorkieteam/yorkie"

Length of output: 529


Script:

#!/bin/bash
# Let's check the package dependencies and their versions

echo "Checking yorkie dependency in package.json files..."
cat backend/package.json frontend/package.json | jq '.dependencies | select(.yorkie != null)'

echo "Checking yorkie configuration in docker-compose-full.yml..."
cat backend/docker/docker-compose-full.yml | grep -A 5 "yorkie"

echo "Checking current docker-compose.yml configuration..."
cat backend/docker/docker-compose.yml | grep -A 5 "yorkie"

Length of output: 1821

backend/docker/docker-compose-full.yml (1)

29-34: ⚠️ Potential issue

Fix MinIO configuration for container networking

While the previous review comment about using environment variables with defaults is still valid, there's an additional networking issue:

  • The MinIO endpoint URL uses localhost which won't work with Docker container networking.

Apply this change in addition to the environment variable improvements suggested in the previous review:

-            MINIO_ENDPOINT: "http://localhost:9000"
+            MINIO_ENDPOINT: "http://minio:9000"

backend/docker/docker-compose.yml Outdated Show resolved Hide resolved
backend/docker/docker-compose.yml Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/docker/docker-compose-full.yml Show resolved Hide resolved
backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
- Add MinIO support in FilesService
- Update docker-compose.yml to include MinIO service
- Implement environment variable switching between S3 and MinIO
- Add MinIO endpoint configuration
- Update documentation for MinIO setup and usage
- Add storage module to handle file upload functionality
- Configure S3Client for storage service
- Update files service to use injected S3Client
- Update files module to import storage module
Copy link
Contributor

@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: 6

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c2bed96 and e55349e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • backend/.env.development (1 hunks)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/docker/docker-compose.yml (1 hunks)
  • backend/src/app.module.ts (2 hunks)
  • backend/src/files/files.module.ts (1 hunks)
  • backend/src/files/files.service.ts (5 hunks)
  • backend/src/settings/settings.service.ts (1 hunks)
  • backend/src/storage/storage.module.ts (1 hunks)
  • backend/src/utils/types/storage.type.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • backend/docker/docker-compose.yml
  • backend/src/app.module.ts
  • backend/src/files/files.module.ts
  • backend/src/settings/settings.service.ts
  • backend/src/storage/storage.module.ts
  • backend/src/utils/types/storage.type.ts
🔇 Additional comments (7)
backend/docker/docker-compose-full.yml (2)

Line range hint 1-105: Verify storage configuration across environments

Let's ensure the storage configuration works correctly across different environments.

✅ Verification successful

Storage configuration is properly implemented and flexible

The verification shows that:

  • The storage module correctly handles both S3 and MinIO configurations through the FILE_UPLOAD environment variable
  • The implementation in storage.module.ts properly configures the S3 client for both S3 and MinIO use cases
  • The docker-compose configuration aligns with the implementation, providing all necessary environment variables
  • The storage client is properly integrated into the application through module imports
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify storage configuration across the codebase

# Check for environment-specific configurations
echo "Checking for environment-specific configurations..."
rg -l "FILE_UPLOAD|MINIO_|AWS_" --type yaml --type env

# Check for storage-related environment variables in deployment files
echo "Checking deployment configurations..."
rg -l "BUCKET_NAME|STORAGE_" --type yaml --type env

# Check for S3/MinIO client initialization
echo "Checking storage client initialization..."
rg -A 5 "new S3Client|new Minio" --type ts

Length of output: 805


Script:

#!/bin/bash
# Let's check for environment configuration files and storage-related code

# Check for environment and docker files
echo "Checking environment and docker files..."
fd -e yml -e yaml -e env

# Check storage module implementation
echo "Checking storage module implementation..."
cat backend/src/storage/storage.module.ts

# Check for storage configuration patterns
echo "Checking storage configuration patterns..."
rg -A 10 "storage.module" --type ts

# Check for MinIO/S3 related configuration
echo "Checking MinIO/S3 configuration..."
rg -A 5 "FILE_UPLOAD|StorageConfig" --type ts

Length of output: 4364


80-94: ⚠️ Potential issue

Add persistent storage for MinIO

The MinIO service is missing volume configuration, which will result in data loss when the container is removed or recreated.

Add the following configuration:

     minio:
         image: minio/minio
+        volumes:
+            - minio_data:/data
         ports:
             - "9000:9000"
             - "9001:9001"
         environment:
             MINIO_ROOT_USER: "minioadmin"
             MINIO_ROOT_PASSWORD: "minioadmin"
         command: server --console-address ":9001" --address ":9000" /data

+volumes:
+    minio_data:
+        driver: local

Likely invalid or redundant comment.

backend/src/files/files.service.ts (4)

1-1: LGTM: Clean import organization

The addition of StorageType import and organization of imports looks good.

Also applies to: 17-17


26-29: LGTM: Improved dependency injection

Good implementation of the suggested dependency injection pattern. This separates concerns and makes the service more testable.


59-59: Add bucket name validation

The bucket name is retrieved multiple times without validation. Consider implementing the previously suggested validation pattern:

Referring to previous suggestion about extracting bucket name retrieval into a validated private method.

Also applies to: 74-74


130-151: ⚠️ Potential issue

Improve storage configuration robustness

The storage configuration has several areas that need improvement:

  1. Missing validation for required MinIO configuration
  2. Region might not be needed for MinIO configuration
  3. Environment variable names should be consistent with storage.module.ts

Apply these changes:

 private getStorageConfig = (): S3ClientConfig => {
   const bucketType: StorageType = this.configService.get("BUCKET_TYPE") || "S3";
   const region = this.configService.get("AWS_REGION") || "us-east-1";
   if (bucketType === "MINIO") {
     const endpoint = this.configService.get("MINIO_ENDPOINT");
+    if (!endpoint) {
+      throw new Error("MINIO_ENDPOINT is required for MinIO configuration");
+    }
-    const accessKeyId = this.configService.get("MINIO_ACCESS_KEY");
+    const accessKeyId = this.configService.get("STORAGE_ACCESS_KEY");
     if (!accessKeyId) {
-      throw new Error("MINIO_ACCESS_KEY is required for MinIO configuration");
+      throw new Error("STORAGE_ACCESS_KEY is required for MinIO configuration");
     }
-    const secretAccessKey = this.configService.get("MINIO_SECRET_KEY");
+    const secretAccessKey = this.configService.get("STORAGE_SECRET_KEY");
     if (!secretAccessKey) {
-      throw new Error("MINIO_SECRET_KEY is required for MinIO configuration");
+      throw new Error("STORAGE_SECRET_KEY is required for MinIO configuration");
     }
     return {
-      region,
       endpoint,
       forcePathStyle: true,
       credentials: {
         accessKeyId,
         secretAccessKey,
       },
     };
   }
   return {
     region,
   };
 };

Let's verify the environment variable usage across the codebase:

backend/.env.development (1)

87-89: 🛠️ Refactor suggestion

Verify bucket name usage and update comment format

The configuration needs to follow the established format and the bucket name should be verified against the codebase.

Apply this diff:

-# BUCKET_NAME: The name of the S3 or MinIO bucket to use.  
-# Required only if FILE_UPLOAD is set to "s3" or "minio".  
+# BUCKET_NAME: Storage bucket name for file uploads
+# Format: <bucket-name>
+# Example: codepair-files (For development mode)
 BUCKET_NAME="default-storage"
✅ Verification successful

Let me try another search strategy to verify the bucket name usage.


Let me check the storage module implementation to understand how the bucket is used.


Comment format should be updated to match the codebase standard

The bucket name "default-storage" is correctly used in the codebase:

  • It's referenced in docker compose files for MinIO setup
  • It's used in FilesService for S3/MinIO operations through the ConfigService
  • The value is appropriate for development environment

The only issue is the comment format which should be updated to match other environment variables.

Apply this diff:

-# BUCKET_NAME: The name of the S3 or MinIO bucket to use.  
-# Required only if FILE_UPLOAD is set to "s3" or "minio".  
+# BUCKET_NAME: Storage bucket name for S3/MinIO file uploads
+# Required: Only if FILE_UPLOAD is set to "s3" or "minio"
+# Example: default-storage
 BUCKET_NAME="default-storage"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify bucket name usage in the codebase

# Test: Search for bucket name references
echo "Checking bucket name usage:"
rg "BUCKET_NAME|getBucketName" --type typescript

# Test: Check for bucket creation/usage in storage module
ast-grep --pattern 'createBucket($$$)'

Length of output: 191


Script:

#!/bin/bash
# Search for bucket name references in all files
echo "Checking bucket name usage in all files:"
rg "BUCKET_NAME|getBucketName|default-storage"

# Search for storage-related files
echo -e "\nFinding storage-related files:"
fd -t f storage

Length of output: 726


Script:

#!/bin/bash
# Check storage module implementation
echo "Storage module implementation:"
cat backend/src/storage/storage.module.ts

# Check storage type definition
echo -e "\nStorage type definition:"
cat backend/src/utils/types/storage.type.ts

# Check files service implementation
echo -e "\nFiles service implementation:"
cat backend/src/files/files.service.ts

Length of output: 5773

backend/docker/docker-compose-full.yml Show resolved Hide resolved
backend/docker/docker-compose-full.yml Show resolved Hide resolved
backend/.env.development Show resolved Hide resolved
backend/.env.development Show resolved Hide resolved
backend/.env.development Show resolved Hide resolved
backend/.env.development Show resolved Hide resolved
@devleejb devleejb self-requested a review November 26, 2024 07:50
Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (1)
backend/docker/docker-compose-full.yml (1)

76-76: Improve service documentation

The comment "You can remove the following content if you're using S3 or not using Minio" could be clearer. Consider:

-    # You can remove the following content if you're using S3 or not using Minio.
+    # MinIO service configuration
+    # Note: This service is only required when FILE_UPLOAD=minio
+    # If you're using S3 (FILE_UPLOAD=s3), you can remove this service.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e55349e and b15117f.

📒 Files selected for processing (2)
  • backend/docker/docker-compose-full.yml (2 hunks)
  • backend/docker/docker-compose.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/docker/docker-compose.yml
🔇 Additional comments (4)
backend/docker/docker-compose-full.yml (4)

29-34: Previous review comment is still applicable

The environment variables configuration needs the same improvements as mentioned in the previous review comment regarding security and reliability.


39-39: Previous review comment is still applicable

The depends_on configuration should be enhanced as suggested in the previous review comment.


92-102: Previous review comment is still applicable

The initialization service needs the same improvements as mentioned in the previous review comment regarding reliability and security.


Line range hint 29-102: Verify storage configuration completeness

Let's verify that all necessary configuration options are present for both S3 and MinIO storage options.

✅ Verification successful

Storage configuration is complete and properly implemented

The verification confirms that all necessary storage configuration options are present and properly integrated:

  • The backend service correctly handles both S3 and MinIO storage options through the FILE_UPLOAD environment variable
  • All required environment variables are properly referenced in the codebase:
    • Core storage variables: FILE_UPLOAD, BUCKET_NAME
    • AWS-specific: AWS_REGION
    • MinIO-specific: MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY
  • The docker-compose configuration aligns with the implementation in the codebase
  • Storage configuration is properly modularized in storage.module.ts and utilized in files.service.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify storage configuration completeness

# Check for required environment variables in backend service
echo "Checking backend service environment variables..."
rg -A 1 'FILE_UPLOAD|AWS_|MINIO_|BUCKET' backend/src/

# Check for storage-related configuration in other files
echo "Checking for related configuration in other files..."
fd -e yml -e yaml -e env | xargs rg 'FILE_UPLOAD|AWS_|MINIO_|BUCKET'

Length of output: 2891

backend/docker/docker-compose-full.yml Show resolved Hide resolved
Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@devleejb devleejb merged commit b618422 into main Nov 26, 2024
2 checks passed
@devleejb devleejb deleted the support-minio branch November 26, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Support MinIO as an default storage option for image repository
2 participants