Commit a29652ca authored by Tom Pillot's avatar Tom Pillot
Browse files

Now nothing is hardcoded

parent f2bea060
......@@ -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 \
......
# 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,7 +374,7 @@ 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, target__main=True)
images = Image.objects.filter(robotpkg__project=self, py3=True, debug=True, target__main=True)
return images.order_by(Length('robotpkg__name').desc()).first()
def print_deps(self):
......@@ -801,16 +801,7 @@ class Robotpkg(NamedModel):
def valid_images(self):
images = self.image_set.filter(created__isnull=False, target__active=True).order_by('target__name')
valid = []
for image in images:
if (image.target.name, image.py3, image.debug) in (
('18.04', True, False), # 18.04 / python 3 / Release
('16.04', True, False), # 16.04 / python 3 / Release
('20.04', True, False), # 20.04 / python 3 / Release
('18.04', False, False), # 18.04 / python 2 / Release and 18.04 / no python / Release
):
valid.append(image)
return valid
return (image for image in images if image.is_valid)
def without_py(self):
if 'py-' in self.name and self.same_py:
......@@ -831,6 +822,7 @@ 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')
......@@ -844,6 +836,30 @@ 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