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} ...@@ -7,10 +7,6 @@ FROM ${REGISTRY}/${FROM}:${TARGET}
ARG ROBOTPKG ARG ROBOTPKG
ARG ROBOTPKG_DEPS=true ARG ROBOTPKG_DEPS=true
ARG ADDITIONAL_DEPENDENCIES="" ARG ADDITIONAL_DEPENDENCIES=""
ARG CHECKOUT=false
RUN /get_deps.sh robotpkg-${ROBOTPKG} RUN /get_deps.sh robotpkg-${ROBOTPKG} $CHECKOUT
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/*
...@@ -19,8 +19,9 @@ class Command(BaseCommand): ...@@ -19,8 +19,9 @@ class Command(BaseCommand):
update_robotpkg(path) update_robotpkg(path)
for project in Project.objects.all(): for project in Project.objects.all():
for pkg in path.glob(f'*/{project.slug}'): for slug in [project.slug, project.slug.replace('_', '-')]:
logger.info(f'{project} found in {pkg}') for pkg in path.glob(f'*/{slug}'):
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project) obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created: if created:
obj.update(pull=False) logger.info(f'{project} found in {pkg}')
obj.update(pull=False)
...@@ -5,6 +5,7 @@ from subprocess import check_output, CalledProcessError ...@@ -5,6 +5,7 @@ from subprocess import check_output, CalledProcessError
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.template.loader import get_template
from django.utils.dateparse import parse_datetime from django.utils.dateparse import parse_datetime
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
...@@ -554,6 +555,12 @@ class Robotpkg(NamedModel): ...@@ -554,6 +555,12 @@ class Robotpkg(NamedModel):
self.save() 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): class RobotpkgBuild(TimeStampedModel):
robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE) robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
...@@ -583,15 +590,20 @@ class Image(models.Model): ...@@ -583,15 +590,20 @@ class Image(models.Model):
def build(self): def build(self):
args = self.get_build_args() args = self.get_build_args()
build_args = sum((['--build-arg', f'{key}={value}'] for key, value in args.items()), list()) 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 ['docker', 'build', '-t', self.get_image_name()] + build_args + ['.']
return ' '.join(cmd)
def pull(self):
return ['docker', 'pull', self.get_image_name()]
def push(self):
return ['docker', 'push', self.get_image_name()]
def update(self): def update(self):
image = check_output(['docker', 'images', '-q', self.get_image_name()]).decode().strip() image = check_output(['docker', 'images', '-q', self.get_image_name()]).decode().strip()
if not image: if not image:
try: try:
logger.info(f' pulling {self}') 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() image = check_output(['docker', 'images', '-q', self.get_image_name()]).decode().strip()
except CalledProcessError: except CalledProcessError:
return 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 @@ ...@@ -44,9 +44,12 @@
{% render_table table %} {% render_table table %}
{% if 'images' in request.path %} {% if 'images' in request.path %}
<pre> <pre>
{% for image in object_list %} # Pull {% for image in object_list %}
{{ image.build }} {{ image.pull|join:' ' }}{% endfor %}
{% endfor %} # Build {% for image in object_list %}
{{ image.build|join:' ' }}{% endfor %}
# Push {% for image in object_list %}
{{ image.push|join:' ' }}{% endfor %}
</pre> </pre>
{% endif %} {% endif %}
...@@ -73,6 +76,11 @@ ...@@ -73,6 +76,11 @@
<dt>Build page</dt> <dd><a href="{{ rpkg.build_page }}">{{ rpkg.build_page }}</a></dd> <dt>Build page</dt> <dd><a href="{{ rpkg.build_page }}">{{ rpkg.build_page }}</a></dd>
</dl> </dl>
<h4>gitlab-ci configuration</h4>
<pre>
{{ rpkg.gitlabciyml }}
</pre>
{% endfor %} {% endfor %}
{% endif %} {% 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