Commit 8ee3bbe3 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

replace docker management commands by a view to get scripts

parent 320a8bf4
Pipeline #549 passed with stages
in 53 seconds
import logging
from subprocess import call
from django.core.management.base import BaseCommand
from rainboard.models import Image
logger = logging.getLogger('rainboard.docker')
class Command(BaseCommand):
help = 'Create all docker images'
def handle(self, *args, **options):
logger.info('Building all docker images…')
for image in Image.objects.all():
ret = call(image.build())
logger.info(f' {image}: {ret}')
if ret == 0:
image.update()
import logging
from subprocess import call
from django.core.management.base import BaseCommand
from rainboard.models import Image
logger = logging.getLogger('rainboard.docker')
class Command(BaseCommand):
help = 'Pull all docker images'
def handle(self, *args, **options):
logger.info('Pulling all docker images…')
for image in Image.objects.all():
call(image.pull())
import logging
from subprocess import call
from django.core.management.base import BaseCommand
from rainboard.models import Image
logger = logging.getLogger('rainboard.docker')
class Command(BaseCommand):
help = 'Push all docker images'
def handle(self, *args, **options):
logger.info('Pushing all docker images…')
for image in Image.objects.all():
call(image.push())
......@@ -17,4 +17,5 @@ urlpatterns = [
path('project/<str:slug>/contributors', views.ProjectContributorsView.as_view(), name='project-contributors'),
path('project/<str:slug>/.gitlab-ci.yml', views.ProjectGitlabView.as_view(), name='project-gitlab'),
path('doc', views.json_doc, name='doc'),
path('docker', views.docker, name='docker'),
]
from django.http.response import JsonResponse
from django.http.response import HttpResponse, JsonResponse
from django.views.generic import DetailView
from django_filters.views import FilterView
......@@ -92,3 +92,11 @@ def json_doc(request):
"""
return JsonResponse({'ret': [(b.project.slug, b.repo.namespace.slug, b.name.split('/', maxsplit=2)[2])
for b in models.Branch.objects.filter(keep_doc=True)]})
def docker(request):
method = request.GET.get('method', 'build')
if method not in ['push', 'pull', 'build']:
method = 'build'
return HttpResponse('\n'.join([' '.join(getattr(image, method)()) for image in models.Image.objects.all()]),
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