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

delete dashboard

parent 7e0496f1
variables:
GIT_SSL_NO_VERIFY: "true"
dashboard:
stage: deploy
image: eur0c.laas.fr:4567/stack-of-tasks/pinocchio-tutorials/deploy
before_script:
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
script: "ssh -p 222 web@eur0c ./deploy-dashboard.sh"
FROM python:3.6-alpine3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /app /static
WORKDIR /app
# Get Dependencies
RUN apk update && apk add --virtual deps \
gcc \
python-dev \
linux-headers \
musl-dev \
postgresql-dev \
&& apk add --no-cache libpq
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN apk del deps
COPY . .
# Collect Static
ENV REDMINE_TOKEN=placeholder \
GITHUB_TOKEN=placeholder \
DJANGO_SECRET_KEY=placeholder \
POSTGRES_PASSWORD=placeholder
RUN python manage.py collectstatic --noinput
# Gepetto Packages Dashboard
## APIs used
- github: https://api.github.com/orgs/stack-of-tasks/repos
- gitlab: https://eur0c.laas.fr/api/v4/projects
- redmine: https://redmine.laas.fr/projects.json
### Get dependencies
- Get Python>=3.6
- `pip3 install -U -r requirements.txt` (you might need `sudo`, or *better* `--user`, or *best* a virtualenv)
## RUN
```
rm db.sqlite3 ; and ./manage.py migrate; and ./manage.py runserver localhost:8001
```
version: '3'
volumes:
db:
static:
services:
db:
image: postgres:10-alpine
restart: unless-stopped
env_file:
- .env
volumes:
- "db:/var/lib/postgresql/data"
web:
build: .
restart: unless-stopped
command: python manage.py runserver 0.0.0.0:8000
depends_on:
- db
env_file:
- .env
volumes:
- "static:/static"
ports:
- 8000:8000
migrate:
build: .
command: python manage.py migrate
depends_on:
- db
env_file:
- .env
from django.contrib.admin import site
from .models import License, Package, Project, Repo
for model in [License, Package, Project, Repo]:
site.register(model)
from django.apps import AppConfig
class GepettoPackagesConfig(AppConfig):
name = 'gepetto_packages'
# Generated by Django 2.0 on 2017-12-19 18:30
import django.db.models.deletion
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='License',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
('github_key', models.CharField(max_length=50)),
('spdx_id', models.CharField(max_length=50)),
('url', models.URLField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Package',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=200, unique=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
('homepage', models.URLField(blank=True, null=True)),
('license', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gepetto_packages.License')),
],
options={
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Project',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Repo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('url', models.URLField(unique=True)),
('homepage', models.URLField(blank=True, null=True)),
('default_branch', models.CharField(max_length=50)),
('open_issues', models.PositiveSmallIntegerField(blank=True, null=True)),
('open_pr', models.PositiveSmallIntegerField(blank=True, null=True)),
('repo_id', models.PositiveIntegerField()),
('source_type', models.PositiveSmallIntegerField(choices=[(1, 'github'), (2, 'gitlab'), (3, 'redmine'), (4, 'robotpkg')])),
('api_url', models.CharField(max_length=100)),
('token', models.CharField(blank=True, max_length=50, null=True)),
('license', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gepetto_packages.License')),
('package', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gepetto_packages.Package')),
],
options={
'ordering': ('package', 'url'),
},
),
migrations.AddField(
model_name='package',
name='project',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gepetto_packages.Project'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-09 15:55
from __future__ import unicode_literals
import os
from django.db import migrations
import requests
from gepetto_packages.utils import SOURCES, api_headers, api_data
GITHUB_API = 'https://api.github.com'
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN', '')
HEADERS = api_headers(source=SOURCES.github, token=GITHUB_TOKEN)
PROJECTS = (
'Humanoid Path Planner',
'Stack of Tasks'
)
def github_licenses(apps, schema_editor):
License = apps.get_model('gepetto_packages', 'License')
for data in requests.get(f'{GITHUB_API}/licenses', headers=HEADERS).json():
License.objects.create(github_key=data['key'], **{key: data[key] for key in ['name', 'spdx_id', 'url']})
def github_projects(apps, schema_editor):
Project, License, Package, Repo = (apps.get_model('gepetto_packages', model)
for model in ['Project', 'License', 'Package', 'Repo'])
for project_name in PROJECTS:
project = Project.objects.create(name=project_name)
for data in requests.get(f'{GITHUB_API}/orgs/{project.slug}/repos', headers=HEADERS).json():
package = Package.objects.create(name=data['name'], project=project, homepage=data['homepage'])
repo = Repo.objects.create(package=package, url=data['html_url'], homepage=data['homepage'],
repo_id=data['id'], default_branch=data['default_branch'],
open_issues=data['open_issues'], source_type=SOURCES.github,
api_url=GITHUB_API, token=GITHUB_TOKEN)
repo_data = api_data(repo)
if 'license' in repo_data and repo_data['license']:
license_data = repo_data['license']
license, _ = License.objects.get_or_create(github_key=license_data['key'], name=license_data['name'])
repo.license = license
package.license = license
package.save()
repo.open_pr = len(api_data(repo, '/pulls'))
repo.save()
class Migration(migrations.Migration):
dependencies = [
('gepetto_packages', '0001_initial'),
]
operations = [
migrations.RunPython(github_licenses),
migrations.RunPython(github_projects),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-13 16:13
from __future__ import unicode_literals
from django.db import migrations
import requests
from gepetto_packages.utils import SOURCES
GITLAB_API = 'https://eur0c.laas.fr/api/v4'
def gitlab(apps, schema_editor):
Project, License, Package, Repo = (apps.get_model('gepetto_packages', model)
for model in ['Project', 'License', 'Package', 'Repo'])
for data in requests.get(f'{GITLAB_API}/projects', verify=False).json():
package_qs = Package.objects.filter(name=data['name'])
if package_qs.exists():
Repo.objects.create(package=package_qs.first(), url=data['web_url'], repo_id=data['id'],
source_type=SOURCES.gitlab, api_url=GITLAB_API)
class Migration(migrations.Migration):
dependencies = [
('gepetto_packages', '0002_github'),
]
operations = [
migrations.RunPython(gitlab),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-14 09:29
from __future__ import unicode_literals
import os
from django.conf import settings
from django.db import migrations
import requests
from gepetto_packages.utils import SOURCES, api_headers, api_data
REDMINES = [
('https://redmine.laas.fr', os.getenv('REDMINE_TOKEN', '')),
# ('https://git.openrobots.org', os.getenv('OPENROB_TOKEN', ''),
]
PACKAGES = [
'openhrp3-hrp2',
'Pyrene Talos',
]
def redmine(apps, schema_editor):
Project, License, Package, Repo = (apps.get_model('gepetto_packages', model)
for model in ['Project', 'License', 'Package', 'Repo'])
dummy_project, _ = Project.objects.get_or_create(name='dummy')
for api, token in REDMINES:
headers = api_headers(source=SOURCES.redmine, token=token)
for data in requests.get(f'{api}/projects.json?limit=100', headers=headers).json()['projects']:
if data['name'] in PACKAGES:
Package.objects.get_or_create(name=data['identifier'], project=dummy_project)
package_qs = Package.objects.filter(name=data['identifier'])
if package_qs.exists():
r = Repo.objects.create(package=package_qs.first(), repo_id=data['id'], open_pr=0,
source_type=SOURCES.redmine, api_url=api, token=token)
repo_data = api_data(r)['project']
r.homepage = repo_data['homepage']
r.url = f'{api}/projects/{r.package.name}'
issues_data = requests.get(f'{api}/issues.json?project_id={r.repo_id}&status_id=open', headers=headers)
r.open_issues = issues_data.json()['total_count']
r.save()
if r.homepage and not r.package.homepage:
r.package.homepage = r.homepage
r.package.save()
class Migration(migrations.Migration):
dependencies = [
('gepetto_packages', '0003_gitlab'),
]
operations = [
migrations.RunPython(redmine),
]
from django.db import models
from ndh.models import NamedModel, TimeStampedModel
from ndh.utils import enum_to_choices, query_sum
from .utils import SOURCES, api_headers, api_url
class Project(NamedModel):
pass
class License(NamedModel):
github_key = models.CharField(max_length=50)
spdx_id = models.CharField(max_length=50)
url = models.URLField(max_length=200)
def __str__(self):
return self.spdx_id or self.name
class Package(NamedModel, TimeStampedModel):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
homepage = models.URLField(max_length=200, blank=True, null=True)
license = models.ForeignKey(License, on_delete=models.CASCADE, blank=True, null=True)
class Meta:
ordering = ('name',)
def open_pr(self):
return query_sum(self.repo_set, 'open_pr')
def open_issues(self):
return query_sum(self.repo_set, 'open_issues')
class Repo(TimeStampedModel):
package = models.ForeignKey(Package, on_delete=models.CASCADE)
url = models.URLField(max_length=200, unique=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
license = models.ForeignKey(License, on_delete=models.CASCADE, blank=True, null=True)
default_branch = models.CharField(max_length=50)
open_issues = models.PositiveSmallIntegerField(blank=True, null=True)
open_pr = models.PositiveSmallIntegerField(blank=True, null=True)
repo_id = models.PositiveIntegerField()
source_type = models.PositiveSmallIntegerField(choices=enum_to_choices(SOURCES))
api_url = models.CharField(max_length=100)
token = models.CharField(max_length=50, blank=True, null=True)
class Meta:
ordering = ('package', 'url')
def __str__(self):
return self.url
{% load static bootstrap3 %}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gepetto Packages</title>
<link rel="stylesheet" href="{% bootstrap_css_url %}" crossorigin="anonymous" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" >
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>body { padding-top: 70px; }</style>
{% block style %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Gepetto Packages</a>
</div>
</div>
</nav>
<div class="container">
{% bootstrap_messages %}
{% block content %}
<h1>Hello, world!</h1>
{% endblock %}
</div>
<hr>
<script src="{% bootstrap_jquery_url %}"></script>
<script src="{% bootstrap_javascript_url %}" crossorigin="anonymous" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" ></script>
<script>{% block scripts %}{% endblock %}</script>
</body>
</html>
{% load gepetto_packages %}
<div class="package">
<div class="package-name">{{ package }}</div>
<div class=""></div>
<div class="package-homepage">{{ package.homepage|domain }}</div>
<div class="package-issues">{{ package.open_issues }}</div>
<div class="package-pr">{{ package.open_pr }}</div>
<div class="package-license">{{ package.license|default_if_none:'?' }}</div>
{% for repo in package.repo_set.all %}
{% include 'gepetto_packages/repo.html' with repo=repo %}
{% endfor %}
</div>
{% extends 'base.html' %}
{% block style %}
<style>
.package {
display: grid;
width: 100%;
grid-template-columns: 1fr 1fr 1fr 40px 40px 100px;
border-top: 1px solid;
}
</style>
{% endblock %}
{% block content %}
<div class="package">
<div class="package-name">Name</div>
<div class="">Repo</div>
<div class="package-homepage">Homepage</div>
<div class="">Issues</div>
<div class="">PR</div>
<div class="package-license">License</div>
</div>
{% for package in package_list %}
{% include 'gepetto_packages/package.html' with package=package %}
{% endfor %}
{% endblock %}
{% load gepetto_packages %}
<div></div>
<div class="repo-url">{{ repo.url|domain }}</div>
<div class="repo-homepage">{{ repo.homepage|domain }}</div>
<div class="repo-issues">{{ repo.open_issues|default_if_none:'?' }}</div>
<div class="repo-pr">{{ repo.open_pr|default_if_none:'?' }}</div>
<div class="repo-license">{{ repo.license|default_if_none:'?' }}</div>
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter
def domain(url):
if url:
domain_name = '.'.join(url.split('/')[2].split('.')[-3:])
return mark_safe(f'<a href="{url}">{domain_name}</a>')
return '?'
from django.conf.urls import url
from django.contrib import admin
from django.views.generic import ListView
from .models import Package
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', ListView.as_view(model=Package)),
]
Supports Markdown
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