From: maxbr Date: Mon, 26 Sep 2016 14:36:11 +0000 (+0200) Subject: Restructure dashboard project for docker deploying X-Git-Tag: 6.0.0~123 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=ff30b14a212f38cf59084d30e9f13f9f92d2be3b;p=pharos.git Restructure dashboard project for docker deploying Change-Id: I13cad51270504ee4bed8558598a8891af58a26ab Signed-off-by: maxbr --- diff --git a/tools/pharos-dashboard/.gitignore b/tools/pharos-dashboard/.gitignore index 2b73909a..4154fdd3 100644 --- a/tools/pharos-dashboard/.gitignore +++ b/tools/pharos-dashboard/.gitignore @@ -19,8 +19,9 @@ coverage.xml # Django: *.log *.pot -migrations/ -settings.py + +# Celery +celerybeat-schedule.db # KDE: .directory @@ -36,3 +37,10 @@ venv/ # Bower Components: bower_components/ + +# Production settings +config.env + +# rsa key files +rsa.pem +rsa.pub diff --git a/tools/pharos-dashboard/Makefile b/tools/pharos-dashboard/Makefile new file mode 100644 index 00000000..e52e15d2 --- /dev/null +++ b/tools/pharos-dashboard/Makefile @@ -0,0 +1,35 @@ +build: + docker-compose build + +up: + docker-compose up -d + +start: + docker-compose start + +stop: + docker-compose stop + +shell-nginx: + docker exec -ti ng01 bash + +shell-web: + docker exec -ti dg01 bash + +shell-db: + docker exec -ti ps01 bash + +log-nginx: + docker-compose logs nginx + +log-web: + docker-compose logs web + +log-ps: + docker-compose logs postgres + +log-rmq: + docker-compose logs rabbitmq + +log-worker: + docker-compose logs worker diff --git a/tools/pharos-dashboard/celerybeat-schedule b/tools/pharos-dashboard/celerybeat-schedule deleted file mode 100644 index 7e5fe853..00000000 Binary files a/tools/pharos-dashboard/celerybeat-schedule and /dev/null differ diff --git a/tools/pharos-dashboard/config.env.sample b/tools/pharos-dashboard/config.env.sample new file mode 100644 index 00000000..bd936164 --- /dev/null +++ b/tools/pharos-dashboard/config.env.sample @@ -0,0 +1,18 @@ +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG=False + +DB_NAME=sample_name +DB_USER=sample_user +DB_PASS=sample_pass +DB_SERVICE=postgres +DB_PORT=5432 + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY=http://www.miniwebtool.com/django-secret-key-generator/ + +OAUTH_CONSUMER_KEY=sample_key +OAUTH_CONSUMER_SECRET=sample_secret + +JIRA_URL=sample_url +JIRA_USER_NAME=sample_jira_user +JIRA_USER_PASSWORD=sample_jira_pass \ No newline at end of file diff --git a/tools/pharos-dashboard/config/nginx/pharos_dashboard.conf b/tools/pharos-dashboard/config/nginx/pharos_dashboard.conf new file mode 100644 index 00000000..87b6f8e8 --- /dev/null +++ b/tools/pharos-dashboard/config/nginx/pharos_dashboard.conf @@ -0,0 +1,24 @@ +upstream web { + ip_hash; + server web:8000; +} + +# portal +server { + listen 80; + server_name localhost; + charset utf-8; + + location /static { + alias /static; + } + + location /media { + alias /media; + } + + location / { + proxy_set_header Host $host; + proxy_pass http://web/; + } +} diff --git a/tools/pharos-dashboard/config/postgres/docker-entrypoint-initdb.d/pharos_dashboard.sh b/tools/pharos-dashboard/config/postgres/docker-entrypoint-initdb.d/pharos_dashboard.sh new file mode 100755 index 00000000..526228a8 --- /dev/null +++ b/tools/pharos-dashboard/config/postgres/docker-entrypoint-initdb.d/pharos_dashboard.sh @@ -0,0 +1,14 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +#!/bin/env bash + +psql -U postgres -c "CREATE USER $DB_USER PASSWORD '$DB_PASS'" +psql -U postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER" diff --git a/tools/pharos-dashboard/deploy.org b/tools/pharos-dashboard/deploy.org deleted file mode 100644 index b8399215..00000000 --- a/tools/pharos-dashboard/deploy.org +++ /dev/null @@ -1,45 +0,0 @@ -* Database - -** Setup -- sudo -u postgres psql -- postgres=# CREATE DATABASE pharos_dashboard -- postgres=# CREATE USER opnfv WITH PASSWORD 'opnfvopnfv' -- postgres# createuser --interactive -- postgres# ALTER ROLE opnfv SET client_encoding TO 'utf8'; -- postgres# ALTER ROLE opnfv SET default_transaction_isolation TO 'read committed'; -- postgres# ALTER ROLE opnfv SET timezone TO 'UTC'; -- postgres# GRANT ALL PRIVILEGES ON DATABASE pharos_dashboard TO opnfv; - -** Dump data - -- log out all users, stop server -- (venv) # python manage.py dumpdata > dashboard/fixtures/.json - -** Load dump - -- setup clean database, run migrate -- (venv) # python manage.py loaddata - -* Django - -** Virtualenv setup - -- # virtualenv venv -- # source venv/bin/activate -- (venv) # pip install -r requirements.txt - -** initializing or after change in models.py - -- (venv) # python manage.py makemigrations -- (venv) # python manage.py migrate - -** Development - -- (venv) # python manage.py runserver -- (venv) # python manage.py shell - -* Dependencies - -Javascript / CSS dependencies are managed with bower. To install them, you have to install bower, switch directory to the dashboard/static folder and run -# bower install -Bower will download and install the right versions of all the static files. diff --git a/tools/pharos-dashboard/docker-compose.yml b/tools/pharos-dashboard/docker-compose.yml new file mode 100644 index 00000000..00a8d151 --- /dev/null +++ b/tools/pharos-dashboard/docker-compose.yml @@ -0,0 +1,69 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +version: '2' +services: + nginx: + restart: always + image: nginx:latest + container_name: ng01 + ports: + - "80:80" + volumes: + - ./config/nginx:/etc/nginx/conf.d + - /var/lib/pharos_dashboard/static:/static + - /var/lib/pharos_dashboard/media:/media + depends_on: + - web + + web: + restart: always + build: ./web/ + container_name: dg01 + command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --no-input && gunicorn pharos_dashboard.wsgi -b 0.0.0.0:8000" + depends_on: + - postgres + links: + - postgres + env_file: config.env + volumes: + - ./src:/src + - /var/lib/pharos_dashboard/static:/static + - /var/lib/pharos_dashboard/media:/media + expose: + - "8000" + + postgres: + restart: always + image: postgres:latest + container_name: ps01 + env_file: config.env + volumes: + - ./config/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + - /var/lib/pharos_dashboard/postgresql:/var/lib/postgresql + + rabbitmq: + restart: always + image: rabbitmq:latest + container_name: rm01 + expose: + - "5672" + + worker: + restart: always + build: ./worker/ + command: bash -c "celery -A pharos_dashboard worker -l info -B" + env_file: config.env + links: + - postgres + - rabbitmq + volumes: + - ./src:/src + \ No newline at end of file diff --git a/tools/pharos-dashboard/readme.txt b/tools/pharos-dashboard/readme.txt new file mode 100644 index 00000000..b21320f3 --- /dev/null +++ b/tools/pharos-dashboard/readme.txt @@ -0,0 +1,35 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +The dashboard is deployed using docker-compose. +Application / database files are saved in /var/lib/pharos_dashboard/. + +Deployment: + +- clone the repository +- complete the config.env.sample file and save it as config.env +- install docker, docker-compose and bower +- run 'bower install' in ./src/static/ to fetch javascript dependencies +- run 'make build' to build the containers +- run 'make up' to run the dashboard + +Updating: + +- make stop +- git pull +- run 'bower install' if javascript dependencies changed +- make build +- make start + +If there is migrations that need user input (like renaming a field), they need to be run manually! + +Logs / Shell access: + +- there is some shortcuts in the makefile \ No newline at end of file diff --git a/tools/pharos-dashboard/account/__init__.py b/tools/pharos-dashboard/src/account/__init__.py similarity index 100% rename from tools/pharos-dashboard/account/__init__.py rename to tools/pharos-dashboard/src/account/__init__.py diff --git a/tools/pharos-dashboard/account/admin.py b/tools/pharos-dashboard/src/account/admin.py similarity index 100% rename from tools/pharos-dashboard/account/admin.py rename to tools/pharos-dashboard/src/account/admin.py diff --git a/tools/pharos-dashboard/account/apps.py b/tools/pharos-dashboard/src/account/apps.py similarity index 100% rename from tools/pharos-dashboard/account/apps.py rename to tools/pharos-dashboard/src/account/apps.py diff --git a/tools/pharos-dashboard/account/forms.py b/tools/pharos-dashboard/src/account/forms.py similarity index 100% rename from tools/pharos-dashboard/account/forms.py rename to tools/pharos-dashboard/src/account/forms.py diff --git a/tools/pharos-dashboard/account/jira_util.py b/tools/pharos-dashboard/src/account/jira_util.py similarity index 100% rename from tools/pharos-dashboard/account/jira_util.py rename to tools/pharos-dashboard/src/account/jira_util.py diff --git a/tools/pharos-dashboard/account/middleware.py b/tools/pharos-dashboard/src/account/middleware.py similarity index 100% rename from tools/pharos-dashboard/account/middleware.py rename to tools/pharos-dashboard/src/account/middleware.py diff --git a/tools/pharos-dashboard/account/migrations/__init__.py b/tools/pharos-dashboard/src/account/migrations/__init__.py similarity index 100% rename from tools/pharos-dashboard/account/migrations/__init__.py rename to tools/pharos-dashboard/src/account/migrations/__init__.py diff --git a/tools/pharos-dashboard/account/models.py b/tools/pharos-dashboard/src/account/models.py similarity index 100% rename from tools/pharos-dashboard/account/models.py rename to tools/pharos-dashboard/src/account/models.py diff --git a/tools/pharos-dashboard/account/rsa.pem b/tools/pharos-dashboard/src/account/rsa.pem similarity index 100% rename from tools/pharos-dashboard/account/rsa.pem rename to tools/pharos-dashboard/src/account/rsa.pem diff --git a/tools/pharos-dashboard/account/rsa.pub b/tools/pharos-dashboard/src/account/rsa.pub similarity index 100% rename from tools/pharos-dashboard/account/rsa.pub rename to tools/pharos-dashboard/src/account/rsa.pub diff --git a/tools/pharos-dashboard/account/tests/__init__.py b/tools/pharos-dashboard/src/account/tests/__init__.py similarity index 100% rename from tools/pharos-dashboard/account/tests/__init__.py rename to tools/pharos-dashboard/src/account/tests/__init__.py diff --git a/tools/pharos-dashboard/account/tests/test_general.py b/tools/pharos-dashboard/src/account/tests/test_general.py similarity index 100% rename from tools/pharos-dashboard/account/tests/test_general.py rename to tools/pharos-dashboard/src/account/tests/test_general.py diff --git a/tools/pharos-dashboard/account/urls.py b/tools/pharos-dashboard/src/account/urls.py similarity index 100% rename from tools/pharos-dashboard/account/urls.py rename to tools/pharos-dashboard/src/account/urls.py diff --git a/tools/pharos-dashboard/account/views.py b/tools/pharos-dashboard/src/account/views.py similarity index 100% rename from tools/pharos-dashboard/account/views.py rename to tools/pharos-dashboard/src/account/views.py diff --git a/tools/pharos-dashboard/api/__init__.py b/tools/pharos-dashboard/src/api/__init__.py similarity index 100% rename from tools/pharos-dashboard/api/__init__.py rename to tools/pharos-dashboard/src/api/__init__.py diff --git a/tools/pharos-dashboard/api/serializers.py b/tools/pharos-dashboard/src/api/serializers.py similarity index 100% rename from tools/pharos-dashboard/api/serializers.py rename to tools/pharos-dashboard/src/api/serializers.py diff --git a/tools/pharos-dashboard/api/urls.py b/tools/pharos-dashboard/src/api/urls.py similarity index 100% rename from tools/pharos-dashboard/api/urls.py rename to tools/pharos-dashboard/src/api/urls.py diff --git a/tools/pharos-dashboard/api/views.py b/tools/pharos-dashboard/src/api/views.py similarity index 100% rename from tools/pharos-dashboard/api/views.py rename to tools/pharos-dashboard/src/api/views.py diff --git a/tools/pharos-dashboard/booking/__init__.py b/tools/pharos-dashboard/src/booking/__init__.py similarity index 100% rename from tools/pharos-dashboard/booking/__init__.py rename to tools/pharos-dashboard/src/booking/__init__.py diff --git a/tools/pharos-dashboard/booking/admin.py b/tools/pharos-dashboard/src/booking/admin.py similarity index 100% rename from tools/pharos-dashboard/booking/admin.py rename to tools/pharos-dashboard/src/booking/admin.py diff --git a/tools/pharos-dashboard/booking/apps.py b/tools/pharos-dashboard/src/booking/apps.py similarity index 100% rename from tools/pharos-dashboard/booking/apps.py rename to tools/pharos-dashboard/src/booking/apps.py diff --git a/tools/pharos-dashboard/booking/forms.py b/tools/pharos-dashboard/src/booking/forms.py similarity index 100% rename from tools/pharos-dashboard/booking/forms.py rename to tools/pharos-dashboard/src/booking/forms.py diff --git a/tools/pharos-dashboard/booking/migrations/__init__.py b/tools/pharos-dashboard/src/booking/migrations/__init__.py similarity index 100% rename from tools/pharos-dashboard/booking/migrations/__init__.py rename to tools/pharos-dashboard/src/booking/migrations/__init__.py diff --git a/tools/pharos-dashboard/booking/models.py b/tools/pharos-dashboard/src/booking/models.py similarity index 100% rename from tools/pharos-dashboard/booking/models.py rename to tools/pharos-dashboard/src/booking/models.py diff --git a/tools/pharos-dashboard/booking/tests/__init__.py b/tools/pharos-dashboard/src/booking/tests/__init__.py similarity index 100% rename from tools/pharos-dashboard/booking/tests/__init__.py rename to tools/pharos-dashboard/src/booking/tests/__init__.py diff --git a/tools/pharos-dashboard/booking/tests/test_models.py b/tools/pharos-dashboard/src/booking/tests/test_models.py similarity index 100% rename from tools/pharos-dashboard/booking/tests/test_models.py rename to tools/pharos-dashboard/src/booking/tests/test_models.py diff --git a/tools/pharos-dashboard/booking/tests/test_views.py b/tools/pharos-dashboard/src/booking/tests/test_views.py similarity index 100% rename from tools/pharos-dashboard/booking/tests/test_views.py rename to tools/pharos-dashboard/src/booking/tests/test_views.py diff --git a/tools/pharos-dashboard/booking/urls.py b/tools/pharos-dashboard/src/booking/urls.py similarity index 100% rename from tools/pharos-dashboard/booking/urls.py rename to tools/pharos-dashboard/src/booking/urls.py diff --git a/tools/pharos-dashboard/booking/views.py b/tools/pharos-dashboard/src/booking/views.py similarity index 100% rename from tools/pharos-dashboard/booking/views.py rename to tools/pharos-dashboard/src/booking/views.py diff --git a/tools/pharos-dashboard/dashboard/__init__.py b/tools/pharos-dashboard/src/dashboard/__init__.py similarity index 100% rename from tools/pharos-dashboard/dashboard/__init__.py rename to tools/pharos-dashboard/src/dashboard/__init__.py diff --git a/tools/pharos-dashboard/dashboard/admin.py b/tools/pharos-dashboard/src/dashboard/admin.py similarity index 100% rename from tools/pharos-dashboard/dashboard/admin.py rename to tools/pharos-dashboard/src/dashboard/admin.py diff --git a/tools/pharos-dashboard/dashboard/apps.py b/tools/pharos-dashboard/src/dashboard/apps.py similarity index 100% rename from tools/pharos-dashboard/dashboard/apps.py rename to tools/pharos-dashboard/src/dashboard/apps.py diff --git a/tools/pharos-dashboard/dashboard/fixtures/dashboard.json b/tools/pharos-dashboard/src/dashboard/fixtures/dashboard.json similarity index 100% rename from tools/pharos-dashboard/dashboard/fixtures/dashboard.json rename to tools/pharos-dashboard/src/dashboard/fixtures/dashboard.json diff --git a/tools/pharos-dashboard/dashboard/migrations/__init__.py b/tools/pharos-dashboard/src/dashboard/migrations/__init__.py similarity index 100% rename from tools/pharos-dashboard/dashboard/migrations/__init__.py rename to tools/pharos-dashboard/src/dashboard/migrations/__init__.py diff --git a/tools/pharos-dashboard/dashboard/models.py b/tools/pharos-dashboard/src/dashboard/models.py similarity index 100% rename from tools/pharos-dashboard/dashboard/models.py rename to tools/pharos-dashboard/src/dashboard/models.py diff --git a/tools/pharos-dashboard/dashboard/tasks.py b/tools/pharos-dashboard/src/dashboard/tasks.py similarity index 100% rename from tools/pharos-dashboard/dashboard/tasks.py rename to tools/pharos-dashboard/src/dashboard/tasks.py diff --git a/tools/pharos-dashboard/dashboard/templatetags/__init__.py b/tools/pharos-dashboard/src/dashboard/templatetags/__init__.py similarity index 100% rename from tools/pharos-dashboard/dashboard/templatetags/__init__.py rename to tools/pharos-dashboard/src/dashboard/templatetags/__init__.py diff --git a/tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py b/tools/pharos-dashboard/src/dashboard/templatetags/jenkins_filters.py similarity index 100% rename from tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py rename to tools/pharos-dashboard/src/dashboard/templatetags/jenkins_filters.py diff --git a/tools/pharos-dashboard/dashboard/templatetags/jira_filters.py b/tools/pharos-dashboard/src/dashboard/templatetags/jira_filters.py similarity index 100% rename from tools/pharos-dashboard/dashboard/templatetags/jira_filters.py rename to tools/pharos-dashboard/src/dashboard/templatetags/jira_filters.py diff --git a/tools/pharos-dashboard/dashboard/urls.py b/tools/pharos-dashboard/src/dashboard/urls.py similarity index 100% rename from tools/pharos-dashboard/dashboard/urls.py rename to tools/pharos-dashboard/src/dashboard/urls.py diff --git a/tools/pharos-dashboard/dashboard/views.py b/tools/pharos-dashboard/src/dashboard/views.py similarity index 100% rename from tools/pharos-dashboard/dashboard/views.py rename to tools/pharos-dashboard/src/dashboard/views.py diff --git a/tools/pharos-dashboard/jenkins/__init__.py b/tools/pharos-dashboard/src/jenkins/__init__.py similarity index 100% rename from tools/pharos-dashboard/jenkins/__init__.py rename to tools/pharos-dashboard/src/jenkins/__init__.py diff --git a/tools/pharos-dashboard/jenkins/adapter.py b/tools/pharos-dashboard/src/jenkins/adapter.py similarity index 100% rename from tools/pharos-dashboard/jenkins/adapter.py rename to tools/pharos-dashboard/src/jenkins/adapter.py diff --git a/tools/pharos-dashboard/src/jenkins/admin.py b/tools/pharos-dashboard/src/jenkins/admin.py new file mode 100644 index 00000000..c4996702 --- /dev/null +++ b/tools/pharos-dashboard/src/jenkins/admin.py @@ -0,0 +1,17 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +from django.conf import settings +from django.contrib import admin + +from jenkins.models import JenkinsSlave + +if settings.DEBUG: + admin.site.register(JenkinsSlave) \ No newline at end of file diff --git a/tools/pharos-dashboard/jenkins/apps.py b/tools/pharos-dashboard/src/jenkins/apps.py similarity index 100% rename from tools/pharos-dashboard/jenkins/apps.py rename to tools/pharos-dashboard/src/jenkins/apps.py diff --git a/tools/pharos-dashboard/jenkins/migrations/__init__.py b/tools/pharos-dashboard/src/jenkins/migrations/__init__.py similarity index 100% rename from tools/pharos-dashboard/jenkins/migrations/__init__.py rename to tools/pharos-dashboard/src/jenkins/migrations/__init__.py diff --git a/tools/pharos-dashboard/jenkins/models.py b/tools/pharos-dashboard/src/jenkins/models.py similarity index 100% rename from tools/pharos-dashboard/jenkins/models.py rename to tools/pharos-dashboard/src/jenkins/models.py diff --git a/tools/pharos-dashboard/jenkins/tasks.py b/tools/pharos-dashboard/src/jenkins/tasks.py similarity index 100% rename from tools/pharos-dashboard/jenkins/tasks.py rename to tools/pharos-dashboard/src/jenkins/tasks.py diff --git a/tools/pharos-dashboard/jenkins/tests.py b/tools/pharos-dashboard/src/jenkins/tests.py similarity index 100% rename from tools/pharos-dashboard/jenkins/tests.py rename to tools/pharos-dashboard/src/jenkins/tests.py diff --git a/tools/pharos-dashboard/manage.py b/tools/pharos-dashboard/src/manage.py similarity index 100% rename from tools/pharos-dashboard/manage.py rename to tools/pharos-dashboard/src/manage.py diff --git a/tools/pharos-dashboard/notification/__init__.py b/tools/pharos-dashboard/src/notification/__init__.py similarity index 100% rename from tools/pharos-dashboard/notification/__init__.py rename to tools/pharos-dashboard/src/notification/__init__.py diff --git a/tools/pharos-dashboard/notification/admin.py b/tools/pharos-dashboard/src/notification/admin.py similarity index 100% rename from tools/pharos-dashboard/notification/admin.py rename to tools/pharos-dashboard/src/notification/admin.py diff --git a/tools/pharos-dashboard/notification/apps.py b/tools/pharos-dashboard/src/notification/apps.py similarity index 100% rename from tools/pharos-dashboard/notification/apps.py rename to tools/pharos-dashboard/src/notification/apps.py diff --git a/tools/pharos-dashboard/notification_framework/__init__.py b/tools/pharos-dashboard/src/notification/migrations/__init__.py similarity index 100% rename from tools/pharos-dashboard/notification_framework/__init__.py rename to tools/pharos-dashboard/src/notification/migrations/__init__.py diff --git a/tools/pharos-dashboard/notification/models.py b/tools/pharos-dashboard/src/notification/models.py similarity index 100% rename from tools/pharos-dashboard/notification/models.py rename to tools/pharos-dashboard/src/notification/models.py diff --git a/tools/pharos-dashboard/notification/signals.py b/tools/pharos-dashboard/src/notification/signals.py similarity index 100% rename from tools/pharos-dashboard/notification/signals.py rename to tools/pharos-dashboard/src/notification/signals.py diff --git a/tools/pharos-dashboard/notification/tasks.py b/tools/pharos-dashboard/src/notification/tasks.py similarity index 100% rename from tools/pharos-dashboard/notification/tasks.py rename to tools/pharos-dashboard/src/notification/tasks.py diff --git a/tools/pharos-dashboard/src/notification_framework/__init__.py b/tools/pharos-dashboard/src/notification_framework/__init__.py new file mode 100644 index 00000000..b5914ce7 --- /dev/null +++ b/tools/pharos-dashboard/src/notification_framework/__init__.py @@ -0,0 +1,10 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + diff --git a/tools/pharos-dashboard/notification_framework/notification.py b/tools/pharos-dashboard/src/notification_framework/notification.py similarity index 100% rename from tools/pharos-dashboard/notification_framework/notification.py rename to tools/pharos-dashboard/src/notification_framework/notification.py diff --git a/tools/pharos-dashboard/pharos_dashboard/__init__.py b/tools/pharos-dashboard/src/pharos_dashboard/__init__.py similarity index 100% rename from tools/pharos-dashboard/pharos_dashboard/__init__.py rename to tools/pharos-dashboard/src/pharos_dashboard/__init__.py diff --git a/tools/pharos-dashboard/pharos_dashboard/celery.py b/tools/pharos-dashboard/src/pharos_dashboard/celery.py similarity index 100% rename from tools/pharos-dashboard/pharos_dashboard/celery.py rename to tools/pharos-dashboard/src/pharos_dashboard/celery.py diff --git a/tools/pharos-dashboard/src/pharos_dashboard/settings.py b/tools/pharos-dashboard/src/pharos_dashboard/settings.py new file mode 100644 index 00000000..2c4e8ccf --- /dev/null +++ b/tools/pharos-dashboard/src/pharos_dashboard/settings.py @@ -0,0 +1,176 @@ +import os +from datetime import timedelta + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = os.environ['DEBUG'] + +# Application definition + +INSTALLED_APPS = [ + 'dashboard', + 'booking', + 'account', + 'jenkins', + 'notification', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.humanize', + 'bootstrap3', + 'crispy_forms', + 'rest_framework', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'account.middleware.TimezoneMiddleware', +] + +ROOT_URLCONF = 'pharos_dashboard.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')] + , + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'pharos_dashboard.wsgi.application' + +# Password validation +# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +# Internationalization +# https://docs.djangoproject.com/en/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ +MEDIA_URL = '/media/' +STATIC_URL = '/static/' + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] + +LOGIN_REDIRECT_URL = '/' + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ['SECRET_KEY'] + +BOOTSTRAP3 = { + 'set_placeholder': False, +} + +ALLOWED_HOSTS = ['*'] + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ['DB_NAME'], + 'USER': os.environ['DB_USER'], + 'PASSWORD': os.environ['DB_PASS'], + 'HOST': os.environ['DB_SERVICE'], + 'PORT': os.environ['DB_PORT'] + } +} + + +# Rest API Settings +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ], + 'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',) +} + +MEDIA_ROOT = '/media' +STATIC_ROOT = '/static' + +# Jira Settings +CREATE_JIRA_TICKET = False + +JIRA_URL = os.environ['JIRA_URL'] + +JIRA_USER_NAME = os.environ['JIRA_USER_NAME'] +JIRA_USER_PASSWORD = os.environ['JIRA_USER_PASSWORD'] + +OAUTH_CONSUMER_KEY = os.environ['OAUTH_CONSUMER_KEY'] +OAUTH_CONSUMER_SECRET = os.environ['OAUTH_CONSUMER_SECRET'] + +OAUTH_REQUEST_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/request-token' +OAUTH_ACCESS_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/access-token' +OAUTH_AUTHORIZE_URL = JIRA_URL + '/plugins/servlet/oauth/authorize' + +OAUTH_CALLBACK_URL = JIRA_URL + '/accounts/authenticated' + +# Celery Settings +CELERY_TIMEZONE = 'UTC' + +RABBITMQ_URL = 'rabbitmq' +BROKER_URL = 'amqp://guest:guest@rabbitmq:5672//' + +CELERYBEAT_SCHEDULE = { + 'sync-jenkins': { + 'task': 'jenkins.tasks.sync_jenkins', + 'schedule': timedelta(minutes=5) + }, + 'send-booking-notifications': { + 'task': 'notification.tasks.send_booking_notifications', + 'schedule': timedelta(minutes=5) + }, + 'clean-database': { + 'task': 'dashboard.tasks.database_cleanup', + 'schedule': timedelta(hours=24) + }, +} \ No newline at end of file diff --git a/tools/pharos-dashboard/pharos_dashboard/urls.py b/tools/pharos-dashboard/src/pharos_dashboard/urls.py similarity index 100% rename from tools/pharos-dashboard/pharos_dashboard/urls.py rename to tools/pharos-dashboard/src/pharos_dashboard/urls.py diff --git a/tools/pharos-dashboard/pharos_dashboard/wsgi.py b/tools/pharos-dashboard/src/pharos_dashboard/wsgi.py similarity index 100% rename from tools/pharos-dashboard/pharos_dashboard/wsgi.py rename to tools/pharos-dashboard/src/pharos_dashboard/wsgi.py diff --git a/tools/pharos-dashboard/static/bower.json b/tools/pharos-dashboard/src/static/bower.json similarity index 100% rename from tools/pharos-dashboard/static/bower.json rename to tools/pharos-dashboard/src/static/bower.json diff --git a/tools/pharos-dashboard/static/css/theme.css b/tools/pharos-dashboard/src/static/css/theme.css similarity index 100% rename from tools/pharos-dashboard/static/css/theme.css rename to tools/pharos-dashboard/src/static/css/theme.css diff --git a/tools/pharos-dashboard/static/js/booking-calendar.js b/tools/pharos-dashboard/src/static/js/booking-calendar.js similarity index 100% rename from tools/pharos-dashboard/static/js/booking-calendar.js rename to tools/pharos-dashboard/src/static/js/booking-calendar.js diff --git a/tools/pharos-dashboard/static/js/dataTables-sort.js b/tools/pharos-dashboard/src/static/js/dataTables-sort.js similarity index 100% rename from tools/pharos-dashboard/static/js/dataTables-sort.js rename to tools/pharos-dashboard/src/static/js/dataTables-sort.js diff --git a/tools/pharos-dashboard/static/js/datetimepicker-options.js b/tools/pharos-dashboard/src/static/js/datetimepicker-options.js similarity index 100% rename from tools/pharos-dashboard/static/js/datetimepicker-options.js rename to tools/pharos-dashboard/src/static/js/datetimepicker-options.js diff --git a/tools/pharos-dashboard/static/js/flot-pie-chart.js b/tools/pharos-dashboard/src/static/js/flot-pie-chart.js similarity index 100% rename from tools/pharos-dashboard/static/js/flot-pie-chart.js rename to tools/pharos-dashboard/src/static/js/flot-pie-chart.js diff --git a/tools/pharos-dashboard/static/js/fullcalendar-options.js b/tools/pharos-dashboard/src/static/js/fullcalendar-options.js similarity index 100% rename from tools/pharos-dashboard/static/js/fullcalendar-options.js rename to tools/pharos-dashboard/src/static/js/fullcalendar-options.js diff --git a/tools/pharos-dashboard/templates/account/user_list.html b/tools/pharos-dashboard/src/templates/account/user_list.html similarity index 100% rename from tools/pharos-dashboard/templates/account/user_list.html rename to tools/pharos-dashboard/src/templates/account/user_list.html diff --git a/tools/pharos-dashboard/templates/account/userprofile_update_form.html b/tools/pharos-dashboard/src/templates/account/userprofile_update_form.html similarity index 100% rename from tools/pharos-dashboard/templates/account/userprofile_update_form.html rename to tools/pharos-dashboard/src/templates/account/userprofile_update_form.html diff --git a/tools/pharos-dashboard/templates/base.html b/tools/pharos-dashboard/src/templates/base.html similarity index 94% rename from tools/pharos-dashboard/templates/base.html rename to tools/pharos-dashboard/src/templates/base.html index c5da483d..5bb55473 100644 --- a/tools/pharos-dashboard/templates/base.html +++ b/tools/pharos-dashboard/src/templates/base.html @@ -66,11 +66,6 @@ class="fa fa-fw">Jenkins Slaves -
  • - Resources - -
  • Users diff --git a/tools/pharos-dashboard/templates/booking/booking_calendar.html b/tools/pharos-dashboard/src/templates/booking/booking_calendar.html similarity index 100% rename from tools/pharos-dashboard/templates/booking/booking_calendar.html rename to tools/pharos-dashboard/src/templates/booking/booking_calendar.html diff --git a/tools/pharos-dashboard/templates/booking/booking_detail.html b/tools/pharos-dashboard/src/templates/booking/booking_detail.html similarity index 100% rename from tools/pharos-dashboard/templates/booking/booking_detail.html rename to tools/pharos-dashboard/src/templates/booking/booking_detail.html diff --git a/tools/pharos-dashboard/templates/booking/booking_table.html b/tools/pharos-dashboard/src/templates/booking/booking_table.html similarity index 100% rename from tools/pharos-dashboard/templates/booking/booking_table.html rename to tools/pharos-dashboard/src/templates/booking/booking_table.html diff --git a/tools/pharos-dashboard/templates/dashboard/ci_pods.html b/tools/pharos-dashboard/src/templates/dashboard/ci_pods.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/ci_pods.html rename to tools/pharos-dashboard/src/templates/dashboard/ci_pods.html diff --git a/tools/pharos-dashboard/templates/dashboard/dev_pods.html b/tools/pharos-dashboard/src/templates/dashboard/dev_pods.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/dev_pods.html rename to tools/pharos-dashboard/src/templates/dashboard/dev_pods.html diff --git a/tools/pharos-dashboard/templates/dashboard/jenkins_slaves.html b/tools/pharos-dashboard/src/templates/dashboard/jenkins_slaves.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/jenkins_slaves.html rename to tools/pharos-dashboard/src/templates/dashboard/jenkins_slaves.html diff --git a/tools/pharos-dashboard/templates/dashboard/resource.html b/tools/pharos-dashboard/src/templates/dashboard/resource.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/resource.html rename to tools/pharos-dashboard/src/templates/dashboard/resource.html diff --git a/tools/pharos-dashboard/templates/dashboard/resource_all.html b/tools/pharos-dashboard/src/templates/dashboard/resource_all.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/resource_all.html rename to tools/pharos-dashboard/src/templates/dashboard/resource_all.html diff --git a/tools/pharos-dashboard/templates/dashboard/resource_detail.html b/tools/pharos-dashboard/src/templates/dashboard/resource_detail.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/resource_detail.html rename to tools/pharos-dashboard/src/templates/dashboard/resource_detail.html diff --git a/tools/pharos-dashboard/templates/dashboard/server_table.html b/tools/pharos-dashboard/src/templates/dashboard/server_table.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/server_table.html rename to tools/pharos-dashboard/src/templates/dashboard/server_table.html diff --git a/tools/pharos-dashboard/templates/dashboard/table.html b/tools/pharos-dashboard/src/templates/dashboard/table.html similarity index 100% rename from tools/pharos-dashboard/templates/dashboard/table.html rename to tools/pharos-dashboard/src/templates/dashboard/table.html diff --git a/tools/pharos-dashboard/templates/layout.html b/tools/pharos-dashboard/src/templates/layout.html similarity index 100% rename from tools/pharos-dashboard/templates/layout.html rename to tools/pharos-dashboard/src/templates/layout.html diff --git a/tools/pharos-dashboard/templates/rest_framework/api.html b/tools/pharos-dashboard/src/templates/rest_framework/api.html similarity index 100% rename from tools/pharos-dashboard/templates/rest_framework/api.html rename to tools/pharos-dashboard/src/templates/rest_framework/api.html diff --git a/tools/pharos-dashboard/web/Dockerfile b/tools/pharos-dashboard/web/Dockerfile new file mode 100644 index 00000000..d5432359 --- /dev/null +++ b/tools/pharos-dashboard/web/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.5 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /config +ADD ./requirements.txt /config/ +RUN pip install -r /config/requirements.txt +RUN mkdir /src; +WORKDIR /src diff --git a/tools/pharos-dashboard/web/requirements.txt b/tools/pharos-dashboard/web/requirements.txt new file mode 100644 index 00000000..edb20d03 --- /dev/null +++ b/tools/pharos-dashboard/web/requirements.txt @@ -0,0 +1,16 @@ +celery==3.1.23 +cryptography==1.4 +Django==1.10 +django-bootstrap3==7.0.1 +django-crispy-forms==1.6.0 +django-filter==0.14.0 +django-registration==2.1.2 +djangorestframework==3.4.6 +gunicorn==19.6.0 +jira==1.0.7 +oauth2==1.9.0.post1 +oauthlib==1.1.2 +pika==0.10.0 +psycopg2==2.6.2 +PyJWT==1.4.2 +requests==2.11.0 diff --git a/tools/pharos-dashboard/worker/Dockerfile b/tools/pharos-dashboard/worker/Dockerfile new file mode 100644 index 00000000..86395e01 --- /dev/null +++ b/tools/pharos-dashboard/worker/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.5 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /config +ADD ./requirements.txt /config/ +RUN pip install -r /config/requirements.txt +RUN useradd -ms /bin/bash celery +USER celery +WORKDIR /src diff --git a/tools/pharos-dashboard/worker/requirements.txt b/tools/pharos-dashboard/worker/requirements.txt new file mode 100644 index 00000000..edb20d03 --- /dev/null +++ b/tools/pharos-dashboard/worker/requirements.txt @@ -0,0 +1,16 @@ +celery==3.1.23 +cryptography==1.4 +Django==1.10 +django-bootstrap3==7.0.1 +django-crispy-forms==1.6.0 +django-filter==0.14.0 +django-registration==2.1.2 +djangorestframework==3.4.6 +gunicorn==19.6.0 +jira==1.0.7 +oauth2==1.9.0.post1 +oauthlib==1.1.2 +pika==0.10.0 +psycopg2==2.6.2 +PyJWT==1.4.2 +requests==2.11.0