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

Mirror Plugin: Initial version #34

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Mirror Plugin: Initial version #34

merged 1 commit into from
Jan 26, 2024

Conversation

ikaneshiro
Copy link
Contributor

@ikaneshiro ikaneshiro commented Jan 25, 2024

  • Syncronizes file repositories with rsync
  • Creates index.html files for each directory
  • Presents a web api for traversing or fetching content

Summary by CodeRabbit

  • New Features
    • Introduced a new plugin, BeskarMirrorBinary, for enhanced configuration and integration capabilities.
    • Added a command-line tool beskar-mirror for server and plugin services.
    • Implemented new functionalities for managing repositories, including creation, deletion, updates, synchronization, and information retrieval.
    • New routing capabilities for requests and serving mirrored artifacts via HTTP.
    • Added database schemas and functionality for logs, files, properties, events, and synchronization status management.
    • Enhanced file handling in mirror repositories, including storage, synchronization, and index generation.
    • Introduced OpenAPI Specification (OAS) version 2 documentation for the Mirror Repository Management API.
  • Documentation
    • Updated .helmignore to improve package build process by excluding unnecessary files.
    • Added Apache License, Version 2.0, to outline terms and conditions for use and distribution.

Copy link
Contributor

coderabbitai bot commented Jan 25, 2024

Warning

Rate Limit Exceeded

@ikaneshiro has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 52 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 286779e and 9c8ef6f.

Walkthrough

The recent changes introduced a comprehensive suite of updates for a new plugin called BeskarMirror, focusing on repository management, configuration parsing, HTTP service functionality, and database schema creation for logs, repositories, and synchronization status. It also includes enhancements for handling Kubernetes chart packaging, licensing, and command-line tooling for server operations. These updates collectively aim to streamline the process of mirroring repositories, managing files, and serving artifacts through a well-structured, plugin-based architecture.

Changes

Files Change Summary
build/mage/build.go Introduced BeskarMirrorBinary constant, added plugin configuration, including paths, API, and flags.
charts/beskar-mirror/... Updated .helmignore, added Apache License, and Kubernetes chart templates.
cmd/beskar-mirror/main.go Added functionality for the beskar-mirror CLI tool.
internal/plugins/mirror/... Added multiple files for repository management, HTTP request handling, and database schemas.
pkg/orasmirror/file.go, pkg/plugins/mirror/api/v1/... Enhanced functionality for mirror file interactions and API management.

"In the realm of code and binary,
A rabbit hopped, both bold and tiny.
🐇 With each leap, a mirror takes shape,
Reflecting artifacts, in an endless cape."
🌟✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 25

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 286779e and 2186463.
Files ignored due to path filters (14)
  • charts/beskar-mirror/Chart.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/configmap.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/hpa.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/pvc.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/role.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/secret.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/service.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/serviceaccount.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/templates/statefulset.yaml is excluded by: !**/*.yaml
  • charts/beskar-mirror/values.yaml is excluded by: !**/*.yaml
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
  • internal/plugins/mirror/embedded/data.json is excluded by: !**/*.json
  • internal/plugins/mirror/pkg/config/default/beskar-mirror.yaml is excluded by: !**/*.yaml
Files selected for processing (34)
  • build/mage/build.go (3 hunks)
  • charts/beskar-mirror/.helmignore (1 hunks)
  • charts/beskar-mirror/LICENSE (1 hunks)
  • charts/beskar-mirror/templates/_helpers.tpl (1 hunks)
  • cmd/beskar-mirror/main.go (1 hunks)
  • internal/plugins/mirror/api.go (1 hunks)
  • internal/plugins/mirror/embedded/router.rego (1 hunks)
  • internal/plugins/mirror/pkg/config/beskar-mirror.go (1 hunks)
  • internal/plugins/mirror/pkg/config/beskar-mirror_test.go (1 hunks)
  • internal/plugins/mirror/pkg/index/embedded/index.html.tpl (1 hunks)
  • internal/plugins/mirror/pkg/index/index.go (1 hunks)
  • internal/plugins/mirror/pkg/index/index_test.go (1 hunks)
  • internal/plugins/mirror/pkg/index/testdata/index.html (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/log.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/repository.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/schema/log/000000_create_logs_table.sql (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/schema/repository/000000_create_files_table.sql (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/schema/status/000000_create_properties_table.sql (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/schema/status/000001_create_events_table.sql (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/schema/status/000002_create_reposync_table.sql (1 hunks)
  • internal/plugins/mirror/pkg/mirrordb/status.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrorrepository/api.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrorrepository/database.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrorrepository/handler.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrorrepository/rsyncstorage.go (1 hunks)
  • internal/plugins/mirror/pkg/mirrorrepository/sync.go (1 hunks)
  • internal/plugins/mirror/plugin.go (1 hunks)
  • internal/plugins/mirror/web.go (1 hunks)
  • pkg/orasmirror/file.go (1 hunks)
  • pkg/plugins/mirror/api/v1/api.go (1 hunks)
  • pkg/plugins/mirror/api/v1/endpoint.go (1 hunks)
  • pkg/plugins/mirror/api/v1/http.go (1 hunks)
  • pkg/plugins/mirror/api/v1/http_client.go (1 hunks)
  • pkg/plugins/mirror/api/v1/oas2.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • charts/beskar-mirror/.helmignore
  • charts/beskar-mirror/LICENSE
  • internal/plugins/mirror/pkg/index/testdata/index.html
Additional comments: 43
internal/plugins/mirror/pkg/mirrordb/schema/status/000001_create_events_table.sql (1)
  • 1-4: The schema for creating the events table looks good. It correctly defines an id as the primary key and a payload to store the event data.
internal/plugins/mirror/pkg/mirrordb/schema/log/000000_create_logs_table.sql (1)
  • 1-6: The schema for creating the logs table is correctly defined with appropriate fields for logging (id, level, date, message). The use of AUTOINCREMENT for the id field ensures unique identifiers for each log entry.
internal/plugins/mirror/pkg/mirrordb/schema/status/000000_create_properties_table.sql (2)
  • 1-6: The schema for creating the properties table is well-defined, including fields for id, created, mirror, and mirror_urls. This setup supports storing configuration properties for the mirror functionality.
  • 8-8: The initial INSERT statement ensures that there is a default row in the properties table. This is a good practice for initializing default configurations.
internal/plugins/mirror/pkg/mirrordb/schema/repository/000000_create_files_table.sql (2)
  • 1-8: The schema for creating the files table is correctly structured, including fields for file metadata (tag, name, link, modified_time, mode, size). This setup supports storing information about files managed by the mirror plugin.
  • 10-10: Creating an index on the name field of the files table is a good practice for optimizing queries that search for files by name.
internal/plugins/mirror/pkg/mirrordb/schema/status/000002_create_reposync_table.sql (2)
  • 1-9: The schema for creating the sync table is well-defined, including fields to track the synchronization process (id, syncing, start_time, end_time, total_files, synced_files, sync_error). This setup supports monitoring and managing synchronization tasks.
  • 11-11: The initial INSERT statement ensures that there is a default row in the sync table. This is a good practice for initializing the synchronization status.
internal/plugins/mirror/pkg/index/embedded/index.html.tpl (1)
  • 1-33: The HTML template for generating directory indexes is well-structured, with placeholders for the current directory, previous directory, directories, and files. This setup supports dynamically generating browsable directory listings.
internal/plugins/mirror/pkg/index/index.go (1)
  • 1-49: The Go code for generating directory indexes from the provided template is correctly implemented. The Generate function and the data structures for directories and files (Directory, File, Config) are well-defined, supporting the dynamic generation of browsable directory listings.
internal/plugins/mirror/pkg/mirrorrepository/sync.go (1)
  • 12-63: The Go code for the repository synchronization process is well-structured, including comprehensive error handling, database updates, and rsync operations. The use of defer for cleanup and error handling is correctly implemented. However, ensure that dbCtx is properly defined and passed to the updateSyncDatabase function.
internal/plugins/mirror/pkg/index/index_test.go (1)
  • 16-61: The Go test code for the index generation function is correctly implemented, including setup for test data, calling the Generate function, and performing assertions on the result. This test ensures that the index generation behaves as expected.
internal/plugins/mirror/embedded/router.rego (1)
  • 1-57: The Rego policy code for routing decisions is well-structured, including logic for handling blob URLs, redirecting based on repository patterns, and handling body-based routing. This setup supports flexible and dynamic routing decisions based on repository and filename.
cmd/beskar-mirror/main.go (1)
  • 56-73: The Go code for the main entry point of the mirror plugin is correctly implemented, including command-line flag parsing, server setup, and handling of the version subcommand. The structure and error handling are appropriate for initializing and running the plugin.
internal/plugins/mirror/pkg/config/beskar-mirror_test.go (1)
  • 12-50: The Go test code for parsing the Beskar Mirror configuration is well-implemented, including comprehensive assertions on various configuration fields. This test ensures that the configuration parsing behaves as expected and correctly initializes the configuration values.
internal/plugins/mirror/pkg/mirrordb/log.go (1)
  • 1-117: The Go code for log database operations is well-structured, including functions for opening the log database, adding logs, and walking through logs. The use of embedded SQL schemas and the WalkLogFunc callback pattern are correctly implemented. Ensure that the Open and Close methods are properly managing database connections.
internal/plugins/mirror/pkg/mirrorrepository/database.go (1)
  • 19-115: The Go code for database operations related to the mirror repository is correctly implemented, including functions for updating synchronization status, adding and removing files, and retrieving file information. The use of MD5 for generating file tags (md5.Sum) should be reviewed for its suitability in this context, considering potential collision issues in large datasets.
internal/plugins/mirror/pkg/config/beskar-mirror.go (1)
  • 62-111: The Go code for parsing the Beskar Mirror configuration is well-structured, including logic for handling default configurations and custom directories. The use of a configuration parser with versioned parse information supports future configuration schema versions. Ensure that the default configuration (defaultBeskarMirrorConfig) meets all necessary configuration requirements.
internal/plugins/mirror/api.go (1)
  • 14-82: The Go code for the mirror plugin API is correctly implemented, including functions for creating, deleting, updating, and syncing repositories, as well as retrieving repository properties and logs. The use of checkRepository to validate repository names against a regex pattern is a good practice for ensuring input validity.
internal/plugins/mirror/web.go (1)
  • 18-105: The Go code for the web handler of the mirror plugin includes logic for resolving symlinks, handling file requests, and serving directory listings. The use of resolveSymlinks to handle symlinked files and the integration with ORAS for serving files are correctly implemented. Ensure that the error handling and HTTP status codes used are appropriate for the various failure scenarios.
pkg/plugins/mirror/api/v1/api.go (1)
  • 1-115: The Go code for the API definitions of the mirror plugin is well-defined, including types and interfaces for managing mirror repositories, such as repository properties, logs, files, and sync status. The use of regular expressions for validating repository names (RepositoryMatch) and the structured approach to defining API operations (Mirror interface) support a clear and extensible API design.
pkg/orasmirror/file.go (1)
  • 30-161: The Go code for ORAS mirror file operations, including functions for generating file references, pushing static files, and pulling mirror files, is correctly implemented. The use of MD5 for generating file tags should be reviewed for its suitability, considering potential collision issues. The MirrorPuller implementation and its integration with the ORAS library support efficient file handling in the mirror plugin.
charts/beskar-mirror/templates/_helpers.tpl (1)
  • 1-150: The Helm chart helper template for the Beskar Mirror plugin is well-structured, including definitions for common labels, service account names, environment variables, volume mounts, and volumes. The use of template functions (define) for generating reusable snippets supports a DRY and maintainable Helm chart. Ensure that the environment variable names and volume configurations match the requirements of the Beskar Mirror plugin.
pkg/plugins/mirror/api/v1/oas2.go (3)
  • 1-1: Generated code disclaimer.

The file contains a clear disclaimer that it's generated code and should not be edited manually. This is a good practice.

  • 13-28: Swagger version and metadata.

The Swagger version and metadata (title, version, description, license) are correctly defined and follow best practices for API documentation.

  • 32-136: API paths and operations.

The API paths and operations are well-defined, following RESTful principles and correctly using HTTP methods for CRUD operations.

pkg/plugins/mirror/api/v1/http.go (2)
  • 17-153: HTTP router setup for API endpoints.

The HTTP router setup for API endpoints is well-structured, using appropriate HTTP methods and paths for each operation. The use of middleware for validation and error handling is also correctly implemented.

  • 156-298: Request decoding functions.

The request decoding functions are correctly implemented, using the provided codec for decoding and performing validation on the decoded request objects.

internal/plugins/mirror/pkg/mirrorrepository/handler.go (12)
  • 55-60: The QueueEvent method is implemented correctly. It logs and enqueues events efficiently.
  • 63-77: The getRepositoryDB method correctly ensures thread safety with mutex locks and lazy initialization. Good use of defer for unlocking.
  • 80-94: The getStatusDB method follows best practices similar to getRepositoryDB, ensuring thread safety and lazy initialization.
  • 97-111: The getLogDB method is consistent with the other database getter methods in its use of mutexes and lazy initialization. Well done.
  • 192-208: The setMirrorURLs method correctly uses a mutex to ensure thread safety when setting mirror URLs. Good practice.
  • 211-215: The getMirrorURLs method properly uses read locks for thread safety, which is efficient for concurrent reads.
  • 218-221: The setMirror method correctly uses a mutex for thread safety. This is a good practice for concurrent access.
  • 224-227: The setCreated method follows best practices for thread safety with proper locking.
  • 230-234: The isCreated method efficiently uses read locks for thread-safe reads. Well implemented.
  • 237-241: The getMirror method demonstrates good use of read locks for thread safety. This is efficient for concurrent reads.
  • 244-245: The getSync method correctly uses atomic operations for thread-safe access to the sync state. This is an efficient choice.
  • 248-250: The setSync method properly uses atomic operations to update the sync state safely. Good choice for concurrency.
build/mage/build.go (3)
  • 68-68: The constant BeskarMirrorBinary is correctly defined, aligning with the naming convention of existing binary constants.
  • 176-193: The configuration for BeskarMirrorBinary within the binaries map includes correct paths for configuration files, API generation settings, and integration test environment variables. However, ensure that the specified paths and environment variables align with the actual directory structure and configuration requirements of the beskar-mirror plugin.
  • 236-236: The addition of BeskarMirrorBinary to the Plugins method correctly integrates the new plugin into the build process, ensuring it is built alongside other plugins.

- Syncronizes file repositories with rsync
- Creates `index.html` files for each directory
- Presents a web api for traversing or fetching content

Signed-off-by: Ian Kaneshiro <[email protected]>
@cclerget cclerget merged commit 64999f4 into main Jan 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants