Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
8251fecf9a | |||
07c1a2d8d6 | |||
9f82e689a1 | |||
9cec170f62 | |||
98b9574c67 | |||
7dc24f1456 | |||
faedfc1b0a | |||
a13df3aea4 | |||
d39e559d24 | |||
d4217bb983 | |||
8b44b8a952 |
72
README.md
72
README.md
@ -1,15 +1,65 @@
|
|||||||
# GibCasa GameServerSupervisor
|
# GibCasa GameServerSupervisor
|
||||||
|
|
||||||
# Setup
|
## Table of Contents
|
||||||
|
- [Prerequisites](#prerequisites)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Usage](#usage)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
- [License](#license)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Python 3.10 or above
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone the repository:
|
||||||
|
```bash
|
||||||
|
git clone https://git.com.de/GibCasa/GameServerSupervisor
|
||||||
|
```
|
||||||
|
2. Create a virtual environment in Python:
|
||||||
|
```bash
|
||||||
|
python -m venv venv
|
||||||
|
```
|
||||||
|
3. Activate the virtual environment:
|
||||||
|
```bash
|
||||||
|
source venv/bin/activate
|
||||||
|
```
|
||||||
|
4. Install dependencies:
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
5. Run tests:
|
||||||
|
```bash
|
||||||
|
./manage.py test
|
||||||
|
```
|
||||||
|
6. Run migrations:
|
||||||
|
```bash
|
||||||
|
./manage.py migrate
|
||||||
|
```
|
||||||
|
7. Create admin user:
|
||||||
|
```bash
|
||||||
|
./manage.py createsuperuser
|
||||||
|
```
|
||||||
|
8. Run server:
|
||||||
|
```bash
|
||||||
|
./manage.py runserver
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
* Visit http://localhost:8000 for /public and
|
||||||
|
http://localhost:8000/admin/ to login via the superuser credentials
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
1. Fork the repository.
|
||||||
|
2. Create a new branch: `git checkout -b feature-name`.
|
||||||
|
3. Make your changes.
|
||||||
|
4. Push your branch: `git push origin feature-name`.
|
||||||
|
5. Create a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the [AGPL](https://www.gnu.org/licenses/agpl-3.0.html).
|
||||||
|
|
||||||
* clone the repo
|
|
||||||
* create venv `python3 -m venv venv`
|
|
||||||
* activate `source venv/bin/activate`
|
|
||||||
* `pip install -r requirements.txt`
|
|
||||||
* will need docker running
|
|
||||||
* `python manage.py migrate`
|
|
||||||
* Create admin user: `python manage.py createsuperuser`
|
|
||||||
* `python manage.py runserver`
|
|
||||||
* visit http://localhost:8000 for /public and
|
|
||||||
http://localhost:8000/admin/ to login via the superuser credentials
|
|
@ -16,9 +16,9 @@ def launch_container(modeladmin, request, queryset):
|
|||||||
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
|
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
|
||||||
try:
|
try:
|
||||||
# Ensure the command is passed as a list of strings
|
# Ensure the command is passed as a list of strings
|
||||||
command = server.get_docker_run_command().split() if server.docker_run_command else []
|
command = server.get_podman_run_command().split() if server.run_command else []
|
||||||
container = client.containers.run(
|
container = client.containers.run(
|
||||||
server.docker_image,
|
server.image,
|
||||||
detach=True,
|
detach=True,
|
||||||
name=container_name,
|
name=container_name,
|
||||||
command=command,
|
command=command,
|
||||||
@ -48,7 +48,7 @@ def remove_container(modeladmin, request, queryset):
|
|||||||
|
|
||||||
@admin.register(Server)
|
@admin.register(Server)
|
||||||
class ServerAdmin(admin.ModelAdmin):
|
class ServerAdmin(admin.ModelAdmin):
|
||||||
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'docker_image', 'docker_run_command', 'command_args')
|
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'image', 'run_command', 'command_args')
|
||||||
search_fields = ('game__name', 'ip_address', 'port')
|
search_fields = ('game__name', 'ip_address', 'port')
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
@ -62,6 +62,6 @@ class ServerAdmin(admin.ModelAdmin):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
list_filter = ('status', 'game')
|
list_filter = ('status', 'game')
|
||||||
search_fields = ('ip_address', 'game__name', 'docker_image')
|
search_fields = ('ip_address', 'game__name', 'image')
|
||||||
ordering = ('game', 'ip_address')
|
ordering = ('game', 'ip_address')
|
||||||
actions = [launch_container, stop_container, remove_container]
|
actions = [launch_container, stop_container, remove_container]
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.1.5 on 2025-02-09 17:03
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("webpanel", "0005_server_command_args_server_docker_run_command"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="server",
|
||||||
|
old_name="docker_image",
|
||||||
|
new_name="image",
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="server",
|
||||||
|
old_name="docker_run_command",
|
||||||
|
new_name="run_command",
|
||||||
|
),
|
||||||
|
]
|
@ -18,8 +18,8 @@ class Server(models.Model):
|
|||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
ip_address = models.GenericIPAddressField(null=True)
|
ip_address = models.GenericIPAddressField(null=True)
|
||||||
port = models.PositiveIntegerField(null=True)
|
port = models.PositiveIntegerField(null=True)
|
||||||
docker_image = models.CharField(max_length=200, null=True)
|
image = models.CharField(max_length=200, null=True)
|
||||||
docker_run_command = models.CharField(max_length=500, blank=True, null=True)
|
run_command = models.CharField(max_length=500, blank=True, null=True)
|
||||||
command_args = models.TextField(blank=True, null=True)
|
command_args = models.TextField(blank=True, null=True)
|
||||||
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='offline')
|
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='offline')
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class Server(models.Model):
|
|||||||
return f"{self.game.name} Server at {self.ip_address}:{self.port}"
|
return f"{self.game.name} Server at {self.ip_address}:{self.port}"
|
||||||
|
|
||||||
def sync_status(self):
|
def sync_status(self):
|
||||||
"""Check the real-time status of the Docker container and update the field."""
|
"""Check the real-time status of the container and update the field."""
|
||||||
client = podman.PodmanClient(base_url="unix:///run/user/1000/podman/podman.sock")
|
client = podman.PodmanClient(base_url="unix:///run/user/1000/podman/podman.sock")
|
||||||
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
|
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
|
||||||
try:
|
try:
|
||||||
@ -42,11 +42,11 @@ class Server(models.Model):
|
|||||||
self.status = "offline" # Fallback in case of unexpected errors
|
self.status = "offline" # Fallback in case of unexpected errors
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def get_docker_run_command(self):
|
def get_podman_run_command(self):
|
||||||
"""Returns the Podman run command, falling back to default image if not set."""
|
"""Returns the Podman run command, falling back to default image if not set."""
|
||||||
if self.docker_run_command:
|
if self.run_command:
|
||||||
# Return command as a string to be split later
|
# Return command as a string to be split later
|
||||||
return self.docker_run_command
|
return self.run_command
|
||||||
else:
|
else:
|
||||||
# Default command with image and arguments
|
# Default command with image and arguments
|
||||||
base_command = f"{self.image}"
|
base_command = f"{self.image}"
|
||||||
|
11
webpanel/test_models.py
Normal file
11
webpanel/test_models.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
from webpanel.models import Game
|
||||||
|
|
||||||
|
class GameTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
Game.objects.create(name="Assassin's Creed")
|
||||||
|
|
||||||
|
def test_game_creation(self):
|
||||||
|
assassins = Game.objects.get(name="Assassin's Creed")
|
||||||
|
assert str(assassins) == "Assassin's Creed"
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
Loading…
x
Reference in New Issue
Block a user