From 4f9e89dfd2acdd34f88e09640add42fe7d27040f Mon Sep 17 00:00:00 2001 From: Zulkhair Abdullah Daim Date: Thu, 14 Nov 2024 01:40:40 +0700 Subject: [PATCH] feat: parameterize nakama image --- common/docker/client_image.go | 1 - common/docker/service/evm.go | 21 ++++++++++++++++++++- common/docker/service/nakama.go | 27 ++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/common/docker/client_image.go b/common/docker/client_image.go index b8b5f7e..684eb7c 100644 --- a/common/docker/client_image.go +++ b/common/docker/client_image.go @@ -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(), diff --git a/common/docker/service/evm.go b/common/docker/service/evm.go index a22016f..bae828e 100644 --- a/common/docker/service/evm.go +++ b/common/docker/service/evm.go @@ -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" ) @@ -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"]), @@ -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, } } diff --git a/common/docker/service/nakama.go b/common/docker/service/nakama.go index 3fb60c4..c6f646d 100644 --- a/common/docker/service/nakama.go +++ b/common/docker/service/nakama.go @@ -3,6 +3,7 @@ package service import ( "fmt" "strconv" + "strings" "time" "github.com/docker/docker/api/types/container" @@ -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 @@ -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)), @@ -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, } }