service

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCardinalDebugPort is the Cardinal debug server port.
	DefaultCardinalDebugPort = 8080
	// DefaultCardinalDebugHostPort is the host port for Cardinal debug.
	DefaultCardinalDebugHostPort = 8081

	// DBDSNEnvVar is the uniform env var carrying the shared project database DSN
	// to every shard and every db = true service.
	DBDSNEnvVar = "DB_DSN"
)
View Source
const (
	// DefaultNetworkMode is the docker network shared by all services.
	DefaultNetworkMode = "world-engine-network"

	// CardinalNamespaceLabel labels Cardinal shard containers/images by namespace.
	CardinalNamespaceLabel = "com.world.cardinal.namespace"

	// GameServiceLabel labels [[services]] containers by project.
	GameServiceLabel = "com.world.service.project"

	// BaseImage is the distroless runtime base for built-from-source images.
	BaseImage = "gcr.io/distroless/base-debian12"

	// GoBuilderImage is the Go toolchain build stage shared by Cardinal shards and
	// built-from-source game services. Keep the Go version in sync with .prototools
	// (go = "...").
	GoBuilderImage = "golang:1.27.1-bookworm"
)

Common string values used across service configurations.

View Source
const (
	// DefaultNatsClientPort is the default NATS client port.
	DefaultNatsClientPort = 4222
	// DefaultNatsMonitorPort is the default NATS monitoring port.
	DefaultNatsMonitorPort = 8222
	// DefaultNatsClusterPort is the default NATS cluster port.
	DefaultNatsClusterPort = 6222
	// DefaultNatsWebsocketPort is the default NATS websocket port.
	DefaultNatsWebsocketPort = 4443

	// DefaultNatsImage is the default Docker image for the NATS service.
	DefaultNatsImage = "nats:"

	// DefaultNatsContainerName is the default container name for the NATS service.
	DefaultNatsContainerName = "world-engine-nats"
)

Variables

This section is empty.

Functions

func CardinalShardContainerName

func CardinalShardContainerName(namespace, instanceID string) string

CardinalShardContainerName returns the per-instance container name for a Cardinal shard (e.g. "game-2").

func CardinalShardImageName

func CardinalShardImageName(namespace, shardID string) string

CardinalShardImageName returns the image tag shared by a Cardinal shard pool, keyed by the world.toml shard ID.

func GameServiceContainerName

func GameServiceContainerName(project, id string) string

GameServiceContainerName returns the container name for a [[services]] entry. Keyed off the world.toml project (not the directory-derived namespace) so hostname-referencing env values (e.g. a postgres DSN) stay deterministic across checkout directories.

func NeedsAutoProjectDB

func NeedsAutoProjectDB(worldToml worldtoml.Config) bool

NeedsAutoProjectDB reports whether the docker backend must auto-provision the shared "{project}-db" Postgres: some service set db = true and no config_db service was declared to satisfy it.

func ProjectDBContainerName

func ProjectDBContainerName(project string) string

ProjectDBContainerName returns a project's shared database container/host name ("{project}-db"). One database per project, reached via DB_DSN.

Types

type Builder

type Builder func(cfg *Config) Service

func BuildCardinalShards

func BuildCardinalShards(cfg *Config) []Builder

func BuildGameServices

func BuildGameServices(cfg *Config) []Builder

BuildGameServices returns one builder per [[services]] entry in declaration order (which drives start order). When a service sets db = true and no config_db service satisfies it, the auto-provisioned "{project}-db" Postgres is prepended so it goes healthy first; it rides here (not just the start path) so stop/purge tear it down with the project.

func GetServices

func GetServices(cfg *Config, order ServiceOrder) []Builder

GetServices returns Cardinal shard builders plus game services and NATS. Game services keep their world.toml declaration order (it drives start order); the auto-provisioned project database (when db = true is used) rides in from BuildGameServices, prepended so it comes up first.

type Config

type Config struct {
	RootDir   string
	Namespace string
	NATSURL   string
	Debug     bool
	Timeout   int
	WorldToml worldtoml.Config
}

type Service

type Service struct {
	container.Config
	container.HostConfig
	network.NetworkingConfig
	ocispec.Platform

	Name string
	// Dependencies are other services that need to be pull before this service
	Dependencies []Service
	// Dockerfile is the content of the Dockerfile
	Dockerfile string
	// BuildTarget is the target build of the Dockerfile e.g. builder or runtime
	BuildTarget string
	// BuildArgs are ARGs passed to the Docker build (e.g., SOURCE_PATH)
	BuildArgs map[string]string
}

Service represents a Docker service configuration. It contains the name of the container and a function to get the container and host config.

func CardinalFromShard

func CardinalFromShard(cfg *Config, shard worldtoml.Shard, hostPort int) Service

func GameServiceFromConfig

func GameServiceFromConfig(cfg *Config, svc worldtoml.GameService) Service

GameServiceFromConfig builds the docker service for one [[services]] entry. Image-kind entries run a pulled image; path-kind entries ride the Cardinal shard build pipeline and carry the namespace label so they build/prune like shard images.

func NATS

func NATS(_ *Config) Service

NATS creates a NATS service with JetStream support.

func ProjectDBService

func ProjectDBService(cfg *Config) Service

ProjectDBService builds the auto-provisioned shared project database: a single "{project}-db" Postgres reached via DB_DSN, initialized with world-cli's default credentials and a project-named database (matching projectDBDSN). It carries the game-service label (so start/stop/purge bucket it like any service), a healthcheck (so dependents wait), and a volume name == container name (so purge cleans it up). Only added when NeedsAutoProjectDB(worldToml) is true.

Known limitation: it binds host port 5432, so only one db = true project can run on a host at a time, and it clashes with a local Postgres already on 5432.

type ServiceOrder

type ServiceOrder int

ServiceOrder controls how shared service builders are ordered for consumers.

const (
	// CardinalShardsFirst lists shard services first, then game services and NATS.
	CardinalShardsFirst ServiceOrder = iota
	// InfrastructureFirst lists NATS first, then game services and shard services.
	InfrastructureFirst
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL