https://github.com/st-matskevich/go-matchmaker
Orchestrator written in Go
https://github.com/st-matskevich/go-matchmaker
containers docker go golang matchmaking orchestration
Last synced: 4 months ago
JSON representation
Orchestrator written in Go
- Host: GitHub
- URL: https://github.com/st-matskevich/go-matchmaker
- Owner: st-matskevich
- License: mit
- Created: 2023-01-21T22:33:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T15:13:54.000Z (about 2 years ago)
- Last Synced: 2024-06-20T06:27:26.245Z (almost 2 years ago)
- Topics: containers, docker, go, golang, matchmaking, orchestration
- Language: Go
- Homepage:
- Size: 107 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-Matchmaker
[](https://raw.githack.com/wiki/st-matskevich/go-matchmaker/coverage.html)
[](https://goreportcard.com/report/github.com/st-matskevich/go-matchmaker)
[](LICENSE)
Microservices based orchestrator for your containers written in Go. Can be used to orchestrate game servers or virtual machines.
## Installation
1. Install [Docker](https://docs.docker.com/get-docker/)
2. Check variables in [docker-compose.yml](docker-compose.yml)
```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
```
3. Setup secrets and additional environment variables(or create .env file)
```properties
# 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
```
4. If "swarm" backend is used, [setup Swarm cluster](https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/)
5. Create Docker network that was defined as `DOCKER_NETWORK` in [docker-compose.yml](docker-compose.yml). Use "overlay" driver for "swarm" backend and "bridge" driver for "docker" backend
```sh
# Docker backend
docker network create -d bridge dev-network
# Swarm backend
docker network create -d overlay dev-network
```
6. Run docker compose from root directory
```sh
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](https://github.com/st-matskevich/go-dummyserver) as example or image for testing. Available as [image](https://hub.docker.com/r/stmatskevich/go-dummyserver) 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](api/auth/auth.go) interface. Then pass your type to auth.New() middleware in [api/main.go](api/main.go).
You can use [DummyAuthorizer](api/auth/auth.go) as example.
## Usage
To request server send POST /request request with authorization token:
```sh
curl -X POST http://localhost:3000/request -H "Authorization: 5jg86j39jdf04"
```
To view services logs use:
```sh
# API service
docker compose logs api -f
# Maker service
docker compose logs maker -f
```
## Documentation
See [DOCUMENTATION](DOCUMENTATION.md) for more information.
## Built with
- [Go](https://go.dev/)
- [Docker](https://www.docker.com/)
- [Redis](https://github.com/redis/redis)
- [Moby Project](https://github.com/moby/moby)
- [Fiber](https://github.com/gofiber/fiber)
- [go-redis](https://github.com/redis/go-redis)
- [testify](https://github.com/stretchr/testify)
- [godotenv](https://github.com/joho/godotenv)
## License
Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
## Contributing
Want a new feature added? Found a bug?
Go ahead an open [a new issue](https://github.com/st-matskevich/go-matchmaker/issues/new) or feel free to submit a pull request.