Skip to content

Commit

Permalink
Merge pull request #47 from Clivern/issue-#16
Browse files Browse the repository at this point in the history
Issue #16
  • Loading branch information
Clivern authored Oct 3, 2018
2 parents 31d8580 + 8ab9432 commit 0ed8fe5
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 175 deletions.
127 changes: 17 additions & 110 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,38 @@
<p align="center">
<img height="150" src="https://raw.githubusercontent.com/Clivern/Kraven/master/static/assets/images/logo.png">
<img alt="Kraven Logo" src="https://raw.githubusercontent.com/Clivern/Kraven/master/static/assets/images/logo.png" height="140" />
<h3 align="center">Kraven</h3>
<p align="center">A SaaS Docker Management Dashboard.</p>
</p>

# Kraven
A SaaS Docker Management Dashboard.
---

[![Build Status](https://travis-ci.org/Clivern/Kraven.svg?branch=master)](https://travis-ci.org/Clivern/Kraven)
[![GitHub license](https://img.shields.io/badge/Version-1.0.0-orange.svg)](https://github.com/Clivern/Kraven#changelog)
[![GitHub license](https://img.shields.io/github/license/Clivern/Kraven.svg)](https://github.com/Clivern/Kraven/blob/master/LICENSE)

Installation
------------

In order to run this app do the following:

### Default Install

1. Get the application code

```bash
git clone https://github.com/Clivern/Kraven.git kraven
cd kraven
cp .env.example .env
```

2. Install dependencies

```bash
pip install -r requirements.txt
```

3. Edit the .env file manually or use command for that

```bash
# Set DB Host
python manage.py kraven update_env DB_HOST=127.0.0.1

# Set DB Port
python manage.py kraven update_env DB_PORT=3306

# Set DB Name
python manage.py kraven update_env DB_DATABASE=kraven

# Set DB Username
python manage.py kraven update_env DB_USERNAME=root

# Set DB Password
python manage.py kraven update_env DB_PASSWORD=

# Create a new app key (Required)
python manage.py kraven update_app_key

# Set DB Type (mysql or sqlite supported till now)
python manage.py kraven update_env DB_CONNECTION=mysql
```

4. Migrate The Database.
Kraven manage different docker environments! It allows you to manage your docker containers, images, volumes, networks and much more! It is easy to install and manage backed with a wonderful stuff like Django, RabbitMQ and Celery and integrated with prometheus and grafana.

```bash
python manage.py migrate
```

5. Run The Server

```bash
python manage.py runserver
```

7. Go to `http://127.0.0.1:8000/install` to install the application.
Everything Asynchronous with ability to run any number of workers to scale. It can run as centralized or distributed application.


### With Docker
## Documentation

1. Get the application code
Documentation is inside the [docs directory](docs/README.md)

```bash
git clone https://github.com/Clivern/Kraven.git kraven
cd kraven
cp .env.docker .env
```

2. Then run our docker containers
## Badges

```bash
docker-compose build
docker-compose up -d
```

3. Open your browser and access the `http://127.0.0.1:8000/`.

4. Also you can add `http://kraven.com` to your `/etc/hosts` file.
[![Build Status](https://travis-ci.org/Clivern/Kraven.svg?branch=master)](https://travis-ci.org/Clivern/Kraven)
[![GitHub license](https://img.shields.io/badge/Version-1.0.0-orange.svg)](https://github.com/Clivern/Kraven#changelog)
[![GitHub license](https://img.shields.io/github/license/Clivern/Kraven.svg)](https://github.com/Clivern/Kraven/blob/master/LICENSE)

```bash
127.0.0.1:8000 kraven.com
```

5. To Check our containers, use the following command:
## Changelog

```bash
docker-compose ps
* [Version 1.0.0:](https://github.com/Clivern/Kraven/milestone/1?closed=1)
```

6. To stop our containers

```bash
docker-compose down
Initial Release.
```


### Running on production

Currently kraven is still under development and for sure we will explain how to run it on production after the first release.


Misc
====

Changelog
---------
Version 1.0.0:
```
Coming Soon.
```

Acknowledgements
----------------
## Acknowledgements

© 2018, Clivern. Released under [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt).

**Kraven** is authored and maintained by [@clivern](http://github.com/clivern).
**Kraven** is authored and maintained by [@clivern](http://github.com/clivern).
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Hosts Actions API Endpoints
Host Images API Endpoints
"""

# Django
Expand All @@ -14,58 +14,11 @@
from app.modules.core.request import Request
from app.modules.core.response import Response
from app.modules.core.host import Host as Host_Module
from app.modules.service.docker.status import Status
from app.modules.core.task import Task as Task_Module
from app.modules.core.notification import Notification as Notification_Module
from app.modules.service.docker.image import Image as Image_Module


class Health_Check(View):

__request = None
__response = None
__helpers = None
__form = None
__logger = None
__user_id = None
__host_id = None
__host_module = None
__status = None

def __init__(self):
self.__request = Request()
self.__response = Response()
self.__helpers = Helpers()
self.__form = Form()
self.__host_module = Host_Module()
self.__status = Status()
self.__logger = self.__helpers.get_logger(__name__)

def get(self, request, host_id):

self.__user_id = request.user.id
self.__host_id = host_id

if not self.__host_module.user_owns(self.__host_id, self.__user_id):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Invalid Request.")
}]))

health = self.__status.set_host(self.__host_id).ping()

if health:
return JsonResponse(self.__response.send_private_success(
[],
{"status": "up"}
))
else:
return JsonResponse(self.__response.send_private_success(
[],
{"status": "down"}
))


class Pull_Image(View):

__request = None
Expand Down Expand Up @@ -964,7 +917,5 @@ def post(self, request, host_id):
else:
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _(
"Error! Something goes wrong with your host!"
)
"message": _("Error! Something goes wrong with your host!")
}]))
3 changes: 3 additions & 0 deletions app/controllers/api/private/v1/admin/host/volumes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Host Volumes API Endpoints
"""
46 changes: 46 additions & 0 deletions app/controllers/api/private/v1/admin/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,49 @@ def delete(self, request, host_id):
"type": "error",
"message": _("Error! Something goes wrong while deleting a host.")
}]))


class Health_Check(View):

__request = None
__response = None
__helpers = None
__form = None
__logger = None
__user_id = None
__host_id = None
__host_module = None
__status = None

def __init__(self):
self.__request = Request()
self.__response = Response()
self.__helpers = Helpers()
self.__form = Form()
self.__host_module = Host_Module()
self.__status = Status()
self.__logger = self.__helpers.get_logger(__name__)

def get(self, request, host_id):

self.__user_id = request.user.id
self.__host_id = host_id

if not self.__host_module.user_owns(self.__host_id, self.__user_id):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Invalid Request.")
}]))

health = self.__status.set_host(self.__host_id).ping()

if health:
return JsonResponse(self.__response.send_private_success(
[],
{"status": "up"}
))
else:
return JsonResponse(self.__response.send_private_success(
[],
{"status": "down"}
))
53 changes: 53 additions & 0 deletions app/management/commands/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# Django
from django.core.management.base import BaseCommand, CommandError
from app.modules.service.docker.image import Image as Image_Module
from app.modules.service.docker.volume import Volume as Volume_Module
from app.modules.service.docker.network import Network as Network_Module
from app.modules.util.io import File
import json


class Command(BaseCommand):
Expand Down Expand Up @@ -82,3 +85,53 @@ def build_image(self, configs={}):
_image = Image_Module()
if _image.set_host(configs["host_id"]).check_health():
print(_image.build(File().read(configs["dockerfile"]), configs["tag"]))

def list_volumes(self, configs={}):
_volume = Volume_Module()
if _volume.set_host(configs["host_id"]).check_health():
print(_volume.list())

def get_volume(self, configs={}):
_volume = Volume_Module()
if _volume.set_host(configs["host_id"]).check_health():
print(_volume.get(configs["volume_id"]))

def remove_volume(self, configs={}):
_volume = Volume_Module()
if _volume.set_host(configs["host_id"]).check_health():
print(_volume.remove(configs["volume_id"], configs["force"] == "True"))

def prune_volumes(self, configs={}):
_volume = Volume_Module()
if _volume.set_host(configs["host_id"]).check_health():
print(_volume.prune())

def create_volume(self, configs={}):
_volume = Volume_Module()
if _volume.set_host(configs["host_id"]).check_health():
print(_volume.create(
name=configs["name"],
driver=configs["driver"] if "driver" in configs else "local",
driver_opts=json.loads(configs["driver_opts"]) if "driver_opts" in configs else {},
labels=json.loads(configs["labels"]) if "labels" in configs else {}
))

def list_networks(self, configs={}):
_network = Network_Module()
if _network.set_host(configs["host_id"]).check_health():
print(_network.list())

def get_network(self, configs={}):
_network = Network_Module()
if _network.set_host(configs["host_id"]).check_health():
print(_network.get(configs["network_id"]))

def prune_networks(self, configs={}):
_network = Network_Module()
if _network.set_host(configs["host_id"]).check_health():
print(_network.prune())

def remove_network(self, configs={}):
_network = Network_Module()
if _network.set_host(configs["host_id"]).check_health():
print(_network.remove(configs["network_id"]))
43 changes: 43 additions & 0 deletions app/modules/service/docker/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Network Module
"""

# local Django
from .auth import Auth


class Network(Auth):

def __init__(self, host_id=None):
Auth.__init__(self, host_id)

def list(self):
result = []
networks_list = self._client.networks.list()
for network in networks_list:
result.append({
"id": network.id,
"short_id": network.short_id,
"name": network.name,
"attrs": network.attrs,
"containers": network.containers
})
return result

def get(self, network_id):
return self._client.networks.get(network_id)

def remove(self, network_id):
return self._client.networks.get(network_id).remove()

def prune(self, filters=None):
return self._client.networks.prune(filters)

def disconnect(self, network_id, container, **configs):
self._client.networks.get(network_id).disconnect(container, **configs)

def connect(self, network_id, container, **configs):
self._client.networks.get(network_id).connect(container, **configs)

def create(self, name):
return self._client.networks.create(name=name)
Loading

0 comments on commit 0ed8fe5

Please sign in to comment.