heroiclabs / nakama

Distributed server for social and realtime games and apps.
https://heroiclabs.com
Apache License 2.0
9.03k stars 1.1k forks source link

plugin was built with a different version of package github.com/heroiclabs/nakama-common/api #1256

Closed rnikrozoft closed 3 months ago

rnikrozoft commented 3 months ago

I tried running nakama version 3.22 using docker following this example go-runtime but it gave me a problem plugin was built with a different version of package github.com/heroiclabs/nakama-common/api

Here is my code go.mod:

module example.com/go-project

go 1.21.2

require (
    github.com/heroiclabs/nakama-common v1.33.0 // indirect
    google.golang.org/protobuf v1.34.1 // indirect
)

go.sum:

github.com/heroiclabs/nakama-common v1.33.0 h1:ojGPgVZ/goyAH6jrm3Emg7034yGDdqB/f5vTa6AJ5n0=
github.com/heroiclabs/nakama-common v1.33.0/go.mod h1:lPG64MVCs0/tEkh311Cd6oHX9NLx2vAPx7WW7QCJHQ0=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=

Dockerfile:

FROM heroiclabs/nakama-pluginbuilder:3.22.0 AS builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /backend
COPY . .
RUN go build --trimpath --buildmode=plugin -o ./backend.so
FROM heroiclabs/nakama:3.22.0
COPY --from=builder /backend/backend.so /nakama/data/modules
COPY --from=builder /backend/local.yml /nakama/data/
COPY --from=builder /backend/*.json /nakama/data/modules

docker-compose.yml:

version: '3'
services:
  postgres:
    command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    expose:
      - "8080"
      - "5432"
    image: postgres:12.2-alpine
    ports:
      - "5432:5432"
      - "8080:8080"
    volumes:
      - data:/var/lib/postgresql/data

  nakama:
    build: .
    depends_on:
      - postgres
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
        exec /nakama/nakama --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama        
    expose:
      - "7349"
      - "7350"
      - "7351"
    healthcheck:
      test: ["CMD", "/nakama/nakama", "healthcheck"]
      interval: 10s
      timeout: 5s
      retries: 5
    links:
      - "postgres:db"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    restart: unless-stopped

volumes:
  data:

main.go:

package main
import (
    "context"
    "database/sql"

    "github.com/heroiclabs/nakama-common/runtime"
)

func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
    logger.Info("Hello World!")
    return nil
}

log in container:

nakama-1    | {"level":"fatal","ts":"2024-07-30T19:23:24.704Z","caller":"main.go:191","msg":"Failed initializing runtime modules","error":"plugin.Open(\"/nakama/data/modules/backend\"): plugin was built with a different version of package github.com/heroiclabs/nakama-common/api"}        
nakama-1 exited with code 1

issue

linear[bot] commented 3 months ago

NK-587 plugin was built with a different version of package github.com/heroiclabs/nakama-common/api

toqueteos commented 3 months ago

Since you are using Nakama v3.22.0 I think you should be using nakama-common v1.32.0

You should pin the version as there's a newer Nakama version in the wild and go get wild detect that one.

Add this to the end of your go.mod:

replace github.com/heroiclabs/nakama-common => github.com/heroiclabs/nakama-common v1.32.0

EDIT: This is mentioned in the docs. image

zyro commented 3 months ago

@rnikrozoft I believe @toqueteos is correct, the error is accurate and indicates you have a version mismatch. You may also find our documentation on Go runtime dependencies and pinning useful.

toqueteos commented 3 months ago

@zyro Shouldn't 3.23.0 be in that table anyways? Can that be contributed or are the docs staff only now?