Commit fc825f68 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

generate gitlab-ci.yml, show docker cmds

parent 060a8b1d
......@@ -7,10 +7,6 @@ FROM ${REGISTRY}/${FROM}:${TARGET}
ARG ROBOTPKG
ARG ROBOTPKG_DEPS=true
ARG ADDITIONAL_DEPENDENCIES=""
ARG CHECKOUT=false
RUN /get_deps.sh robotpkg-${ROBOTPKG}
RUN apt-get update -qq && apt-get install -qqy \
$(sort -u /system_deps $(${ROBOTPKG_DEPS} && echo /robotpkg_deps)) \
${ADDITIONAL_DEPENDENCIES} \
&& rm -rf /var/lib/apt/lists/*
RUN /get_deps.sh robotpkg-${ROBOTPKG} $CHECKOUT
......@@ -19,8 +19,9 @@ class Command(BaseCommand):
update_robotpkg(path)
for project in Project.objects.all():
for pkg in path.glob(f'*/{project.slug}'):
logger.info(f'{project} found in {pkg}')
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created:
obj.update(pull=False)
for slug in [project.slug, project.slug.replace('_', '-')]:
for pkg in path.glob(f'*/{slug}'):
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created:
logger.info(f'{project} found in {pkg}')
obj.update(pull=False)
......@@ -5,6 +5,7 @@ from subprocess import check_output, CalledProcessError
from django.conf import settings
from django.db import models
from django.template.loader import get_template
from django.utils.dateparse import parse_datetime
from django.utils.safestring import mark_safe
......@@ -554,6 +555,12 @@ class Robotpkg(NamedModel):
self.save()
def valid_images(self):
return self.image_set.filter(created__isnull=False)
def gitlabciyml(self):
return get_template('rainboard/gitlab-ci.yml').render({'robotpkg': self})
class RobotpkgBuild(TimeStampedModel):
robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
......@@ -583,15 +590,20 @@ class Image(models.Model):
def build(self):
args = self.get_build_args()
build_args = sum((['--build-arg', f'{key}={value}'] for key, value in args.items()), list())
cmd = ['docker', 'build', '-t', self.get_image_name()] + build_args + ['.']
return ' '.join(cmd)
return ['docker', 'build', '-t', self.get_image_name()] + build_args + ['.']
def pull(self):
return ['docker', 'pull', self.get_image_name()]
def push(self):
return ['docker', 'push', self.get_image_name()]
def update(self):
image = check_output(['docker', 'images', '-q', self.get_image_name()]).decode().strip()
if not image:
try:
logger.info(f' pulling {self}')
check_output(['docker', 'pull', self.get_image_name()])
check_output(self.pull())
image = check_output(['docker', 'images', '-q', self.get_image_name()]).decode().strip()
except CalledProcessError:
return
......
variables:
GIT_SSL_NO_VERIFY: "true"
GIT_SUBMODULE_STRATEGY: "recursive"
GIT_DEPTH: "3"
NAMESPACE: {{ robotpkg.project.main_namespace.slug }}
PROJECT: {{ robotpkg.project }}
ROBOTPKG: {{ robotpkg }}
CATEGORY: {{ robotpkg.category }}
IMAGE: "${CI_REGISTRY}/${NAMESPACE}/${PROJECT}"
cache:
paths:
- build/ccache
.build: &build
before_script:
- mkdir -p build/ccache
- cd build
- export CCACHE_BASEDIR=${PWD}
- export CCACHE_DIR=${PWD}/ccache
script:
- cd /root/robotpkg/${CATEGORY}/${ROBOTPKG}
- make install
- cd work.*/${ROBOTPKG}*/
- make test
retry: 2
except:
- gh-pages
{% for image in robotpkg.valid_images %}
{{ image }}:
<<: *build
image: ${IMAGE}:{{ image.get_target_display }}
{% endfor %}
......@@ -44,9 +44,12 @@
{% render_table table %}
{% if 'images' in request.path %}
<pre>
{% for image in object_list %}
{{ image.build }}
{% endfor %}
# Pull {% for image in object_list %}
{{ image.pull|join:' ' }}{% endfor %}
# Build {% for image in object_list %}
{{ image.build|join:' ' }}{% endfor %}
# Push {% for image in object_list %}
{{ image.push|join:' ' }}{% endfor %}
</pre>
{% endif %}
......@@ -73,6 +76,11 @@
<dt>Build page</dt> <dd><a href="{{ rpkg.build_page }}">{{ rpkg.build_page }}</a></dd>
</dl>
<h4>gitlab-ci configuration</h4>
<pre>
{{ rpkg.gitlabciyml }}
</pre>
{% endfor %}
{% endif %}
......
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