Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement build number manager (Django) #2

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# backend-services

Scripts used to power the Mumble public infrastructure backend (e.g. public server list)


## Development

Enter the Django project folder ``mumble_backend``. Call ``source setup``
to create a new venv which automatically installs Django and activates it.

Create the database tables with:
```
python manage.py migrate
```

Start the development server with:
```
python manage.py runserver
```

Run tests with:
```
python manage.py test
```

Create an admin account for the admin interface with:
```
python manage.py createsuperuser
```

Auto format code with:
```
black .
```

## Production

TBD
46 changes: 46 additions & 0 deletions mumble_backend/build_number_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### Build Number Manager

#### API v1:

Endpoint: ``/build-number/v1/<series>/<commit>?token=<token>``
| HTTP <br> Method| Parameters | Response |
| :-----: | ----- | ---- |
| ``POST`` | ``<series>``: The Mumble series e.g. ``1.4`` <br> ``<commit>``: The commit hash <br> ``<token>``: An authorized password | ``201``: New build number created <br> ``400``: Invalid parameters <br> ``401``: Unauthorized token <br> ``409``: Commit already exists in series <br> ``422``: New build number exceeds 2 bytes |
| ``GET`` | ``<series>``: The Mumble series e.g. ``1.4`` <br> ``<commit>``: The commit hash <br> ``<token>``: An authorized password | ``200``: Found <br> ``400``: Invalid parameters <br> ``401``: Unauthorized token <br> ``404``: Series or build not found |

Returned JSON:
```
{
"commit_hash": <The commit hash>,
"series": <The Mumble version series e.g. "1.4.x">,
"series_id": <The series DB id>,
"build_number": <The new build number>,
"series_created": <Series creation datetime>,
"build_created": <Build number creation datetime>
}
```

---

Endpoint: ``/build-number/v1/<series>?token=<token>``
| HTTP <br> Method| Parameters | Response |
| :-----: | ----- | ---- |
| ``GET`` | ``<series>``: The Mumble series e.g. ``1.4`` <br> ``<token>``: An authorized password | ``200``: Found <br> ``400``: Invalid parameters <br> ``401``: Unauthorized token <br> ``404``: Series not found |

Returned JSON:
```
{
"series": <The Mumble version series e.g. "1.4.x">,
"series_id": <The series DB id>,
"series_created": <Series creation datetime>,
"builds": <List of all builds>
}
```
Build object:
```
{
"commit_hash": <The commit hash>,
"build_number": <The build number>,
"build_created": <Build number creation datetime>
}
```
Empty file.
6 changes: 6 additions & 0 deletions mumble_backend/build_number_manager/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin

from .models import Series, Build

admin.site.register(Series)
admin.site.register(Build)
6 changes: 6 additions & 0 deletions mumble_backend/build_number_manager/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BuildNumberManagerConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "build_number_manager"
70 changes: 70 additions & 0 deletions mumble_backend/build_number_manager/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Generated by Django 4.1.7 on 2023-04-13 14:44

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Build",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("commit_hash", models.CharField(max_length=128)),
("build_number", models.PositiveIntegerField()),
("created_on", models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name="Series",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("major", models.PositiveIntegerField()),
("minor", models.PositiveIntegerField()),
("created_on", models.DateTimeField(auto_now_add=True)),
],
options={
"verbose_name_plural": "series",
},
),
migrations.AddConstraint(
model_name="series",
constraint=models.UniqueConstraint(
fields=("major", "minor"), name="major_minor_unique"
),
),
migrations.AddField(
model_name="build",
name="series",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="build_number_manager.series",
),
),
migrations.AddConstraint(
model_name="build",
constraint=models.UniqueConstraint(
fields=("series", "commit_hash"), name="commit_unique_in_series"
),
),
]
Empty file.
39 changes: 39 additions & 0 deletions mumble_backend/build_number_manager/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.db import models


class Series(models.Model):
major = models.PositiveIntegerField()
minor = models.PositiveIntegerField()
created_on = models.DateTimeField(auto_now_add=True)

def __str__(self):
return "%i.%i.x" % (self.major, self.minor) # e.g. 1.4.x

class Meta:
constraints = [
models.UniqueConstraint(
fields=["major", "minor"], name="major_minor_unique"
)
]
verbose_name_plural = "series"


class Build(models.Model):
series = models.ForeignKey(Series, on_delete=models.PROTECT)
commit_hash = models.CharField(max_length=128)
build_number = models.PositiveIntegerField()
created_on = models.DateTimeField(auto_now_add=True)

def __str__(self):
return "%i.%i.%i" % (
self.series.major,
self.series.minor,
self.build_number,
) # e.g. 1.4.142

class Meta:
constraints = [
models.UniqueConstraint(
fields=["series", "commit_hash"], name="commit_unique_in_series"
)
]
Loading