Commit 7bc1f0a3 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

target is now a model

parent 4685ef8a
Pipeline #694 passed with stages
in 49 seconds
# Generated by Django 2.0.5 on 2018-05-15 15:55
from enum import IntEnum
import autoslug.fields
from django.db import migrations, models
TARGETS = IntEnum('Targets', '14.04 16.04 17.10 18.04 dubnium jessie')
def add_targets(apps, schema_editor):
Target = apps.get_model('rainboard', 'Target')
Target.objects.create(name='14.04')
Target.objects.create(name='16.04')
Target.objects.create(name='17.10')
Target.objects.create(name='18.04')
Target.objects.create(name='dubnium')
Target.objects.create(name='jessie')
def update_targets(apps, schema_editor):
Image, Target = [apps.get_model('rainboard', model) for model in [Image, Target]]
images = {Target.objects.get(name=target.name): Image.objects.filter(target=target)}
for target, qs in images.items():
qs.update(target=target)
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0011_null_true'),
]
operations = [
migrations.CreateModel(
name='Target',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
],
options={
'abstract': False,
},
),
migrations.RunPython(add_targets),
migrations.AlterField(
model_name='image',
name='target',
field=models.ForeignKey(on_delete=models.deletion.CASCADE, to='rainboard.Target'),
),
migrations.RemoveField(
model_name='robotpkgbuild',
name='robotpkg',
),
migrations.RemoveField(
model_name='robotpkgbuild',
name='target',
),
migrations.RemoveField(
model_name='systemdependency',
name='project',
),
migrations.RemoveField(
model_name='systemdependency',
name='target',
),
migrations.RemoveField(
model_name='test',
name='branch',
),
migrations.RemoveField(
model_name='test',
name='commit',
),
migrations.RemoveField(
model_name='test',
name='project',
),
migrations.RemoveField(
model_name='test',
name='target',
),
migrations.DeleteModel(
name='RobotpkgBuild',
),
migrations.DeleteModel(
name='SystemDependency',
),
migrations.DeleteModel(
name='Test',
),
]
......@@ -15,7 +15,7 @@ from autoslug import AutoSlugField
from ndh.models import Links, NamedModel, TimeStampedModel
from ndh.utils import enum_to_choices, query_sum
from .utils import SOURCES, TARGETS, api_next, invalid_mail, slugify_with_dots
from .utils import SOURCES, api_next, invalid_mail, slugify_with_dots
logger = logging.getLogger('rainboard.models')
......@@ -504,19 +504,23 @@ class Branch(TimeStampedModel):
return self.repo.namespace
class Test(TimeStampedModel):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
branch = models.ForeignKey(Branch, on_delete=models.CASCADE)
commit = models.ForeignKey(Commit, on_delete=models.CASCADE)
target = models.PositiveSmallIntegerField(choices=enum_to_choices(TARGETS))
passed = models.BooleanField(default=False)
class Target(NamedModel):
pass
# class Test(TimeStampedModel):
# project = models.ForeignKey(Project, on_delete=models.CASCADE)
# branch = models.ForeignKey(Branch, on_delete=models.CASCADE)
# commit = models.ForeignKey(Commit, on_delete=models.CASCADE)
# target = models.ForeignKey(Target, on_delete=models.CASCADE)
# passed = models.BooleanField(default=False)
# TODO: travis vs gitlab-ci ?
# TODO: deploy binary, doc, coverage, lint
class SystemDependency(NamedModel):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
target = models.PositiveSmallIntegerField(choices=enum_to_choices(TARGETS))
# class SystemDependency(NamedModel):
# project = models.ForeignKey(Project, on_delete=models.CASCADE)
# target = models.ForeignKey(Target, on_delete=models.CASCADE)
class Robotpkg(NamedModel):
......@@ -545,7 +549,7 @@ class Robotpkg(NamedModel):
return f'{RPKG_URL}/rbulk/robotpkg{path}/{self.name}'
def update_images(self, pull=False):
for target in TARGETS:
for target in Target.objects.all():
image, _ = Image.objects.get_or_create(robotpkg=self, target=target)
image.update(pull)
......@@ -583,15 +587,15 @@ class Robotpkg(NamedModel):
return self.image_set.filter(created__isnull=False)
class RobotpkgBuild(TimeStampedModel):
robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
target = models.PositiveSmallIntegerField(choices=enum_to_choices(TARGETS))
passed = models.BooleanField(default=False)
# class RobotpkgBuild(TimeStampedModel):
# robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
# target = models.ForeignKey(Target, on_delete=models.CASCADE)
# passed = models.BooleanField(default=False)
class Image(models.Model):
robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
target = models.PositiveSmallIntegerField(choices=enum_to_choices(TARGETS))
target = models.ForeignKey(Target, on_delete=models.CASCADE)
created = models.DateTimeField(blank=True, null=True)
image = models.CharField(max_length=12, blank=True, null=True)
......@@ -599,10 +603,10 @@ class Image(models.Model):
unique_together = ('robotpkg', 'target')
def __str__(self):
return f'{self.robotpkg}-{self.get_target_display()}'
return f'{self.robotpkg}-{self.target}'
def get_build_args(self):
ret = {'TARGET': self.get_target_display(), 'ROBOTPKG': self.robotpkg,
ret = {'TARGET': self.target, 'ROBOTPKG': self.robotpkg,
'REGISTRY': self.robotpkg.project.registry()}
if not self.robotpkg.project.public:
ret['IMAGE'] = 'robotpkg-jrl'
......@@ -610,7 +614,7 @@ class Image(models.Model):
def get_image_name(self):
project = self.robotpkg.project
return f'{project.registry()}/{project.main_namespace.slug}/{project}:{self.get_target_display()}'
return f'{project.registry()}/{project.main_namespace.slug}/{project}:{self.target}'
def build(self):
args = self.get_build_args()
......
......@@ -5,7 +5,7 @@ from django_filters.views import FilterView
from django_tables2 import RequestConfig
from django_tables2.views import SingleTableMixin, SingleTableView
from . import filters, models, tables, utils
from . import filters, models, tables
class ForgesView(SingleTableView):
......@@ -99,7 +99,5 @@ def docker(request):
filters = request.GET.dict()
if 'cmd' in filters and filters['cmd'] in ['push', 'pull', 'build']:
cmd = filters.pop('cmd')
if 'target' in filters:
filters['target'] = int(utils.TARGETS.__getitem__(filters['target']))
images = models.Image.objects.filter(**filters)
return HttpResponse('\n'.join([' '.join(getattr(image, cmd)()) for image in images]), content_type="text/plain")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment