I’m new to Docker and Nakama as a whole, so I do apologize if the answers to my questions are quite obvious.
That being said, I am trying to add Go Modules to my Nakama setup.
I have tried the following solution (nakama-project-template), however it uses Postgres and I am going for CockroachDB.
I have tried combining my current config which comes directly from the getting started docker compose section, however it doesn’t work and none of my modules load.
When I start the docker container everything runs fine, however no module is added.
I am running Docker on Windows (if that’s relevant?).
- Versions: Nakama latest and Docker latest
- Server Framework Runtime language: Go
Dockerfile:
FROM heroiclabs/nakama-pluginbuilder:3.16.0 AS builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /backend
COPY . .
RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so
FROM heroiclabs/nakama:3.16.0
COPY --from=builder /backend/backend.so /nakama/data/modules
COPY --from=builder /backend/local.yml /nakama/data/
docker-compose.yml
version: '3'
services:
cockroachdb:
image: cockroachdb/cockroach:latest-v23.1
command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/
restart: "no"
volumes:
- data:/var/lib/cockroach
expose:
- "8080"
- "26257"
ports:
- "26257:26257"
- "8080:8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
interval: 3s
timeout: 3s
retries: 5
nakama:
image: registry.heroiclabs.com/heroiclabs/nakama:3.20.0
entrypoint:
- "/bin/sh"
- "-ecx"
- >
/nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100
restart: "no"
links:
- "cockroachdb:db"
depends_on:
cockroachdb:
condition: service_healthy
prometheus:
condition: service_started
#volumes:
# - ./:/nakama/data
expose:
- "7349"
- "7350"
- "7351"
- "9100"
ports:
- "7349:7349"
- "7350:7350"
- "7351:7351"
healthcheck:
test: ["CMD", "/nakama/nakama", "healthcheck"]
interval: 10s
timeout: 5s
retries: 5
prometheus:
image: prom/prometheus
entrypoint: /bin/sh -c
command: |
'sh -s <<EOF
cat > ./prometheus.yml <<EON
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: nakama
metrics_path: /
static_configs:
- targets: ['nakama:9100']
EON
prometheus --config.file=./prometheus.yml
EOF'
ports:
- '9090:9090'
volumes:
data:
local.yml
name: nakama-1
data_dir: "./data/"
logger:
stdout: false
level: DEBUG
file: "/nakama/data/logfile.log"
console:
port: 7351
username: "admin"
password: "password"
session:
token_expiry_sec: 7200
metrics:
prometheus_port: 9100
main.go
package main
import (
"context"
"database/sql"
"time"
"github.com/heroiclabs/nakama-common/runtime"
)
const (
OK = 0
CANCELED = 1
UNKNOWN = 2
INVALID_ARGUMENT = 3
DEADLINE_EXCEEDED = 4
NOT_FOUND = 5
ALREADY_EXISTS = 6
PERMISSION_DENIED = 7
RESOURCE_EXHAUSTED = 8
FAILED_PRECONDITION = 9
ABORTED = 10
OUT_OF_RANGE = 11
UNIMPLEMENTED = 12
INTERNAL = 13
UNAVAILABLE = 14
DATA_LOSS = 15
UNAUTHENTICATED = 16
)
var (
errBadInput = runtime.NewError("input contained invalid data", INVALID_ARGUMENT)
errInternalError = runtime.NewError("internal server error", INTERNAL)
errGuildAlreadyExists = runtime.NewError("guild name is in use", ALREADY_EXISTS)
errFullGuild = runtime.NewError("guild is full", RESOURCE_EXHAUSTED)
errNotAllowed = runtime.NewError("operation not allowed", PERMISSION_DENIED)
errNoGuildFound = runtime.NewError("guild not found", NOT_FOUND)
)
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
initStart := time.Now()
if err := initializer.RegisterRpc("healthcheck", RpcHealthCheck); err != nil {
return err
}
logger.Info("Plugin loaded in '%d' msec.", time.Now().Sub(initStart).Milliseconds())
return nil
}
healthcheck.go
package main
import (
"context"
"database/sql"
"encoding/json"
"github.com/heroiclabs/nakama-common/runtime"
)
type HealthCheckResponse struct {
Success bool `json: "success"`
}
func RpcHealthCheck(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
logger.Debug("HealthCheck RPC called.")
response := &HealthCheckResponse{Success: true}
out, err := json.Marshal(response)
if err != nil {
logger.Error("Error marshalling repsonse type to JSON: %v", err)
return "", runtime.NewError("Cannon marshal type", 13)
}
return string(out), nil
}
Media: