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

feat: parameterize nakama image #84

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

zulkhair
Copy link
Collaborator

@zulkhair zulkhair commented Nov 13, 2024

Closes: WORLD-XXX

Overview

Change nakama image to alway use latest version and can be parameterize through world.toml if user want to use specific version

Brief Changelog

  • Change nakama default image to latest version
  • Add NAKAMA_IMAGE and NAKAMA_IMAGE_PLATFORM on world.toml to use specific version of nakama

Testing and Verifying

Tested manually using world cardinal start command

Summary by CodeRabbit

  • New Features
    • Enhanced configurability for the Nakama container image and platform settings via environment variables.
    • Improved configurability for the EVM container image and platform settings based on environment variables.
  • Improvements
    • Improved logging for container removal during image building.
    • Enhanced error reporting and progress handling when pulling images.
    • Added robust error handling for asset availability in the release download process.
    • Increased retry duration for service status checks, allowing more time for services to become available.

Copy link

graphite-app bot commented Nov 13, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “graphite/merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

coderabbitai bot commented Nov 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve modifications to the Client struct in the common/docker/client_image.go file, the Nakama function in the common/docker/service/nakama.go file, and the EVM function in the common/docker/service/evm.go file. Enhancements include improved logging and error handling during image building and pulling processes, as well as the introduction of new variables for dynamic configuration of the Nakama and EVM images and platforms, enhancing flexibility without altering existing functionality.

Changes

File Path Change Summary
common/docker/client_image.go - Added logging for container removal in buildImages method.
- Improved error handling and logging in pullImages method with eris.Wrapf and refined progress bar handling.
common/docker/service/nakama.go - Introduced nakamaImage and platform variables for dynamic image and platform configuration.
- Replaced hardcoded image version with nakamaImage variable while retaining existing functionality.
common/docker/service/evm.go - Introduced evmImage and platform variables for dynamic image and platform configuration.
- Updated Image field in container.Config to use evmImage variable.
- Added Platform field in Service struct.
common/editor/editor.go - Enhanced error handling in downloadReleaseIfNotCached function to check for nil or empty Assets field in Release struct.
cmd/world/root/root_test.go - Increased loop iteration count from 60 to 120 in ServiceIsUp and ServiceIsDown functions to extend service status checking duration.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Docker
    Client->>Docker: buildImages()
    Docker-->>Client: Log removal of container
    Client->>Docker: removeContainer()
    Client->>Docker: pullImages()
    Docker-->>Client: Error occurred
    Client->>Docker: Log error with context
    Client->>Docker: Abort progress bar
Loading

Possibly related PRs

Suggested reviewers

  • smsunarto
  • rmrt1n

🪧 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 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
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @zulkhair and the rest of your teammates on Graphite Graphite

@zulkhair zulkhair marked this pull request as ready for review November 13, 2024 18:46
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 64feb1f and 32895b4.

📒 Files selected for processing (2)
  • common/docker/client_image.go (0 hunks)
  • common/docker/service/nakama.go (4 hunks)
💤 Files with no reviewable changes (1)
  • common/docker/client_image.go
🔇 Additional comments (1)
common/docker/service/nakama.go (1)

80-80: LGTM!

The parameterized image is correctly used in the container configuration.

common/docker/service/nakama.go Outdated Show resolved Hide resolved
common/docker/service/nakama.go Outdated Show resolved Hide resolved
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch from 32895b4 to 20e29f5 Compare November 13, 2024 19:17
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch 2 times, most recently from dbad8be to 1b86761 Compare November 13, 2024 19:25
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 32895b4 and 1b86761.

📒 Files selected for processing (3)
  • common/docker/client_image.go (0 hunks)
  • common/docker/service/evm.go (3 hunks)
  • common/docker/service/nakama.go (4 hunks)
💤 Files with no reviewable changes (1)
  • common/docker/client_image.go
🔇 Additional comments (4)
common/docker/service/evm.go (2)

86-86: Service configuration changes look good

The image and platform configurations are properly applied to the service.

Also applies to: 106-106


Line range hint 52-63: Security: Consider removing hardcoded sensitive values

The default values for chainKeyMnemonic, routerKey, and other sensitive configurations are hardcoded. This could lead to accidental use in production environments.

Consider:

  1. Moving these to a separate development configuration file
  2. Requiring these values to be explicitly set in production
  3. Adding validation to ensure development defaults aren't used in production

Let's check if these default values are used elsewhere:

common/docker/service/nakama.go (2)

57-60: LGTM with consideration of previous feedback

The implementation correctly allows for image customization while maintaining backward compatibility.


123-123: LGTM!

The platform configuration is correctly applied to the service struct.

common/docker/service/evm.go Show resolved Hide resolved
common/docker/service/nakama.go Outdated Show resolved Hide resolved
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch from 1b86761 to 4f9e89d Compare November 13, 2024 19:42
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: 2

🧹 Outside diff range comments (1)
common/docker/service/evm.go (1)

Line range hint 86-106: Review sensitive data handling practices

The service configuration exposes sensitive data (keys, mnemonics) through environment variables. This is a security anti-pattern as:

  1. Environment variables are often logged
  2. They're accessible to all processes running as the same user
  3. They can persist in shell history

Consider:

  1. Using a secure secret management service
  2. Implementing runtime secret injection
  3. Using temporary environment variables that are unset after reading

Would you like assistance in implementing a more secure configuration pattern?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 1b86761 and 4f9e89d.

📒 Files selected for processing (3)
  • common/docker/client_image.go (0 hunks)
  • common/docker/service/evm.go (3 hunks)
  • common/docker/service/nakama.go (4 hunks)
💤 Files with no reviewable changes (1)
  • common/docker/client_image.go
🔇 Additional comments (5)
common/docker/service/evm.go (3)

67-70: Consider using a specific version tag instead of 'latest'

This issue was previously identified. Using the 'latest' tag can lead to non-deterministic deployments and unexpected breaks. Consider using a specific version tag as default and documenting the supported version range.


72-81: ⚠️ Potential issue

Add input validation for platform configuration

  1. The previous review comment about platform validation remains unaddressed.
  2. Additionally, accepting unvalidated input from environment variables poses a security risk. Consider:
    • Sanitizing input to prevent injection attacks
    • Validating against a whitelist of supported OS/ARCH combinations
    • Adding proper error handling for malformed input

67-81: Verify image compatibility and platform support

Let's ensure the changes maintain compatibility across services and platforms.

✅ Verification successful

Platform configuration follows consistent pattern across services

The implementation follows the same pattern used in other services (specifically Nakama):

  • Both EVM and Nakama services use identical platform configuration logic
  • Both allow customization via environment variables (*_IMAGE and *_IMAGE_PLATFORM)
  • The platform configuration is properly integrated into the Service struct
  • The OS/Architecture split logic is consistent across services

The changes maintain compatibility and follow established patterns in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify image compatibility and platform support

# Check if the image exists and supports specified platforms
echo "Checking image availability and platform support..."
rg -g '*.go' -A 5 'ghcr.io/argus-labs/world-engine-evm'

# Check for other services using similar platform configuration
echo "Checking platform configuration patterns..."
rg -g '*.go' 'ocispec.Platform'

# Look for related configuration in other files
echo "Checking related configuration..."
fd -e toml -x cat {} \; | grep -i "EVM_IMAGE\|PLATFORM"

Length of output: 1080


Script:

#!/bin/bash
# Let's analyze the platform configuration usage in more detail

# Check the full context of platform configuration in service files
echo "=== Platform configuration in service files ==="
rg -g '*.go' -B 5 -A 10 'ocispec.Platform'

# Check for any environment variable usage patterns
echo "=== Environment variable patterns ==="
rg -g '*.go' "DockerEnv\[.*PLATFORM"

# Check for any image configuration patterns
echo "=== Image configuration patterns ==="
rg -g '*.go' "DockerEnv\[.*IMAGE"

# Check service configuration structure
echo "=== Service configuration structure ==="
ast-grep --pattern 'type $_ struct {
  $$$
  Platform $$$
  $$$
}'

Length of output: 5249

common/docker/service/nakama.go (2)

57-60: Consider using a specific version tag instead of 'latest'

While the implementation correctly allows image parameterization, using 'latest' as the default tag can lead to non-deterministic deployments. Consider:

  1. Setting a specific version as default
  2. Adding a constant for the default image
+const defaultNakamaImage = "ghcr.io/argus-labs/world-engine-nakama:v1.0.0" // Update version as needed

 func Nakama(cfg *config.Config) Service {
     // ...
-    nakamaImage := "ghcr.io/argus-labs/world-engine-nakama:latest"
+    nakamaImage := defaultNakamaImage
     if cfg.DockerEnv["NAKAMA_IMAGE"] != "" {
         nakamaImage = cfg.DockerEnv["NAKAMA_IMAGE"]
     }

88-88: LGTM: Service configuration updates look good

The changes to use the parameterized image and platform configuration are implemented correctly.

Also applies to: 123-123

common/docker/service/nakama.go Show resolved Hide resolved
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch from 4f9e89d to 0148219 Compare November 13, 2024 20:44
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: 4

🧹 Outside diff range comments (1)
common/docker/service/evm.go (1)

Platform configuration needs to be added for celestia service

The verification revealed inconsistent implementation of platform configuration across services:

  • Both EVM and Nakama services have image parameterization via environment variables
  • Only EVM service has platform configuration support
  • Celestia service uses a ghcr.io image but lacks both image parameterization and platform configuration
🔗 Analysis chain

Line range hint 67-106: Verify consistent implementation across services

Let's verify that the image and platform parameterization is implemented consistently across other services.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent implementation of image and platform parameterization

# Check for image parameterization pattern
echo "Checking image parameterization pattern..."
rg -U 'Image.*=.*ghcr\.io.*latest.*\n.*if.*\["[A-Z_]+_IMAGE"\].*\n.*=.*\n.*}' common/docker/service/

# Check for platform configuration pattern
echo "Checking platform configuration pattern..."
rg -U 'var platform ocispec\.Platform.*\n.*if.*\["[A-Z_]+_IMAGE_PLATFORM"\]' common/docker/service/

Length of output: 1070


Script:

#!/bin/bash
# Let's check if there are other service files that might need similar platform configuration

# First, list all service files
echo "All service files:"
fd "\.go$" common/docker/service/

# Then check for Platform field usage in service structs
echo -e "\nPlatform field usage in Service structs:"
rg -U "Service\s*{\s*(?s:.)*Platform:\s*\w+" common/docker/service/

# Finally check for any other image configurations that might need platform support
echo -e "\nOther image configurations:"
rg "Image.*:.*ghcr\.io" common/docker/service/

Length of output: 1076

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9e89d and 0148219.

📒 Files selected for processing (4)
  • common/docker/client_image.go (0 hunks)
  • common/docker/service/evm.go (3 hunks)
  • common/docker/service/nakama.go (4 hunks)
  • common/editor/editor.go (1 hunks)
💤 Files with no reviewable changes (1)
  • common/docker/client_image.go
🔇 Additional comments (4)
common/docker/service/evm.go (2)

67-70: Consider using a specific version tag instead of 'latest'


86-86: LGTM: Service configuration updates look good

The changes correctly integrate the parameterized image and platform configuration into the service struct.

Also applies to: 106-106

common/docker/service/nakama.go (1)

88-88: LGTM: Service configuration updates are correct

The dynamic image reference and platform configuration are properly integrated into the service struct.

Also applies to: 123-123

common/editor/editor.go (1)

153-156: Verify PR scope: This change seems unrelated to nakama image parameterization.

While this is a good improvement to error handling, it appears unrelated to the PR's stated objective of parameterizing the nakama image. Consider splitting unrelated changes into separate PRs to maintain clear change scope and simplify review.

common/docker/service/evm.go Show resolved Hide resolved
common/docker/service/nakama.go Show resolved Hide resolved
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch from 0148219 to 30ae85f Compare November 14, 2024 07:30
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: 6

🧹 Outside diff range comments (1)
common/docker/service/evm.go (1)

Line range hint 41-65: Consider moving sensitive configuration to a secure store

The code contains hardcoded sensitive values (router keys, mnemonics). Consider:

  1. Moving these to a secure configuration management system
  2. Using environment variables with secure defaults
  3. Adding documentation about secure configuration practices
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 0148219 and 30ae85f.

📒 Files selected for processing (5)
  • cmd/world/root/root_test.go (2 hunks)
  • common/docker/client_image.go (0 hunks)
  • common/docker/service/evm.go (3 hunks)
  • common/docker/service/nakama.go (4 hunks)
  • common/editor/editor.go (1 hunks)
💤 Files with no reviewable changes (1)
  • common/docker/client_image.go
🔇 Additional comments (3)
common/docker/service/evm.go (1)

86-86: LGTM: Service configuration changes look good

The integration of the configurable image and platform settings into the Service struct is clean and aligns well with the PR objectives.

Also applies to: 106-106

common/docker/service/nakama.go (2)

6-6: LGTM: Import addition is appropriate

The strings package import is required for the new platform string parsing functionality.


88-88: LGTM: Service configuration updates are correct

The changes properly integrate the parameterized image and platform configuration into the service struct.

Also applies to: 123-123

common/docker/service/evm.go Show resolved Hide resolved
common/docker/service/nakama.go Show resolved Hide resolved
common/docker/service/nakama.go Show resolved Hide resolved
cmd/world/root/root_test.go Show resolved Hide resolved
cmd/world/root/root_test.go Show resolved Hide resolved
common/editor/editor.go Show resolved Hide resolved
Closes: WORLD-XXX

## Overview

Change nakama image to alway use latest version and can be parameterize through world.toml if user want to use specific version

## Brief Changelog

- Change nakama default image to latest version
- Add `NAKAMA_IMAGE` and `NAKAMA_IMAGE_PLATFORM` on world.toml to use specific version of nakama

## Testing and Verifying

Tested manually using `world cardinal start` command

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Enhanced configurability for the Nakama container image and platform settings via environment variables.
	- Improved configurability for the EVM container image and platform settings based on environment variables.
- **Improvements**
	- Improved logging for container removal during image building.
	- Enhanced error reporting and progress handling when pulling images.
	- Added robust error handling for asset availability in the release download process.
	- Increased retry duration for service status checks, allowing more time for services to become available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@zulkhair zulkhair force-pushed the daim/parameterize_nakama_image branch from 30ae85f to caa3fc3 Compare November 14, 2024 16:49
Copy link

graphite-app bot commented Nov 14, 2024

Merge activity

@graphite-app graphite-app bot merged commit caa3fc3 into main Nov 14, 2024
6 of 7 checks passed
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 30.55556% with 25 lines in your changes missing coverage. Please review.

Project coverage is 46.60%. Comparing base (64feb1f) to head (caa3fc3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
common/docker/service/evm.go 26.66% 9 Missing and 2 partials ⚠️
common/docker/service/nakama.go 38.88% 9 Missing and 2 partials ⚠️
common/editor/editor.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
- Coverage   46.84%   46.60%   -0.25%     
==========================================
  Files          56       56              
  Lines        3546     3575      +29     
==========================================
+ Hits         1661     1666       +5     
- Misses       1675     1694      +19     
- Partials      210      215       +5     

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

Copy link

sentry-io bot commented Nov 15, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ***eris.wrapError: Encountered an error with Cardinal Editor: No assets found in release ** pkg.world.dev/world-cli/cmd/world/cardinal in i... View Issue

Did you find this useful? React with a 👍 or 👎

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