Compare commits

...

11 Commits

Author SHA1 Message Date
8251fecf9a Merge pull request 'unit-testing' (#19) from calm-steam/GameServerSupervisor:unit-testing into master
Reviewed-on: #19
Reviewed-by: Pratyush Desai <pratyush.desai@liberta.casa>
2025-02-18 19:07:37 +01:00
07c1a2d8d6
fix readme 2025-02-16 16:06:06 +05:30
9f82e689a1
modify readme 2025-02-16 16:05:58 +05:30
9cec170f62
add webpanel/test_models.py as example 2025-02-16 16:05:47 +05:30
98b9574c67
delete webpanel/tests.py 2025-02-16 16:05:31 +05:30
7dc24f1456
remove docker reference in readme 2025-02-16 16:04:51 +05:30
faedfc1b0a Merge pull request 'Rm references to "docker"' (#16) from cleanup/docker_references into master
Reviewed-on: #16
2025-02-09 18:17:43 +01:00
a13df3aea4
Rm references to "docker"
Closes #13
Required a change in name of two fields in the Server model.

Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
2025-02-09 22:35:24 +05:30
d39e559d24 signed commits (#9) 2025-02-07 01:37:34 +01:00
d4217bb983
substitute python3 for python 2025-02-06 10:25:57 +05:30
8b44b8a952
add prerequisites 2025-02-06 10:25:23 +05:30
6 changed files with 105 additions and 24 deletions

View File

@ -1,15 +1,65 @@
# 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

View File

@ -16,9 +16,9 @@ def launch_container(modeladmin, request, queryset):
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
try:
# 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(
server.docker_image,
server.image,
detach=True,
name=container_name,
command=command,
@ -48,7 +48,7 @@ def remove_container(modeladmin, request, queryset):
@admin.register(Server)
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')
def save_model(self, request, obj, form, change):
@ -62,6 +62,6 @@ class ServerAdmin(admin.ModelAdmin):
return queryset
list_filter = ('status', 'game')
search_fields = ('ip_address', 'game__name', 'docker_image')
search_fields = ('ip_address', 'game__name', 'image')
ordering = ('game', 'ip_address')
actions = [launch_container, stop_container, remove_container]

View File

@ -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",
),
]

View File

@ -18,8 +18,8 @@ class Server(models.Model):
name = models.CharField(max_length=100)
ip_address = models.GenericIPAddressField(null=True)
port = models.PositiveIntegerField(null=True)
docker_image = models.CharField(max_length=200, null=True)
docker_run_command = models.CharField(max_length=500, blank=True, null=True)
image = models.CharField(max_length=200, null=True)
run_command = models.CharField(max_length=500, blank=True, null=True)
command_args = models.TextField(blank=True, null=True)
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}"
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")
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
try:
@ -42,11 +42,11 @@ class Server(models.Model):
self.status = "offline" # Fallback in case of unexpected errors
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."""
if self.docker_run_command:
if self.run_command:
# Return command as a string to be split later
return self.docker_run_command
return self.run_command
else:
# Default command with image and arguments
base_command = f"{self.image}"

11
webpanel/test_models.py Normal file
View 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"

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.