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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Support MinIO for file storage #365

wants to merge 10 commits into from

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 (Replace with actual issue number if applicable)

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

  • New Features

    • Introduced support for MinIO storage alongside AWS S3, enhancing flexibility in file storage options.
    • Added a new minio service in the backend configuration for improved object storage management.
  • Bug Fixes

    • Updated environment variable configurations to ensure proper integration of storage options.
  • Documentation

    • Clarified comments regarding file upload settings and the necessity of AWS S3 bucket name.
  • Refactor

    • Updated methods for generating presigned URLs to utilize new storage configuration parameters.
    • Streamlined dependency management for the S3 client.
    • Added a new StorageModule to manage S3 client configuration.
    • Reorganized module imports for better structure and clarity.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes introduce a comprehensive update to the backend configuration, specifically enhancing file storage capabilities by integrating support for MinIO alongside AWS S3. Key modifications include the addition of new environment variables for MinIO configuration in the .env.development and docker-compose-full.yml files, as well as adjustments to the FilesService to accommodate these storage options. A new StorageModule has been created to manage the S3 client configuration, ensuring standardized usage across the codebase.

Changes

File Change Summary
backend/.env.development Updated file upload settings; replaced AWS_S3_BUCKET_NAME with BUCKET_NAME; added MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY, and AWS_REGION.
backend/docker/docker-compose-full.yml Updated codepair-backend service to use BUCKET_NAME; added minio service with relevant configurations.
backend/src/app.module.ts Reordered imports and added StorageModule to the imports array.
backend/src/files/files.module.ts Added StorageModule to the imports array in FilesModule.
backend/src/files/files.service.ts Modified FilesService to use BUCKET_NAME for presigned URL methods; injected S3Client via constructor.
backend/src/storage/storage.module.ts Introduced StorageModule to manage S3 client configuration and provide it as a service.

Assessment against linked issues

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

Poem

🐇 In the land of code where changes bloom,
MinIO joins S3, making space in the room.
Buckets now dance with names so bright,
Configurations shift, bringing new light.
A rabbit's delight in storage so grand,
Flexibility hops across the land! 🌟


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.

- 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
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
backend/src/files/files.service.ts 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.

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
Comment on lines 74 to 77
MINIO_ENDPOINT="your_minio_endpoint"
MINIO_ACCESS_KEY="your_minio_access_key"
MINIO_SECRET_KEY="your_minio_secret_key"
Copy link
Member

Choose a reason for hiding this comment

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

Please add comments for these variables.
The format of the comments should be consistent with the others.

Copy link
Member

Choose a reason for hiding this comment

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

Also, we have to set default value.
Note that users should be able to run CodePair with minimal configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devleejb
Regarding the default values, I think not having them won't cause any issues. As noted in the implementation, if the MINIO_ENDPOINT environment variable is not provided, the MinIO client won't be initialized or used. This ensures that MinIO is only executed when all required variables are properly configured.

For reference, please check the storage.module.ts file, where the MinIO client is only created when the necessary endpoint is provided.

Copy link
Member

Choose a reason for hiding this comment

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

I understand. However, I want the default upload options to be configured for MinIO. Also, I want the CodePair project to run only with the following commands:

docker-compose -f ./backend/docker/docker-compose-full.yml up -d
pnpm i
pnpm frontend dev 

Therefore, we should set default values (This is just for the local environment. For production, we will provide other guidelines).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devleejb
sorry, I don't check this comment.
Minio buckets need to be created manually either via the web interface after the server starts or through a shell script.
In that case, how should the initial value for the bucket name be set?

Copy link
Member

Choose a reason for hiding this comment

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

Then, can we create bucket using entrypoint in docker-compose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devleejb
I checked that it's possible through the entry point, so I updated the implementation in this pull request.

backend/docker/docker-compose-full.yml Outdated Show resolved Hide resolved
backend/src/files/files.service.ts Outdated Show resolved Hide resolved
- 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: 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/src/files/files.service.ts 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
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).

if (configService.get<boolean>("FILE_UPLOAD") === false) {
return null;
}
const region = configService.get<string>("AWS_REGION") || "us-east-1";
Copy link
Member

Choose a reason for hiding this comment

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

Why the default region is us-east-1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chose us-east-1 as the default region because it's AWS's first and one of the most commonly used regions. The goal is to provide a stable, well-known fallback for cases where the user doesn't specify a region.

Copy link
Member

Choose a reason for hiding this comment

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

I believe it should be empty so the S3 client can throw an error. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also agree that users may not be able to check if they are set up with us-east-1.

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.

if (configService.get<boolean>("FILE_UPLOAD") === false) {
return null;
}
const region = configService.get<string>("AWS_REGION") || "us-east-1";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

chose us-east-1 as the default region because it's AWS's first and one of the most commonly used regions. The goal is to provide a stable, well-known fallback for cases where the user doesn't specify a region.

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.

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.

Comment on lines +30 to +35
AWS_REGION: "your_aws_region_here"
# Default configuration values for using Minio
BUCKET_NAME: "default-storage"
MINIO_ENDPOINT: "http://localhost:9000"
STORAGE_ACCESS_KEY: "minioadmin"
STORAGE_SECRET_KEY: "minioadmin"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance security and usability of storage configuration.

The current configuration has several issues:

  1. Sensitive credentials are hardcoded in plain text
  2. Some values use placeholder text instead of defaults
  3. No environment variable substitution is used

Apply this diff to improve the configuration:

-            AWS_REGION: "your_aws_region_here"
-            # Default configuration values for using Minio
-            BUCKET_NAME: "default-storage"
-            MINIO_ENDPOINT: "http://localhost:9000"
-            STORAGE_ACCESS_KEY: "minioadmin"
-            STORAGE_SECRET_KEY: "minioadmin"
+            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}
+            STORAGE_ACCESS_KEY: ${STORAGE_ACCESS_KEY}
+            STORAGE_SECRET_KEY: ${STORAGE_SECRET_KEY}
📝 Committable suggestion

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

Suggested change
AWS_REGION: "your_aws_region_here"
# Default configuration values for using Minio
BUCKET_NAME: "default-storage"
MINIO_ENDPOINT: "http://localhost:9000"
STORAGE_ACCESS_KEY: "minioadmin"
STORAGE_SECRET_KEY: "minioadmin"
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}
STORAGE_ACCESS_KEY: ${STORAGE_ACCESS_KEY}
STORAGE_SECRET_KEY: ${STORAGE_SECRET_KEY}

Comment on lines +83 to +103
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
volumes:
- minio_data:/data
environment:
MINIO_ROOT_USER: "minioadmin"
MINIO_ROOT_PASSWORD: "minioadmin"
entrypoint: /bin/sh -c "
/usr/bin/docker-entrypoint.sh server --console-address ':9001' --address ':9000' /data &
sleep 1 &&
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
timeout: 20s
retries: 3
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance MinIO service security and configuration.

Several improvements can be made to the MinIO service configuration:

  1. Use environment variables for credentials
  2. Simplify the entrypoint script
  3. Optimize health check frequency

Apply these changes:

     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
📝 Committable suggestion

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

Suggested change
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
volumes:
- minio_data:/data
environment:
MINIO_ROOT_USER: "minioadmin"
MINIO_ROOT_PASSWORD: "minioadmin"
entrypoint: /bin/sh -c "
/usr/bin/docker-entrypoint.sh server --console-address ':9001' --address ':9000' /data &
sleep 1 &&
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
timeout: 20s
retries: 3
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
volumes:
- minio_data:/data
environment:
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 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: 10s
timeout: 20s
retries: 3

Comment on lines +75 to +77
# This is the name of the S3 Bucket or MinIO Bucket
BUCKET_NAME="default-storage"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add explicit storage type configuration

The configuration doesn't provide a clear way to select between S3 and MinIO storage backends. This could lead to confusion about which storage system is being used.

Add a STORAGE_TYPE variable to explicitly control the storage backend:

 # Storage configuration for either AWS S3 or MinIO
+# STORAGE_TYPE: The storage backend to use
+# Available options: s3, minio
+STORAGE_TYPE=minio
+
 # This is the name of the S3 Bucket or MinIO Bucket
 BUCKET_NAME="default-storage"
📝 Committable suggestion

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

Suggested change
# Storage configuration for either AWS S3 or MinIO
# This is the name of the S3 Bucket or MinIO Bucket
BUCKET_NAME="default-storage"
# Storage configuration for either AWS S3 or MinIO
# STORAGE_TYPE: The storage backend to use
# Available options: s3, minio
STORAGE_TYPE=minio
# This is the name of the S3 Bucket or MinIO Bucket
BUCKET_NAME="default-storage"

Comment on lines 72 to 74
# Available options: false, s3, minio
# If set to false, AWS_S3_BUCKET_NAME is not required.
FILE_UPLOAD=false
# AWS_S3_BUCKET_NAME: S3 Bucket name
# This is the name of the S3 Bucket
AWS_S3_BUCKET_NAME="your_s3_bucket_name" No newline at end of file
# Set to true if file upload is required.
FILE_UPLOAD=true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update FILE_UPLOAD comment to reflect current options

The comment on line 72 references the removed AWS_S3_BUCKET_NAME variable and doesn't accurately reflect the current storage options.

Apply this diff to fix the comment:

 # FILE_UPLOAD: Whether to enable file upload to storage
-# Available options: false, s3, minio
-# If set to false, AWS_S3_BUCKET_NAME is not required.
+# Set to true to enable file upload functionality
+# When enabled, configure either S3 or MinIO storage below
 # Set to true if file upload is required.
 FILE_UPLOAD=true
📝 Committable suggestion

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

Suggested change
# Available options: false, s3, minio
# If set to false, AWS_S3_BUCKET_NAME is not required.
FILE_UPLOAD=false
# AWS_S3_BUCKET_NAME: S3 Bucket name
# This is the name of the S3 Bucket
AWS_S3_BUCKET_NAME="your_s3_bucket_name"
\ No newline at end of file
# Set to true if file upload is required.
FILE_UPLOAD=true
# FILE_UPLOAD: Whether to enable file upload to storage
# Set to true to enable file upload functionality
# When enabled, configure either S3 or MinIO storage below
# Set to true if file upload is required.
FILE_UPLOAD=true

Comment on lines +78 to +82
MINIO_ENDPOINT="http://localhost:9000"
# Common access keys for both S3 and MinIO
MINIO_ACCESS_KEY="minioadmin"
MINIO_SECRET_KEY="minioadmin"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance security and documentation for MinIO configuration

The MinIO configuration needs better documentation and security warnings for sensitive values.

Apply this diff to improve the configuration:

-# MinIO endpoint, only required for MinIO
+# MINIO_ENDPOINT: The endpoint URL for the MinIO server
+# Format: http(s)://<host>:<port>
+# Example: http://localhost:9000 (For development mode)
 MINIO_ENDPOINT="http://localhost:9000"

-# Common access keys for both S3 and MinIO
+# MINIO_ACCESS_KEY: Access key for authentication
+# Warning: Use a strong, unique value in production
+# Default: minioadmin (for development only)
 MINIO_ACCESS_KEY="minioadmin"

+# MINIO_SECRET_KEY: Secret key for authentication
+# Warning: Keep this value secret and never commit to version control
+# Default: minioadmin (for development only)
 MINIO_SECRET_KEY="minioadmin"
📝 Committable suggestion

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

Suggested change
# MinIO endpoint, only required for MinIO
MINIO_ENDPOINT="http://localhost:9000"
# Common access keys for both S3 and MinIO
MINIO_ACCESS_KEY="minioadmin"
MINIO_SECRET_KEY="minioadmin"
# MINIO_ENDPOINT: The endpoint URL for the MinIO server
# Format: http(s)://<host>:<port>
# Example: http://localhost:9000 (For development mode)
MINIO_ENDPOINT="http://localhost:9000"
# MINIO_ACCESS_KEY: Access key for authentication
# Warning: Use a strong, unique value in production
# Default: minioadmin (for development only)
MINIO_ACCESS_KEY="minioadmin"
# MINIO_SECRET_KEY: Secret key for authentication
# Warning: Keep this value secret and never commit to version control
# Default: minioadmin (for development only)
MINIO_SECRET_KEY="minioadmin"

Comment on lines 72 to 84
# Available options: false, s3, minio
# If set to false, AWS_S3_BUCKET_NAME is not required.
FILE_UPLOAD=false
# AWS_S3_BUCKET_NAME: S3 Bucket name
# This is the name of the S3 Bucket
AWS_S3_BUCKET_NAME="your_s3_bucket_name" No newline at end of file
# Set to true if file upload is required.
FILE_UPLOAD=true
# Storage configuration for either AWS S3 or MinIO
# This is the name of the S3 Bucket or MinIO Bucket
BUCKET_NAME="default-storage"
# MinIO endpoint, only required for MinIO
MINIO_ENDPOINT="http://localhost:9000"
# Common access keys for both S3 and MinIO
MINIO_ACCESS_KEY="minioadmin"
MINIO_SECRET_KEY="minioadmin"
# AWS Region, only required for AWS S3
AWS_REGION="your_aws_region"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Environment variables need to be updated for consistency

The verification revealed inconsistencies between the environment variables defined and their actual usage in the codebase:

  • The code uses STORAGE_ACCESS_KEY and STORAGE_SECRET_KEY, but the .env file defines MINIO_ACCESS_KEY and MINIO_SECRET_KEY
  • The storage configuration in storage.module.ts supports both S3 and MinIO using a unified configuration approach
  • The environment variables should be renamed for consistency:
    • Rename MINIO_ACCESS_KEY to STORAGE_ACCESS_KEY
    • Rename MINIO_SECRET_KEY to STORAGE_SECRET_KEY
🔗 Analysis chain

Verify storage configuration usage

Let's verify how these environment variables are being used in the codebase.


Let me try a different search pattern to verify the storage configuration usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of storage-related environment variables

# Test: Check for environment variable usage in TypeScript files
echo "Checking environment variable usage:"
rg -A 2 'process\.env\.(FILE_UPLOAD|BUCKET_NAME|MINIO_ENDPOINT|MINIO_ACCESS_KEY|MINIO_SECRET_KEY|AWS_REGION)'

# Test: Check for MinIO client initialization
echo "Checking MinIO client initialization:"
ast-grep --pattern 'new Minio.Client({
  $$$
})'

# Test: Check for S3 client initialization
echo "Checking S3 client initialization:"
ast-grep --pattern 'new S3Client({
  $$$
})'

Length of output: 456


Script:

#!/bin/bash
# Search for storage-related configurations and implementations
echo "Searching for storage-related files and configurations:"
fd -e ts -e js storage

echo "\nChecking content of storage-related files:"
fd -e ts -e js storage --exec cat {}

echo "\nSearching for storage/file upload related imports:"
rg -i "import.*(@aws-sdk/client-s3|minio|storage)"

echo "\nSearching for bucket name usage:"
rg -i "bucket.*name"

Length of output: 2413

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

Successfully merging this pull request may close these issues.

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