Skip to content

st-matskevich/go-matchmaker

Repository files navigation

Go-Matchmaker

Coverage Go Report License

Microservices based orchestrator for your containers written in Go. Can be used to orchestrate game servers or virtual machines.

Installation

  1. Install Docker
  2. Check variables in docker-compose.yml
# API service
# How long service will wait for Reservation API confirmation from created server in ms
RESERVATION_TIMEOUT: 5000

# Maker service
# Type of backend used for containerization, available options:
# "docker" - use Docker on local machine to orchestrate containers
# "swarm" - use Docker Swarm cluster to orchestrate containers
CONTAINER_BACKEND: swarm
# How long service will wait for Reservation API confirmation from created server in ms
RESERVATION_TIMEOUT: 5000
# If retrying reservation, how long thread should sleep between requests
RESERVATION_COOLDOWN: 2000
# If retrying reservation, how many tries thread can do
RESERVATION_RETRY_TIMES: 3
# How long thread should wait between swarm service converge verification requests
CONVERGE_VERIFY_COOLDOWN: 1000
# How many tries thread can do to verify swarm service convergence
CONVERGE_VERIFY_RETRY_TIMES: 10
# How many threads should be created for requsets processing
MAX_CONCURRENT_JOBS: 3
# Docker network that will be used for starting new containers
DOCKER_NETWORK: dev-network
# How long thread should wait between looking for available containers
LOOKUP_COOLDOWN: 1000

# Network for compose is not created automaticaly
# go-matchmaker containers and your servers should run on same network to be able to interact with each other
# Change dev-network to your network if you wish
# It should be equal to DOCKER_NETWORK variable
networks:
  dev-network:
    name: dev-network
  1. Setup secrets and additional environment variables(or create .env file)
# Image to use as server container
IMAGE_TO_PULL=docker.io/stmatskevich/go-dummyserver
# Image port that should be exposed, protocol can be also specified, tcp is used if nothing added
IMAGE_EXPOSE_PORT=3000/tcp
# Image port that provide Reservation API
IMAGE_CONTROL_PORT=3000
# Image registry username, if authorization not needed leave blank
IMAGE_REGISTRY_USERNAME=stmatskevich
# Image registry password, if authorization not needed leave blank
IMAGE_REGISTRY_PASSWORD=supersecretpassword
  1. If "swarm" backend is used, setup Swarm cluster
  2. Create Docker network that was defined as DOCKER_NETWORK in docker-compose.yml. Use "overlay" driver for "swarm" backend and "bridge" driver for "docker" backend
# Docker backend
docker network create -d bridge dev-network  

# Swarm backend
docker network create -d overlay dev-network  
  1. Run docker compose from root directory
docker compose up --build -d

Optional

  • Use proc/sys/net/ipv4/ip_local_port_range to limit number of ports that will be used for exposing

Reservation API

To use your own image with go-matchmaker, it should serve Reservation API on IMAGE_CONTROL_PORT port.

Reservation API Endpoints

POST /reservation/{client-id}

Used from Maker service to reserve slot for client with client-id id.

Respond with 200 if slot was successfully reserved, 403 otherwise.

GET /reservation/{client-id}

Used from API service to verify reservation for client with client-id id.

Respond with 200 if there is a slot reserved for specified client, 404 otherwise.

You can use go-dummyserver as example or image for testing. Available as image on Docker Hub.

Clients authentication

No special authentication included by default, but all interfaces are already here for you.

To use authentication you need to implement your own type with Authorize method form Authorizer interface. Then pass your type to auth.New() middleware in api/main.go.

You can use DummyAuthorizer as example.

Usage

To request server send POST /request request with authorization token:

curl -X POST http://localhost:3000/request -H "Authorization: 5jg86j39jdf04"

To view services logs use:

# API service
docker compose logs api -f

# Maker service
docker compose logs maker -f

Documentation

See DOCUMENTATION for more information.

Built with

License

Distributed under the MIT License. See LICENSE for more information.

Contributing

Want a new feature added? Found a bug? Go ahead an open a new issue or feel free to submit a pull request.