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

ci(server): mongo update 7 #1326

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

ci(server): mongo update 7 #1326

wants to merge 2 commits into from

Conversation

hexaforce
Copy link
Contributor

@hexaforce hexaforce commented Dec 24, 2024

Overview

I will update the version of MongoDB used for development to version 7.

This will match the current cloud environment.

Additionally, I will set up a replica for MongoDB. This is necessary to enable complex transactions in MongoDB and is required when running reearth-cloud locally.

This will not affect reearth-visualizer.

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • Chores
    • Updated the MongoDB service definition in the CI workflow.
    • Added caching for dependencies in the CI configuration.

@hexaforce hexaforce requested a review from pyshx December 24, 2024 05:34
@hexaforce hexaforce self-assigned this Dec 24, 2024
@hexaforce hexaforce requested a review from rot1024 as a code owner December 24, 2024 05:34
Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request updates the GitHub Actions CI workflow configuration for the server testing environment. The primary modifications include upgrading the MongoDB service image from version 5 to version 7 and adding a cache dependency path for the server's Go dependencies. These changes aim to improve the consistency and performance of the continuous integration pipeline by using a more recent MongoDB version and implementing dependency caching.

Changes

File Change Summary
.github/workflows/ci_server.yml - Updated MongoDB service image from mongo:5-focal to mongo:7
- Added cache-dependency-path for server/go.sum in the ci-server-test job

Possibly related PRs

Suggested labels

server

Poem

🐰 A Rabbit's CI Delight 🚀

MongoDB leaps from five to seven,
Caching dependencies, a coder's heaven
Workflows dance with newfound grace
Continuous integration's warm embrace
Testing spirits soar so 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 55f0762 and 73bfa3d.

📒 Files selected for processing (1)
  • .github/workflows/ci_server.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci_server.yml

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 Dec 24, 2024

Deploy Preview for reearth-web canceled.

Name Link
🔨 Latest commit 73bfa3d
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/676a593c4248a500087934e7

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: 1

🔭 Outside diff range comments (1)
.github/workflows/ci_server.yml (1)

Replica set configuration should be kept in CI environment

The review comment is valid. From the search results, we can see that:

  • The docker-compose.yml uses MongoDB with replica set configuration: command: ["mongod", "--replSet", "rs0"]
  • The application's default configuration in various environments (development, docker) consistently includes replica set setup
  • The CI environment (.github/workflows/ci_server.yml) is the only place where replica set configuration is missing

The suggested change to include replica set configuration in CI would make it consistent with other environments and ensure proper testing of MongoDB-dependent features.

🔗 Analysis chain

Line range hint 41-42: Review MongoDB connection configuration

The test environment uses a simple MongoDB URL without replica set configuration. This might not properly test the application's behavior with a replica set.

Consider updating the connection string to match production configuration:

        env:
-         REEARTH_DB: mongodb://localhost
+         REEARTH_DB: mongodb://localhost:27017/?replicaSet=rs0

Let me gather more information about the MongoDB configuration in the codebase to verify if replica set configuration is necessary.

This will help us understand:

  1. How MongoDB connections are configured across the codebase
  2. Whether replica sets are used in other environments
  3. If there are any specific MongoDB client initialization patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for MongoDB connection strings and configuration patterns
rg -i "mongodb://" -A 3 -B 3

# Search for MongoDB related configuration or setup files
fd -e yaml -e yml -e json | xargs rg -i "mongodb|mongo"

# Look for any MongoDB client initialization or connection setup code
ast-grep --pattern 'mongodb://$$$'

Length of output: 2690

🧰 Tools
🪛 actionlint (1.7.4)

33-33: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (1)
docker-compose.yml (1)

23-24: Review MongoDB replication configuration

The current replication setup appears incomplete:

  1. Single node replica set configuration without additional members
  2. No explicit configuration for replica set initialization timing
  3. Missing health check to ensure replica set is ready before application starts

Consider these improvements:

  1. Add healthcheck configuration to ensure replica set is properly initialized
  2. Add restart policy for proper startup ordering
  3. Consider adding additional replica set members for proper redundancy

Example additions:

    command: ["mongod", "--replSet", "rs0"]
+   healthcheck:
+     test: mongosh --eval "rs.status().ok"
+     interval: 10s
+     timeout: 5s
+     retries: 5
+   restart: always
🧰 Tools
🪛 yamllint (1.35.1)

[error] 24-24: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 769a278 and de81ae8.

📒 Files selected for processing (3)
  • .github/workflows/ci_server.yml (1 hunks)
  • docker-compose.yml (1 hunks)
  • mongo-init.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • mongo-init.js
🧰 Additional context used
🪛 yamllint (1.35.1)
docker-compose.yml

[error] 24-24: trailing spaces

(trailing-spaces)

🔇 Additional comments (2)
docker-compose.yml (2)

23-23: Verify mongo-init.js script existence and permissions

The configuration mounts mongo-init.js but this file is not included in the PR. Please ensure:

  1. The initialization script is provided
  2. It contains proper replica set initialization logic
✅ Verification successful

MongoDB initialization script is present and contains replica set configuration

The mongo-init.js file exists and includes the necessary replica set initialization logic:

  • Initializes a replica set named "rs0"
  • Configures a single member node at localhost:27017
  • Includes status check command
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if mongo-init.js exists and verify its content
if [ -f mongo-init.js ]; then
    echo "File exists. Content:"
    cat mongo-init.js
else
    echo "ERROR: mongo-init.js is missing"
    exit 1
fi

Length of output: 195


18-18: Verify MongoDB 7.x compatibility with the application

The upgrade to MongoDB 7 (focal) is a significant version change that might introduce breaking changes. Please ensure:

  1. The application is compatible with MongoDB 7.x
  2. All MongoDB driver versions in the application support MongoDB 7.x

Run this script to check MongoDB driver compatibility in the codebase:

✅ Verification successful

Let me gather more information about the MongoDB driver version being used.


MongoDB 7.x compatibility is verified

The application uses MongoDB Go Driver v1.13.1 which fully supports MongoDB 7.x. According to MongoDB's compatibility matrix, this driver version is compatible with MongoDB server versions 3.6 through 7.0. The upgrade to mongo:7-focal is safe to proceed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for MongoDB driver/client version declarations
rg -g '*.go' 'mongo.Connect|mongo.NewClient|go.mongodb.org/mongo-driver' server/

Length of output: 4981


Script:

#!/bin/bash
# Check go.mod for MongoDB driver version
rg "go.mongodb.org/mongo-driver" server/go.mod -A 1

Length of output: 306

Comment on lines 29 to 31
- name: Docker Compose start
run: docker compose -f ../docker-compose.yml up -d reearth-mongo
working-directory: server
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance MongoDB service initialization in CI

The current setup has several potential issues:

  1. No wait for MongoDB to be ready before tests
  2. No verification of replica set initialization
  3. Relative path ../docker-compose.yml might be fragile in CI

Add proper initialization checks:

      - name: Docker Compose start
        run: docker compose -f ../docker-compose.yml up -d reearth-mongo
        working-directory: server
+     - name: Wait for MongoDB
+       run: |
+         timeout 30s bash -c 'until mongosh --eval "rs.status().ok" > /dev/null 2>&1; do sleep 1; done'
+       working-directory: server

Also, consider using absolute paths with ${{ github.workspace }} for more reliable file resolution:

-       run: docker compose -f ../docker-compose.yml up -d reearth-mongo
+       run: docker compose -f ${{ github.workspace }}/docker-compose.yml up -d reearth-mongo

Committable suggestion skipped: line range outside the PR's diff.

mongo-init.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

command: ["mongod", "--replSet", "rs0"]

The idea is to set up the replica (rs0) using the "mongod" startup option, and once it starts, the mongo-init.js will be executed, enabling rs0.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need replica, we can keep on using mongo the way we've been doing so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I will remove it.
When running reearth-cloud locally, it needs to be configured individually.

@pyshx pyshx changed the title feat(server): mongo update 7 ci(server): mongo update 7 Dec 24, 2024
@hexaforce hexaforce force-pushed the feat/mogodb-update-ver7 branch from a01ce11 to 73bfa3d Compare December 24, 2024 06:48
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.

2 participants