Commit 67825f9a authored by Tom Pillot's avatar Tom Pillot
Browse files

Use another base image if the preferred parameters are not available for the project

parent a29652ca
......@@ -37,9 +37,9 @@ RUN pipenv install --system --deploy
ADD . .
CMD rm -f /opt/openrobots/etc/robotpkg.conf \
# && git clone git://git.openrobots.org/robots/robotpkg /srv/dashboard/robotpkg || true \
# && git clone git://git.openrobots.org/robots/robotpkg/robotpkg-wip /srv/dashboard/robotpkg/wip || true \
# && /srv/dashboard/robotpkg/bootstrap/bootstrap \
&& git clone git://git.openrobots.org/robots/robotpkg /srv/dashboard/robotpkg || true \
&& git clone git://git.openrobots.org/robots/robotpkg/robotpkg-wip /srv/dashboard/robotpkg/wip || true \
&& /srv/dashboard/robotpkg/bootstrap/bootstrap \
&& while ! nc -z postgres 5432; do sleep 1; done \
&& ./manage.py migrate \
&& ./manage.py collectstatic --no-input \
......
......@@ -29,6 +29,27 @@ def add_project(apps, schema_editor):
)
git_project.save()
git_project = Project(
name='talos-data',
public=True,
main_namespace=Namespace.objects.get(name='Gepetto'),
main_forge=Forge.objects.get(name='Gitlab'),
license=None,
homepage=None,
description=None,
version=None,
updated=None,
tests=True,
docs=True,
from_gepetto=True,
cmake_name=None,
archived=False,
suffix='',
allow_format_failure=True,
has_python=True
)
git_project.save()
class Migration(migrations.Migration):
dependencies = [
......
......@@ -7,17 +7,17 @@ path = settings.RAINBOARD_RPKG
def add_robotpkg(apps, schema_editor):
project = Project.objects.get(slug='example-adder')
for project in [Project.objects.get(slug='example-adder'), Project.objects.get(slug='talos-data')]:
for slug in [project.slug, project.slug.replace('_', '-')]:
for pkg in itertools.chain(path.glob(f'*/{slug}{project.suffix}'), path.glob(f'*/py-{slug}{project.suffix}')):
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created:
print(project, pkg)
obj.update(pull=False)
for slug in [project.slug, project.slug.replace('_', '-')]:
for pkg in itertools.chain(path.glob(f'*/{slug}{project.suffix}'), path.glob(f'*/py-{slug}{project.suffix}')):
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created:
print(project, pkg)
obj.update(pull=False)
for rpkg in project.robotpkg_set.all():
rpkg.update_images()
for rpkg in project.robotpkg_set.all():
rpkg.update_images()
class Migration(migrations.Migration):
......
# Generated by Django 3.0.7 on 2020-07-23 12:15
from django.db import migrations, models
from rainboard.models import Image
def add_base_image(apps, schema_editor):
"""Make 18.04 / Python 3 / Release the base image."""
base_image = Image.objects.get(target__name='18.04', py3=True, debug=False)
base_image.is_base_image = True
base_image.save()
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0046_robotpkg'),
]
operations = [
migrations.AddField(
model_name='image',
name='is_base_image',
field=models.NullBooleanField(default=None, unique=True),
),
migrations.RunPython(add_base_image),
]
......@@ -374,8 +374,8 @@ class Project(Links, NamedModel, TimeStampedModel):
return settings.PUBLIC_REGISTRY if self.public else settings.PRIVATE_REGISTRY
def doc_coverage_image(self):
images = Image.objects.filter(robotpkg__project=self, py3=True, debug=True, target__main=True)
return images.order_by(Length('robotpkg__name').desc()).first()
images = Image.objects.filter(robotpkg__project=self, target__main=True)
return images.order_by('-py3', '-debug').first() # 18.04 / Python 3 / Release is the preferred image
def print_deps(self):
return mark_safe(', '.join(d.library.get_link() for d in self.dependencies.all()))
......@@ -800,8 +800,28 @@ class Robotpkg(NamedModel):
self.save()
def valid_images(self):
def is_valid(_base_image, _image):
"""The image is valid if it has less than one different parameter from the base image."""
if _image == self.project.doc_coverage_image():
# There is no need to keep this image because it is already tested by doc-coverage
return False
base_param = (_base_image.target.name, _base_image.py3, _base_image.debug)
param = (_image.target.name, _image.py3, _image.debug)
diff = 0 # Number of different parameters between the base image and the current image
for i in range(len(base_param)):
if base_param[i] != param[i]:
diff += 1
return diff <= 1
# 18.04 / Python 3 / Release is the preferred base image
base_images = Image.objects.filter(robotpkg__project=self.project, target__main=True)
base_image = base_images.order_by('-py3', 'debug').first()
print(f"base_image = {(base_image.target.name, base_image.py3, base_image.debug)}")
images = self.image_set.filter(created__isnull=False, target__active=True).order_by('target__name')
return (image for image in images if image.is_valid)
return (image for image in images if is_valid(base_image, image))
def without_py(self):
if 'py-' in self.name and self.same_py:
......@@ -822,7 +842,6 @@ class Image(models.Model):
py3 = models.BooleanField(default=False)
debug = models.BooleanField(default=False)
allow_failure = models.BooleanField(default=False)
is_base_image = models.NullBooleanField(default=None, unique=True)
class Meta:
unique_together = ('robotpkg', 'target', 'py3', 'debug')
......@@ -836,30 +855,6 @@ class Image(models.Model):
py = ''
return f'{self.robotpkg}{py}:{self.target}'
def save(self, *args, **kwargs):
if self.is_base_image is False:
self.is_base_image = None # Needed to ensure the uniqueness of the base image
super(Image, self).save(*args, **kwargs)
@property
def is_valid(self):
"""The image is valid if it has less than one different parameter from the base image."""
doc_coverage_image = Project.objects.all().first().doc_coverage_image()
# TODO: is it ok to assume that all doc-coverage images are the same ?
if self == doc_coverage_image:
# There is no need to keep this image because it is already tested by doc-coverage
return False
base_image = Image.objects.get(is_base_image=True)
base_param = (base_image.target.name, base_image.py3, base_image.debug)
param = (self.target.name, self.py3, self.debug)
diff = 0 # Number of different parameters between the base image and the current image
for i in range(len(base_param)):
if base_param[i] != param[i]:
diff += 1
return diff <= 1
def get_build_args(self):
ret = {
'TARGET': self.target,
......
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