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

chore(web): validate Re:Earth configuration on container startup #1390

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

KeisukeYamashita
Copy link
Contributor

@KeisukeYamashita KeisukeYamashita commented Jan 30, 2025

Overview

What I've done

I added jq to the Dockerfile so that the container can validate the Re:Earth configuration file (format: JSON) on startup.

This will prevent the container from starting when the required environment variables aren't configured and improve the reliability of our deployment workflow.
In the current implementation, the container will start and run even if the configuration file is broken.

What I haven't done

How I tested

Which point I want you to review particularly

Memo

jq for Alpine is about 650 KB, which is comparatively tiny and worth adding.

Summary by CodeRabbit

  • New Features

    • Added jq utility installation in the Dockerfile to support JSON parsing.
  • Bug Fixes

    • Improved configuration file validation by adding JSON parsing check in the deployment script.

@KeisukeYamashita KeisukeYamashita self-assigned this Jan 30, 2025
Copy link

coderabbitai bot commented Jan 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces changes to the web service's Docker configuration and deployment script. A new command is added to the Dockerfile to install the jq utility, which is then utilized in the 40-envsubst-on-reearth-config.sh script to validate the JSON configuration file. This enhancement ensures that the generated configuration file is valid JSON before the application proceeds.

Changes

File Change Summary
web/Dockerfile Added RUN apk add --no-cache jq to install the jq utility during image build.
web/docker/40-envsubst-on-reearth-config.sh Added JSON validation using jq to check the generated configuration file, exiting with an error if the JSON is invalid.

Sequence Diagram

sequenceDiagram
    participant Dockerfile
    participant BuildStage
    participant Script
    Dockerfile->>BuildStage: Install jq utility
    BuildStage->>Script: Run configuration script
    Script->>Script: Generate config file with envsubst
    Script->>Script: Validate JSON using jq
    alt JSON is valid
        Script-->>BuildStage: Continue deployment
    else JSON is invalid
        Script--xBuildStage: Exit with error
    end
Loading

Possibly related PRs

Suggested reviewers

  • mkumbobeaty
  • airslice

Poem

🐰 A rabbit's tale of config delight,
Where jq checks JSON with all its might.
No broken configs shall pass today,
Validation ensures the smooth deploy's way.
Hippity-hop, our script now gleams bright! 🔍


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ebb8df and b582480.

📒 Files selected for processing (2)
  • web/Dockerfile (1 hunks)
  • web/docker/40-envsubst-on-reearth-config.sh (1 hunks)

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.

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

netlify bot commented Jan 30, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit b582480
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/679c7c5835eb320008ccdb0d
😎 Deploy Preview https://deploy-preview-1390--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@KeisukeYamashita KeisukeYamashita marked this pull request as ready for review January 30, 2025 19:21
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)
web/docker/40-envsubst-on-reearth-config.sh (1)

39-42: Enhance error reporting for JSON validation failures.

While the validation logic is correct, we could provide more helpful error messages by showing the specific JSON parsing error.

Consider this improvement:

-if ! jq empty "$_REEARTH_CONFIG_OUTPUT_FILE" > /dev/null 2>&1; then
-  echo "Invalid JSON configuration file $_REEARTH_CONFIG_OUTPUT_FILE" >&2
+if ! error=$(jq empty "$_REEARTH_CONFIG_OUTPUT_FILE" 2>&1); then
+  echo "Invalid JSON configuration file $_REEARTH_CONFIG_OUTPUT_FILE:" >&2
+  echo "$error" >&2
   exit 1
 fi
web/Dockerfile (1)

71-73: Consider pinning the jq version for reproducible builds.

While the current implementation works, pinning the jq version would ensure reproducible builds and prevent potential issues from unexpected updates.

 RUN --mount=type=cache,target=/var/cache/apk \
-    apk add --no-cache jq
+    apk add --no-cache jq=1.7.1-r0
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9eeaf16 and 4ebb8df.

📒 Files selected for processing (2)
  • web/Dockerfile (1 hunks)
  • web/docker/40-envsubst-on-reearth-config.sh (1 hunks)
🔇 Additional comments (1)
web/Dockerfile (1)

71-73: LGTM! Clean implementation using build cache.

The implementation follows Docker best practices by using cache mount and no-cache flag.

@rot1024 rot1024 force-pushed the validate-reearth-config-on-startup branch from 4ebb8df to b582480 Compare January 31, 2025 07:31
@rot1024 rot1024 changed the title feat(web): validate Re:Earth configuration on container startup chore(web): validate Re:Earth configuration on container startup Jan 31, 2025
@rot1024 rot1024 merged commit d004b64 into main Jan 31, 2025
17 of 18 checks passed
@rot1024 rot1024 deleted the validate-reearth-config-on-startup branch January 31, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants