heroiclabs / nakama-project-template

An example project on how to set up and write custom server code in Nakama server.
https://github.com/heroiclabs/nakama
Apache License 2.0
109 stars 42 forks source link

Getting segmentation fault while trying to build docker container #23

Closed navaneethkwalee closed 1 week ago

navaneethkwalee commented 1 month ago

go.mod

module github.com/heroiclabs/nakama-project-template

go 1.20

require (
    github.com/heroiclabs/nakama-common v1.27.0
    google.golang.org/protobuf v1.28.1
)

main.go

package main

import (
    "context"
    "database/sql"
    "time"

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

func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
    initStart := time.Now()

    logger.Info("Module loaded in %dms", time.Since(initStart).Microseconds())

    return nil
}

Dockerfile

FROM heroiclabs/nakama-pluginbuilder:3.16.0 AS builder

ENV GO111MODULE on
ENV CGO_ENABLED 1
# ENV GOPRIVATE "github.com/heroiclabs/nakama-project-template"

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/*.lua /nakama/data/modules/
COPY --from=builder /backend/build/*.js /nakama/data/modules/build/
COPY --from=builder /backend/local.yml /nakama/data/

docker-compose.yml

version: '3'
services:
  postgres:
    command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
    container_name: template_nk_postgres
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    expose:
      - "8080"
      - "5432"
    image: postgres:12.2-alpine
    ports:
      - "5432:5432"
      - "8080:8080"
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres", "-d", "nakama"]
      interval: 3s
      timeout: 3s
      retries: 5
    volumes:
      - data:/var/lib/postgresql/data

  tf:
    image: tensorflow/serving
    container_name: template_tf
    environment:
      - MODEL_NAME=ttt
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8501/"]
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - "8501"
    volumes:
      - ./model:/models/ttt
    restart: unless-stopped

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

volumes:
  data:

```shell
(base) navaneethsuresh@Navaneeths-MacBook-Pro heroic-experiments % docker-compose up --build nakama
[+] Building 7.0s (12/16)                                                                            
 => [nakama internal] load build definition from Dockerfile                                     0.0s
 => => transferring dockerfile: 566B                                                            0.0s
 => [nakama internal] load .dockerignore                                                        0.0s
 => => transferring context: 2B                                                                 0.0s
 => [nakama internal] load metadata for docker.io/heroiclabs/nakama:3.16.0                      1.8s
 => [nakama internal] load metadata for docker.io/heroiclabs/nakama-pluginbuilder:3.16.0        1.8s
 => [nakama auth] heroiclabs/nakama:pull token for registry-1.docker.io                         0.0s
 => [nakama auth] heroiclabs/nakama-pluginbuilder:pull token for registry-1.docker.io           0.0s
 => [nakama builder 1/4] FROM docker.io/heroiclabs/nakama-pluginbuilder:3.16.0@sha256:8ae6fe22  0.0s
 => CACHED [nakama builder 2/4] WORKDIR /backend                                                0.0s
 => [nakama internal] load build context                                                        0.0s
 => => transferring context: 14.44kB                                                            0.0s
 => [nakama stage-1 1/5] FROM docker.io/heroiclabs/nakama:3.16.0@sha256:4d03f7d16eea0c6f395ceb  0.0s
 => [nakama builder 3/4] COPY . .                                                               0.0s
 => ERROR [nakama builder 4/4] RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./ba  5.1s
------                                                                                               
 > [nakama builder 4/4] RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so:     
0.725 internal/goarch: /usr/local/go/pkg/tool/linux_amd64/compile: signal: segmentation fault (core dumped)
------
failed to solve: process "/bin/sh -c go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so" did not complete successfully: exit code: 1
(base) navaneethsuresh@Navaneeths-MacBook-Pro heroic-experiments % docker-compose down -v          
[+] Running 1/0
 ✔ Volume heroic-experiments_data  Removed                                                      0.0s 
(base) navaneethsuresh@Navaneeths-MacBook-Pro heroic-experiments % docker-compose up --build nakama
[+] Building 6.8s (10/14)                                                                            
 => [nakama internal] load build definition from Dockerfile                                     0.0s
 => => transferring dockerfile: 566B                                                            0.0s
 => [nakama internal] load .dockerignore                                                        0.0s
 => => transferring context: 2B                                                                 0.0s
 => [nakama internal] load metadata for docker.io/heroiclabs/nakama:3.16.0                      0.9s
 => [nakama internal] load metadata for docker.io/heroiclabs/nakama-pluginbuilder:3.16.0        1.2s
 => [nakama stage-1 1/5] FROM docker.io/heroiclabs/nakama:3.16.0@sha256:4d03f7d16eea0c6f395ceb  0.0s
 => [nakama internal] load build context                                                        0.0s
 => => transferring context: 15.41kB                                                            0.0s
 => [nakama builder 1/4] FROM docker.io/heroiclabs/nakama-pluginbuilder:3.16.0@sha256:8ae6fe22  0.0s
 => CACHED [nakama builder 2/4] WORKDIR /backend                                                0.0s
 => [nakama builder 3/4] COPY . .                                                               0.0s
 => ERROR [nakama builder 4/4] RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./ba  5.5s
------                                                                                               
 > [nakama builder 4/4] RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so:     
2.216 runtime/internal/math: /usr/local/go/pkg/tool/linux_amd64/compile: signal: segmentation fault (core dumped)
------
failed to solve: process "/bin/sh -c go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so" did not complete successfully: exit code: 1
zyro commented 1 month ago

@navaneethkwalee I've just tried to build the current commit on master of this repo (50d84d8f11f7ac201f8dbcae37bc8557ae08f260) and ran docker compose up --build nakama as the README.md file indicates. This completes fine and everything starts up correctly.

Did you make any changes to what is on master of this repo?

(Side note, we've just updated the template for the latest Nakama 3.23.0 release as of commit 9a3cf022d4383b5a9a870b3bd66f05aef6336b8b).

navaneethkwalee commented 1 month ago

Interesting! @zyro I've cloned the repo and tried in both of the commits that you've suggested, still getting the same error.

zyro commented 1 month ago

Very strange, can you share a bit about your environment? OS version, docker version, anything you can think of that might be useful.

Until then, do you have another machine you can try the build on? Maybe it's an environment issue. 🤔

navaneethkwalee commented 1 month ago

OS: Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64 Docker: Docker version 24.0.3, build 3713ee1eea

I'll see if I can find another machine to test

navaneethkwalee commented 1 month ago

I tried to build https://github.com/heroiclabs/kwalee-submarinejump-server and it's working fine surprisingly.

zyro commented 1 week ago

@navaneethkwalee It has been a while with no new info, for the moment I will assume this is no longer a blocker but please feel free to re-open if needed. 👍