Skip to content

Commit

Permalink
feat: parameterize nakama image (#84)
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
zulkhair committed Nov 14, 2024
1 parent 64feb1f commit caa3fc3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func evmIsDown(t *testing.T) bool {

func ServiceIsUp(name, address string, t *testing.T) bool {
up := false
for i := 0; i < 60; i++ {
for i := 0; i < 120; i++ {
conn, err := net.DialTimeout("tcp", address, time.Second)
if err != nil {
time.Sleep(time.Second)
Expand All @@ -255,7 +255,7 @@ func ServiceIsUp(name, address string, t *testing.T) bool {

func ServiceIsDown(name, address string, t *testing.T) bool {
down := false
for i := 0; i < 60; i++ {
for i := 0; i < 120; i++ {
conn, err := net.DialTimeout("tcp", address, time.Second)
if err != nil {
down = true
Expand Down
1 change: 0 additions & 1 deletion common/docker/client_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (c *Client) buildImages(ctx context.Context, dockerServices ...service.Serv

// Remove the container
err := c.removeContainer(ctx, dockerService.Name)
fmt.Printf("Removing container %s\n", dockerService.Image)
if err != nil {
p.Send(multispinner.ProcessState{
Icon: style.CrossIcon.Render(),
Expand Down
21 changes: 20 additions & 1 deletion common/docker/service/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package service

import (
"fmt"
"strings"

"github.com/docker/docker/api/types/container"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"pkg.world.dev/world-cli/common/config"
)
Expand Down Expand Up @@ -62,10 +64,26 @@ func EVM(cfg *config.Config) Service {
"thank slam unknown fury script among bread social switch glide wool clog flag enroll"
}

evmImage := "ghcr.io/argus-labs/world-engine-evm:latest"
if cfg.DockerEnv["EVM_IMAGE"] != "" {
evmImage = cfg.DockerEnv["EVM_IMAGE"]
}

var platform ocispec.Platform
if cfg.DockerEnv["EVM_IMAGE_PLATFORM"] != "" {
evmImagePlatform := strings.Split(cfg.DockerEnv["EVM_IMAGE_PLATFORM"], "/")
if len(evmImagePlatform) == 2 { //nolint:gomnd //2 is the expected length
platform = ocispec.Platform{
Architecture: evmImagePlatform[1],
OS: evmImagePlatform[0],
}
}
}

return Service{
Name: getEVMContainerName(cfg),
Config: container.Config{
Image: "ghcr.io/argus-labs/world-engine-evm:1.4.1",
Image: evmImage,
Env: []string{
fmt.Sprintf("DA_BASE_URL=%s", daBaseURL),
fmt.Sprintf("DA_AUTH_TOKEN=%s", cfg.DockerEnv["DA_AUTH_TOKEN"]),
Expand All @@ -85,5 +103,6 @@ func EVM(cfg *config.Config) Service {
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
NetworkMode: container.NetworkMode(cfg.DockerEnv["CARDINAL_NAMESPACE"]),
},
Platform: platform,
}
}
27 changes: 22 additions & 5 deletions common/docker/service/nakama.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"fmt"
"strconv"
"strings"
"time"

"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -53,6 +54,25 @@ func Nakama(cfg *config.Config) Service {
}
}

nakamaImage := "ghcr.io/argus-labs/world-engine-nakama:latest"
if cfg.DockerEnv["NAKAMA_IMAGE"] != "" {
nakamaImage = cfg.DockerEnv["NAKAMA_IMAGE"]
}

platform := ocispec.Platform{
Architecture: "amd64",
OS: "linux",
}
if cfg.DockerEnv["NAKAMA_IMAGE_PLATFORM"] != "" {
nakamaImagePlatform := strings.Split(cfg.DockerEnv["NAKAMA_IMAGE_PLATFORM"], "/")
if len(nakamaImagePlatform) == 2 { //nolint:gomnd //2 is the expected length
platform = ocispec.Platform{
Architecture: nakamaImagePlatform[1],
OS: nakamaImagePlatform[0],
}
}
}

// prometheus metrics export is disabled if port is 0
// src: https://heroiclabs.com/docs/nakama/getting-started/configuration/#metrics
prometheusPort := 0
Expand All @@ -65,7 +85,7 @@ func Nakama(cfg *config.Config) Service {
return Service{
Name: getNakamaContainerName(cfg),
Config: container.Config{
Image: "ghcr.io/argus-labs/world-engine-nakama:1.2.9",
Image: nakamaImage,
Env: []string{
fmt.Sprintf("CARDINAL_CONTAINER=%s", getCardinalContainerName(cfg)),
fmt.Sprintf("CARDINAL_ADDR=%s:4040", getCardinalContainerName(cfg)),
Expand Down Expand Up @@ -100,9 +120,6 @@ func Nakama(cfg *config.Config) Service {
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
NetworkMode: container.NetworkMode(cfg.DockerEnv["CARDINAL_NAMESPACE"]),
},
Platform: ocispec.Platform{
Architecture: "amd64",
OS: "linux",
},
Platform: platform,
}
}
4 changes: 4 additions & 0 deletions common/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func downloadReleaseIfNotCached(downloadURL, configDir string) (string, string,
editorDir := filepath.Join(configDir, "editor")

targetDir := filepath.Join(editorDir, release.Name)
if release.Assets == nil || (release.Assets != nil && len(release.Assets) == 0) {
return targetDir, release.Name, eris.New(fmt.Sprintf("No assets found in release %s", release.Name))
}

if _, err = os.Stat(targetDir); os.IsNotExist(err) {
return targetDir, release.Name, downloadAndUnzip(release.Assets[0].BrowserDownloadURL, targetDir)
}
Expand Down

0 comments on commit caa3fc3

Please # to comment.