TT#17622 release_dashboard: add docker images forms

Change-Id: I7da3b00a8a5f7f69d12876de33406919df223e31
changes/21/13921/3
Victor Seva 9 years ago
parent f56bd95932
commit 45f81959e2

@ -0,0 +1,24 @@
# Copyright (C) 2017 The Sipwise Team - http://sipwise.com
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
rd_settings = settings.RELEASE_DASHBOARD_SETTINGS
trunk_projects = sorted(set(rd_settings['projects']) -
set(rd_settings['abandoned']) -
set(rd_settings['build_deps']))
trunk_build_deps = sorted(set(rd_settings['build_deps']) -
set(rd_settings['abandoned']))
docker_projects = rd_settings['docker_projects']

@ -14,14 +14,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms from django import forms
from django.conf import settings from . import rd_settings
from . import trunk_projects, trunk_build_deps
rd_settings = settings.RELEASE_DASHBOARD_SETTINGS
trunk_projects = sorted(set(rd_settings['projects']) -
set(rd_settings['abandoned']) -
set(rd_settings['build_deps']))
trunk_build_deps = sorted(set(rd_settings['build_deps']) -
set(rd_settings['abandoned']))
class BuildForm(forms.Form): class BuildForm(forms.Form):

@ -0,0 +1,28 @@
# Copyright (C) 2016 The Sipwise Team - http://sipwise.com
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from . import docker_projects
class BuildDockerForm(forms.Form):
common_select = forms.CharField(max_length=50)
def __init__(self, *args, **kwargs):
super(BuildDockerForm, self).__init__(*args, **kwargs)
for project in docker_projects:
self.fields['version_%s' %
project] = forms.CharField(max_length=15)

@ -33,16 +33,13 @@ class Project(models.Model):
res = set() res = set()
for value in values: for value in values:
logger.debug("ref[%s]", value["ref"])
match = re.search(val_ok_filter, value["ref"]) match = re.search(val_ok_filter, value["ref"])
if match: if match:
val_ok = match.group(1) val_ok = match.group(1)
if regex is not None: if regex is not None:
if re.search(regex, val_ok): if re.search(regex, val_ok):
res.add(val_ok) res.add(val_ok)
logger.debug("val_ok[%s] regex", val_ok)
else: else:
logger.debug("val_ok[%s]", val_ok)
res.add(val_ok) res.add(val_ok)
return sorted(res, reverse=True) return sorted(res, reverse=True)
@ -51,7 +48,6 @@ class Project(models.Model):
"""gerrit responds with malformed json """gerrit responds with malformed json
https://gerrit-review.googlesource.com/Documentation/rest-api.html#output https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
""" """
logging.debug("json[:5]: %s", text[:5])
return json.loads(text[5:]) return json.loads(text[5:])
def __str__(self): def __str__(self):

@ -20,6 +20,7 @@
</select> </select>
</div> </div>
{% endif %} {% endif %}
{% if not docker %}
<div class="form-group"> <div class="form-group">
<label for="version_release">Release version</label> <label for="version_release">Release version</label>
<input class="form-control" id="version_release" <input class="form-control" id="version_release"
@ -35,6 +36,7 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
{% endif %}
<button id="main" type="submit" class="btn btn-default">Submit</button> <button id="main" type="submit" class="btn btn-default">Submit</button>
</div> </div>
<div id="select_text_info" class="panel-footer"></div> <div id="select_text_info" class="panel-footer"></div>

@ -0,0 +1,13 @@
{% extends "release_dashboard/base.html" %}
{% load staticfiles %}
{% block title %}Build docker images per project{% endblock %}
{% block navlist %}
<li><a href="{% url 'release_dashboard:index'%}">Release Dashboard</a></li>
<li><a href="{% url 'release_dashboard:build_docker_images'%}">Build Docker Images</a></li>
{% endblock %}
{% block content %}
{% include "release_dashboard/build_content.html" %}
{% endblock %}
{% block extrajs %}
<script src="{% static "release_dashboard/js/build.js" %}"></script>
{% endblock %}

@ -3,7 +3,11 @@
{% block title %}Build release{% endblock %} {% block title %}Build release{% endblock %}
{% block navlist %} {% block navlist %}
<li><a href="{% url 'release_dashboard:index'%}">Release Dashboard</a></li> <li><a href="{% url 'release_dashboard:index'%}">Release Dashboard</a></li>
{% if release %}
<li><a href="{% url 'panel:release-view' release %}">Panel {{release}}</a></li> <li><a href="{% url 'panel:release-view' release %}">Panel {{release}}</a></li>
{% else %}
<li><a href="{% url 'release_dashboard:build_docker_images'%}">Build project docker images</a></li>
{% endif %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
@ -18,7 +22,11 @@
{% for project in projects %} {% for project in projects %}
{% if project.url %} {% if project.url %}
<p class="bg-success"> <p class="bg-success">
{% if release %}
<a href="{% url 'panel:project-view' release project.name %}">{{ project.name }}</a> <a href="{% url 'panel:project-view' release project.name %}">{{ project.name }}</a>
{% else %}
<a href="{{ project.url }}">{{ project.name }}</a>
{% endif %}
</p> </p>
{% else %} {% else %}
<p class="bg-danger"> <p class="bg-danger">

@ -39,6 +39,10 @@
<a href="{% url 'release_dashboard:refresh_all'%}"> <a href="{% url 'release_dashboard:refresh_all'%}">
Refresh tag/branch Info</a> Refresh tag/branch Info</a>
</li> </li>
<li class="list-group-item">
<a href="{% url 'release_dashboard:build_docker_images'%}">
Build project docker images</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>

@ -31,4 +31,6 @@ urlpatterns = [
views.hotfix_build), views.hotfix_build),
url(r'^refresh/$', views.refresh_all, name='refresh_all'), url(r'^refresh/$', views.refresh_all, name='refresh_all'),
url(r'^refresh/(?P<project>[^/]+)/$', views.refresh, name='refresh'), url(r'^refresh/(?P<project>[^/]+)/$', views.refresh, name='refresh'),
url(r'^build_docker/$', views.build_docker_images,
name='build_docker_images'),
] ]

@ -34,6 +34,9 @@ hotfix_url = ("{base}/job/release-tools-runner/buildWithParameters?"
"PROJECTNAME={project}&repository={project}&" "PROJECTNAME={project}&repository={project}&"
"push={push}&uuid={uuid}") "push={push}&uuid={uuid}")
docker_url = ("{base}/job/build-project-docker/buildWithParameters?"
"token={token}&project={project}&branch={branch}")
def get_response(url): def get_response(url):
auth = HTTPDigestAuth( auth = HTTPDigestAuth(
@ -100,6 +103,27 @@ def trigger_build(project, trigger_release=None,
return "{base}/job/{job}/".format(**params) return "{base}/job/{job}/".format(**params)
def trigger_docker_build(project, branch):
if branch == "ignore":
logger.debug("ignoring request to trigger project %s due"
" to request of version 'ignore'", project)
return
branch = branch.split("branch/")[1]
params = {
'base': settings.JENKINS_URL,
'token': urllib.quote(settings.JENKINS_TOKEN),
'project': project,
'branch': urllib.quote(branch),
}
url = docker_url.format(**params)
if settings.DEBUG:
logger.debug("Debug mode, would trigger: %s", url)
else:
openurl(url)
return "{base}/job/build-project-docker/".format(**params)
def get_gerrit_info(url): def get_gerrit_info(url):
if settings.DEBUG: if settings.DEBUG:
logger.debug("Debug mode, would trigger: %s", url) logger.debug("Debug mode, would trigger: %s", url)

@ -19,16 +19,17 @@ import json
import uuid import uuid
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponseNotFound, JsonResponse from django.http import HttpResponseNotFound, JsonResponse
from django.conf import settings
from django.views.decorators.http import require_http_methods from django.views.decorators.http import require_http_methods
from release_dashboard.models import Project from release_dashboard.models import Project
from .utils import get_tags, get_branches, trigger_hotfix, trigger_build from .utils import get_tags, get_branches
from .utils import trigger_hotfix, trigger_build, trigger_docker_build
from .tasks import gerrit_fetch_info, gerrit_fetch_all from .tasks import gerrit_fetch_info, gerrit_fetch_all
from .forms import BuildDepForm, BuildReleaseForm from .forms.build import BuildDepForm, BuildReleaseForm
from .forms import BuildTrunkDepForm, BuildTrunkReleaseForm from .forms.build import BuildTrunkDepForm, BuildTrunkReleaseForm
from .forms import trunk_projects, trunk_build_deps from .forms.docker import BuildDockerForm
from .forms import trunk_projects, trunk_build_deps, docker_projects
from .forms import rd_settings
rd_settings = settings.RELEASE_DASHBOARD_SETTINGS
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
regex_hotfix = re.compile(r'^mr[0-9]+\.[0-9]+\.[0-9]+$') regex_hotfix = re.compile(r'^mr[0-9]+\.[0-9]+\.[0-9]+$')
regex_mr = re.compile(r'^mr.+$') regex_mr = re.compile(r'^mr.+$')
@ -40,26 +41,29 @@ def index(request):
return render(request, 'release_dashboard/index.html', context) return render(request, 'release_dashboard/index.html', context)
def _projects_versions(projects, regex=None, tag_only=False): def _projects_versions(projects, regex=None,
tags=True, branches=True):
res = [] res = []
for project in projects: for project in projects:
info = { info = {
'name': project, 'name': project,
'tags': get_tags(project, regex),
} }
if not tag_only: if tags:
info['tags'] = get_tags(project, regex)
if branches:
info['branches'] = get_branches(project, regex) info['branches'] = get_branches(project, regex)
res.append(info) res.append(info)
logger.debug(res) logger.debug(res)
return res return res
def _common_versions(context, tag_only=False): def _common_versions(context, tags=True, branches=True):
common_versions = {'tags': set(), 'branches': set()} common_versions = {'tags': set(), 'branches': set()}
for project in context['projects']: for project in context['projects']:
common_versions['tags'] |= set(project['tags']) if tags:
if not tag_only: common_versions['tags'] |= set(project['tags'])
if branches:
common_versions['branches'] |= set(project['branches']) common_versions['branches'] |= set(project['branches'])
context['common_versions'] = { context['common_versions'] = {
'tags': sorted(common_versions['tags'], reverse=True), 'tags': sorted(common_versions['tags'], reverse=True),
@ -139,11 +143,12 @@ def build_deps(request, tag_only=False):
'projects': _projects_versions( 'projects': _projects_versions(
rd_settings['build_deps'], rd_settings['build_deps'],
regex_mr, regex_mr,
tag_only True,
not tag_only,
), ),
'debian': rd_settings['debian_supported'], 'debian': rd_settings['debian_supported'],
} }
_common_versions(context, tag_only) _common_versions(context, True, not tag_only)
return render(request, 'release_dashboard/build_deps.html', context) return render(request, 'release_dashboard/build_deps.html', context)
@ -151,7 +156,7 @@ def hotfix(request):
context = { context = {
'projects': _projects_versions( 'projects': _projects_versions(
rd_settings['projects'], rd_settings['projects'],
regex_hotfix regex_hotfix,
) )
} }
return render(request, 'release_dashboard/hotfix.html', context) return render(request, 'release_dashboard/hotfix.html', context)
@ -170,11 +175,12 @@ def build_release(request, tag_only=False):
'projects': _projects_versions( 'projects': _projects_versions(
rd_settings['projects'], rd_settings['projects'],
regex_mr, regex_mr,
tag_only True,
not tag_only,
), ),
'debian': rd_settings['debian_supported'], 'debian': rd_settings['debian_supported'],
} }
_common_versions(context, tag_only) _common_versions(context, True, not tag_only)
if tag_only: if tag_only:
return render(request, 'release_dashboard/build_tag.html', context) return render(request, 'release_dashboard/build_tag.html', context)
return render(request, 'release_dashboard/build.html', context) return render(request, 'release_dashboard/build.html', context)
@ -204,12 +210,7 @@ def refresh(request, project):
def build_trunk_deps(request): def build_trunk_deps(request):
if request.method == "POST": if request.method == "POST":
form = BuildTrunkDepForm(request.POST) pass
if form.is_valid():
context = _build_logic(form, trunk_build_deps)
else:
context = {'error': 'form validation error'}
return render(request, 'release_dashboard/build_result.html', context)
else: else:
context = { context = {
'projects': _projects_versions( 'projects': _projects_versions(
@ -247,3 +248,52 @@ def build_trunk_release(request):
'debian': rd_settings['debian_supported'], 'debian': rd_settings['debian_supported'],
} }
return render(request, 'release_dashboard/build_trunk.html', context) return render(request, 'release_dashboard/build_trunk.html', context)
def _build_docker_logic(form, projects):
result = _hash_versions(form.cleaned_data, projects)
context = {'projects': []}
for pro in projects:
try:
logger.debug(
"trying to trigger docker image at branch %s for project %s",
result[pro], pro)
url = trigger_docker_build(pro, result[pro])
context['projects'].append(
{'name': pro, 'url': url})
except KeyError:
logger.error("Houston, we have a problem with"
"trigger for %s", pro)
context['projects'].append(
{'name': pro, 'url': None})
return context
def build_docker_images(request):
if request.method == "POST":
form = BuildDockerForm(request.POST)
if form.is_valid():
context = _build_docker_logic(form, docker_projects)
else:
context = {'error': 'form validation error'}
return render(request,
'release_dashboard/build_result.html',
context)
else:
context = {
'projects': _projects_versions(
docker_projects,
regex_mr,
False,
True,
),
'common_versions': {
'tags': [],
'branches': []
},
'docker': True,
}
_common_versions(context, False, True)
return render(request,
'release_dashboard/build_docker.html',
context)

@ -265,4 +265,22 @@ RELEASE_DASHBOARD_SETTINGS = {
"www_admin", "www_admin",
"www_csc", "www_csc",
), ),
'docker_projects': (
"comx-fileshare-service",
"data-hal",
"documentation",
"janus-admin",
"janus-client",
"kamailio-config-tests",
"libswrate",
"libtcap",
"lua-ngcp-kamailio",
"ngcp-csc",
"ngcp-panel",
"ngcp-rtcengine",
"ngcpcfg",
"rate-o-mat",
"snmp-agent",
"system-tools",
),
} }

Loading…
Cancel
Save