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 BASEHREF handling in Docker Compose #249

Merged
merged 3 commits into from
Jan 10, 2025
Merged

Conversation

FelixFrizzy
Copy link
Collaborator

@FelixFrizzy FelixFrizzy commented Jan 10, 2025

  • envsubst would overwrite existing skosmos config on every startup
  • basehref now written to config.ttl with bash script

Summary by CodeRabbit

  • New Features

    • Added a custom script for replacing base href configuration in Skosmos services
    • Simplified environment variable handling in Docker Compose configuration
  • Chores

    • Updated configuration files for Skosmos development and live environments
    • Removed template configuration files
    • Modified Docker Compose service initialization process
  • Bug Fixes

    • Improved configuration file processing for more reliable URL configuration

- envsubst would overwrite existing skosmos config on every startup
- basehref now written to config.ttl with bash script
Copy link

coderabbitai bot commented Jan 10, 2025

Warning

Rate limit exceeded

@FelixFrizzy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 55 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

Reviewing files that changed from the base of the PR and between 3d175cd and a671d66.

📒 Files selected for processing (2)
  • docker-compose.yml (4 hunks)
  • helperscripts/replace-basehref.sh (1 hunks)

Walkthrough

This pull request introduces changes to the Docker Compose configuration and Skosmos configuration files. The primary modifications involve removing quotation marks from environment variables in docker-compose.yml, adding a new helper script replace-basehref.sh to handle configuration file updates, and updating the configuration files for both development and live Skosmos services. The changes replace the previous envsubst method with a custom script for processing configuration files and hardcode the base href URLs.

Changes

File Change Summary
docker-compose.yml - Removed quotes from BASEHREFDEV and BASEHREFLIVE environment variables
- Added volume mount for replace-basehref.sh in both skosmos-dev and skosmos-live services
- Updated command to use new helper script instead of envsubst
helperscripts/replace-basehref.sh - New Bash script added for replacing skosmos:baseHref in configuration files
- Includes error handling and backup creation
skosmos-dev/config-template.ttl - File deleted
skosmos-dev/config.ttl - Removed dc: and void: prefixes
- Hardcoded skosmos:baseHref to "http://localhost:9000/skosmos-dev/"
skosmos-live/config-template.ttl - File deleted
skosmos-live/config.ttl - Removed dc: and void: prefixes
- Hardcoded skosmos:baseHref to "http://localhost:9000/skosmos-live/"

Sequence Diagram

sequenceDiagram
    participant DC as Docker Compose
    participant HS as Helper Script
    participant CF as Config File
    DC->>HS: Execute replace-basehref.sh
    HS->>CF: Read original config
    HS->>CF: Create backup
    HS->>CF: Replace baseHref value
    HS->>CF: Validate and save changes
    HS-->>DC: Return success/failure status
Loading

Possibly Related PRs

Poem

🐰 A Rabbit's Configuration Tale 🐰

With scripts and configs, we dance and twirl,
Replacing base hrefs in a magical swirl
No quotes to bind, no envsubst in sight
Our helper script makes everything right!
Docker composes, the rabbit's delight! 🎉


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 (2)
helperscripts/replace-basehref.sh (1)

1-77: Well-structured script with comprehensive error handling!

The script follows best practices with clear documentation, error handling, and backup creation. A few suggestions for improvement:

  1. Declare and assign variables separately to avoid masking return values:
-    local timestamp=$(date +"%Y%m%d_%H%M%S")
+    local timestamp
+    timestamp=$(date +"%Y%m%d_%H%M%S")
  1. Add input validation for the basehref format:
 basehref="$2"
+# Validate basehref format
+if [[ ! "$basehref" =~ ^https?:// ]]; then
+    echo "Error: basehref must start with http:// or https://"
+    exit 1
+fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 17-17: Declare and assign separately to avoid masking return values.

(SC2155)

skosmos-live/config.ttl (1)

8-8: Consider environment-specific configuration files.

The hardcoded baseHref values in both config files (http://localhost:9000/skosmos-dev/ and http://localhost:9000/skosmos-live/) might limit deployment flexibility. Consider maintaining separate configuration files for different environments (development, staging, production).

This would allow for:

  1. Environment-specific settings without runtime modifications
  2. Better version control of configurations
  3. Simplified deployment process
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 00c88f8 and 3d175cd.

📒 Files selected for processing (6)
  • docker-compose.yml (4 hunks)
  • helperscripts/replace-basehref.sh (1 hunks)
  • skosmos-dev/config-template.ttl (0 hunks)
  • skosmos-dev/config.ttl (1 hunks)
  • skosmos-live/config-template.ttl (0 hunks)
  • skosmos-live/config.ttl (1 hunks)
💤 Files with no reviewable changes (2)
  • skosmos-dev/config-template.ttl
  • skosmos-live/config-template.ttl
🧰 Additional context used
🪛 Shellcheck (0.10.0)
helperscripts/replace-basehref.sh

[warning] 17-17: Declare and assign separately to avoid masking return values.

(SC2155)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test-all
  • GitHub Check: test-all
🔇 Additional comments (5)
helperscripts/replace-basehref.sh (1)

46-46: Consider file permissions for backup and temporary files.

The script creates backup and temporary files but doesn't set their permissions. This could cause issues if the files need to be accessed by other users/processes.

Add permission handling:

 echo "$content" > "$backup_path"
+chmod --reference="$file_path" "$backup_path"
 
 echo "$updated_content" > "$temp_file_path"
+chmod --reference="$file_path" "$temp_file_path"

Also applies to: 50-50

docker-compose.yml (1)

165-165: Ensure script execution permissions in containers.

The helper script is mounted but might not have execution permissions in the containers.

Add a step to make the script executable:

 command: >
   /bin/bash -c "export BASEHREFDEV &&
+  chmod +x /home/replace-basehref.sh &&
   /home/replace-basehref.sh /var/www/html/config.ttl $$BASEHREFDEV &&

Also applies to: 170-171, 195-195, 200-201

✅ Verification successful

Review comment is valid and the suggested fix is recommended.

The script has execution permissions on the host, but Docker bind mounts may not preserve these permissions. Adding chmod +x ensures reliable script execution during container startup, following the same pattern used for other critical scripts in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check current permissions of the script
ls -l helperscripts/replace-basehref.sh

# Search for existing chmod commands in docker-compose and Dockerfile
echo "=== Searching for chmod in docker-compose.yml ==="
rg "chmod" docker-compose.yml -A 2 -B 2

echo "=== Searching for chmod in Dockerfile ==="
fd Dockerfile --exec rg "chmod" {} -A 2 -B 2

# Find all usages of replace-basehref.sh
echo "=== Finding all usages of replace-basehref.sh ==="
rg "replace-basehref.sh" -A 2 -B 2

Length of output: 2806

skosmos-dev/config.ttl (3)

1-7: LGTM! Removed unused prefixes.

The removal of unused dc: and void: prefixes helps maintain a cleaner configuration file.


Line range hint 9-52: LGTM! Configuration follows best practices.

The remaining Skosmos configuration is well-structured and includes all necessary settings.


8-8: Verify the hardcoded base URL approach.

While hardcoding http://localhost:9000/skosmos-dev/ fixes the envsubst overwriting issue, please verify:

  1. If this URL is appropriate for all development environments
  2. If there's a more flexible solution that doesn't require hardcoding

Let's check if this base URL is referenced elsewhere:

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.85%. Comparing base (c840e4f) to head (a671d66).
Report is 11 commits behind head on development.

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #249   +/-   ##
============================================
  Coverage        93.85%   93.85%           
============================================
  Files               49       49           
  Lines             1774     1774           
============================================
  Hits              1665     1665           
  Misses             109      109           

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

@FelixFrizzy FelixFrizzy merged commit 16cbb13 into development Jan 10, 2025
7 of 8 checks passed
@FelixFrizzy FelixFrizzy deleted the skosmos-config branch January 10, 2025 15:59
@coderabbitai coderabbitai bot mentioned this pull request Jan 10, 2025
@FelixFrizzy FelixFrizzy restored the skosmos-config branch January 10, 2025 16:16
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.

1 participant