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

Fix/no commit hash on the deployed project #611

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ihab4real
Copy link
Collaborator

@ihab4real ihab4real commented Dec 29, 2024

Fixes #567
Follows this approach


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added ability to track Git commit SHA through environment variable
    • Enhanced flexibility for retrieving current Git commit SHA
  • Tests

    • Updated system tests to cover new Git commit SHA retrieval methods
    • Added test scenarios for environment variable and fallback mechanisms
  • Infrastructure

    • Modified Dockerfile to support passing Git commit SHA as a build argument

Copy link

coderabbitai bot commented Dec 29, 2024

Walkthrough

The pull request introduces a mechanism to capture and expose the Git commit SHA in a deployed Ruby on Rails application. This is achieved by adding a build argument and environment variable in the Dockerfile, modifying the GitCommitSha model to check the environment variable first, and updating the corresponding system tests to validate the new approach of retrieving the commit hash.

Changes

File Change Summary
.controlplane/Dockerfile Added ARG GIT_COMMIT_SHA and ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} to include commit hash in the Docker image
app/models/git_commit_sha.rb Updated current_sha method to first check GIT_COMMIT_SHA environment variable before falling back to previous retrieval methods
spec/system/pages_spec.rb Modified test contexts to use environment variable for commit SHA and added cleanup mechanism

Assessment against linked issues

Objective Addressed Explanation
Provide commit hash for deployed project [#567]
Avoid including entire .git directory Uses environment variable instead of .git directory

Poem

🐰 In the realm of code, a commit hash gleams,
Through Dockerfile's magic and environment's streams,
No .git directory, just a simple trace,
Of the version that runs in this digital space!
Hop, hop, hooray for tracking our code's embrace! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
spec/system/pages_spec.rb (1)

20-29: Consider using a more robust approach to stub environment variables.

Manually setting and deleting ENV["GIT_COMMIT_SHA"] works but can be fragile if additional tests run in parallel or the environment remains altered after a failure. Libraries like ClimateControl isolate environment variable changes per test. This approach helps ensure consistency and concurrency safety.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e1f722 and 309d712.

📒 Files selected for processing (3)
  • .controlplane/Dockerfile (1 hunks)
  • app/models/git_commit_sha.rb (1 hunks)
  • spec/system/pages_spec.rb (2 hunks)
🔇 Additional comments (3)
app/models/git_commit_sha.rb (1)

8-10: Ensure proper handling of empty or malformed environment variables.

By relying on .presence, this correctly treats empty strings as invalid. However, consider adding a test case for the scenario where GIT_COMMIT_SHA is set but empty. This helps ensure robust fallback behavior to the file-based or git-based retrieval.

spec/system/pages_spec.rb (1)

46-56: Test coverage for fallback logic looks good.

Stubbing retrieve_sha_from_git ensures the fallback scenario is thoroughly tested. This approach is a clean way to validate that the application correctly retrieves the SHA when the environment variable and file-based methods are unavailable.

.controlplane/Dockerfile (1)

79-82: Great addition of a build argument for the commit SHA.

Defining ARG GIT_COMMIT_SHA and setting it to the environment variable ensures reproducible builds and easy identification of the deployed commit. Confirm that your build pipeline passes --build-arg GIT_COMMIT_SHA=$(git rev-parse HEAD) (or similar) so the SHA is set accurately in production.

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

Successfully merging this pull request may close these issues.

No commit hash on the deployed project
1 participant