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

use nim65s/traefik-{dev,prod}

parent 27094d47
db.sqlite3
*.cfg
.env
LICENSE
README.md
requirements.in
.git
LICENSE
*.md
*.orig
*/__pycache__
.python-version
requirements.in
*.sqlite3
.venv
*/__pycache__
*.orig
*.yml
FROM python:alpine
FROM python:alpine3.7
EXPOSE 8000
RUN mkdir /app
WORKDIR /app
RUN apk update && apk add --no-cache git
ADD requirements.txt ./
ADD requirements.txt manage.py ./
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir -U https://github.com/jieter/django-tables2/archive/template-makeover.zip
ENV PYTHONPATH=/usr/lib/python3.6/site-packages
RUN apk update -q && apk add -q --no-cache \
git \
py3-psycopg2 \
&& pip3 install --no-cache-dir -r requirements.txt \
gunicorn
ADD . .
CMD ./manage.py runserver 0.0.0.0:8000
CMD while ! nc -z postgres 5432; do sleep 1; done \
&& ./manage.py migrate \
&& ./manage.py collectstatic --no-input \
&& gunicorn \
--bind 0.0.0.0 \
dashboard.wsgi
# Gepetto Softwares Dashboard
## Dependencies
## Reverse Proxy
Get Python3.6, create a virtualenv, and install dependencies:
Look at my Traefik easy setup for [dev](https://github.com/nim65s/traefik-dev) and
[prod](https://github.com/nim65s/traefik-prod)
`pip install -U -r requirements.txt`
## Launch
## Configuration example
```
export GITHUB_TOKEN=xxx
export GITLAB_TOKEN=xxx
export REDMINE_TOKEN=xxx
export OPENROB_TOKEN=xxx
export TRAVIS_TOKEN=xxx
./manage.py migrate
./manage.py populate
./manage.py runserver
echo POSTGRES_PASSWORD=$(openssl rand -base64 32) >> .env
echo SECRET_KEY=$(openssl rand -base64 32) >> .env
echo EMAIL_HOST_PASSWORD=xxx >> .env
echo GITHUB_TOKEN=xxx >> .env
echo GITLAB_TOKEN=xxx >> .env
echo REDMINE_TOKEN=xxx >> .env
echo OPENROB_TOKEN=xxx >> .env
echo TRAVIS_TOKEN=xxx >> .env
```
You can then go to http://localhost:8000
## Launch
## TODO
`docker-compose up -d`
- fix urls (https://api.github.com/repos/stack-of-tasks/pinocchio)
## Populate
## Prod
`docker-compose exec app ./manage.py populate`
### Traefik
## Create super user
```
docker network create web
cd traefik
docker-compose up -d
```
`docker-compose exec app ./manage.py createsuperuser`
### Dashboard
## TODO
```
docker-compose up -d
docker-compose exec app ./manage.py collectstatic --noinput
docker-compose exec app ./manage.py migrate
```
- fix urls (https://api.github.com/repos/stack-of-tasks/pinocchio)
"""
Django settings for dashboard project.
Generated by 'django-admin startproject' using Django 2.0.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
from os import environ
from os.path import abspath, dirname, join
from pathlib import Path
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
PROJECT = 'dashboard'
PROJECT_VERBOSE = PROJECT.capitalize()
SELF_MAIL = False
DOMAIN_NAME = environ.get('DOMAIN_NAME', 'local')
ALLOWED_HOSTS = [environ.get('ALLOWED_HOST', f'{PROJECT}.{DOMAIN_NAME}')]
ALLOWED_HOSTS += [f'www.{host}' for host in ALLOWED_HOSTS]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
BASE_DIR = dirname(dirname(abspath(__file__)))
ALLOWED_HOSTS = ['rainboard', 'rainboard.laas.fr', 'localhost']
SECRET_KEY = environ['SECRET_KEY']
DEBUG = environ.get('DEBUG', 'False').lower() == 'true'
# Application definition
EMAIL_USE_SSL = True
EMAIL_HOST = environ.get('EMAIL_HOST', f'smtp.{DOMAIN_NAME}')
EMAIL_HOST_PASSWORD = environ['EMAIL_HOST_PASSWORD']
EMAIL_USER = environ.get('EMAIL_USER', 'majo')
EMAIL_PORT = environ.get('EMAIL_PORT', 465)
EMAIL_FQDN = environ.get('EMAIL_FQDN', ALLOWED_HOSTS[0] if SELF_MAIL else DOMAIN_NAME)
EMAIL_HOST_USER = f'{EMAIL_USER}@{EMAIL_FQDN}'
SERVER_EMAIL = f'{EMAIL_USER}+{PROJECT}@{EMAIL_FQDN}'
DEFAULT_FROM_EMAIL = f'{PROJECT_VERBOSE} <{EMAIL_USER}@{EMAIL_FQDN}>'
EMAIL_BACKEND = 'django.core.mail.backends.%s' % ('filebased.EmailBackend' if DEBUG else 'smtp.EmailBackend')
EMAIL_SUBJECT_PREFIX = f'[{PROJECT_VERBOSE}] '
INSTALLED_APPS = [
'django.contrib.admin',
......@@ -56,7 +52,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'dashboard.urls'
ROOT_URLCONF = f'{PROJECT}.urls'
TEMPLATES = [
{
......@@ -75,22 +71,23 @@ TEMPLATES = [
},
]
WSGI_APPLICATION = 'dashboard.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
WSGI_APPLICATION = f'{PROJECT}.wsgi.application'
DB = environ.get('DB', 'postgres')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': f'django.db.backends.sqlite3',
'NAME': join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
if DB == 'postgres':
DATABASES['default'].update(
ENGINE='django.db.backends.postgresql',
NAME=environ.get('POSTGRES_DB', DB),
USER=environ.get('POSTGRES_USER', DB),
HOST=environ.get('POSTGRES_HOST', DB),
PASSWORD=environ['POSTGRES_PASSWORD'],
)
AUTH_PASSWORD_VALIDATORS = [
{
......@@ -107,55 +104,44 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'fr-FR'
TIME_ZONE = 'Europe/Paris'
LANGUAGE_CODE = environ.get('LANGUAGE_CODE', 'fr-FR')
TIME_ZONE = environ.get('TIME_ZONE', 'Europe/Paris')
USE_I18N = True
USE_L10N = True
USE_TZ = True
SITE_ID = int(environ.get('SITE_ID', 1))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = '/srv/media/'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/srv/media'
STATIC_ROOT = '/srv/static'
SITE_ID = 1
STATIC_URL = '/static/'
STATIC_ROOT = '/srv/static/'
DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'memcached:11211',
}
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'null': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '/tmp/dashboard.log',
'class': 'logging.NullHandler',
},
},
'loggers': {
'': {
'handlers': ['console', 'file'],
'propagate': True,
'level': 'WARNING',
'django.security.DisallowedHost': {
'handlers': ['null'],
'propagate': False,
},
},
}
DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html'
RAINBOARD_DATA = Path('/srv/dashboard')
RAINBOARD_GITS = RAINBOARD_DATA / 'repositories'
RAINBOARD_RPKG = RAINBOARD_DATA / 'robotpkg'
......
version: '3'
volumes:
static:
media:
srv:
sql:
services:
postgres:
image: postgres:alpine
image: postgres:10-alpine
restart: unless-stopped
env_file:
- .env
volumes:
- "sql:/var/lib/postgresql/data"
memcached:
image: memcached:alpine
restart: unless-stopped
app:
image: eur0c.laas.fr:5000/gepetto/dashboard:master
build: .
restart: unless-stopped
volumes:
- ./db.sqlite3:/app/db.sqlite3
- "srv:/srv"
- /srv/dashboard/repositories:/srv/dashboard/repositories
- /srv/dashboard/robotpkg:/srv/dashboard/robotpkg
- static:/srv/static
- media:/srv/media
env_file:
- .env
networks:
- traefik
- default
labels:
- "traefik.enable=true"
- "traefik.frontend.rule= Host:rainboard.${DOMAIN_NAME:-local}"
- "traefik.docker.network=traefik"
nginx:
image: nim65s/ndh:nginx
restart: unless-stopped
volumes:
- static:/srv/static
- media:/srv/media
labels:
- "traefik.frontend.rule=Host:rainboard.laas.fr"
- "srv:/srv"
networks:
- web
- default
- traefik
labels:
- "traefik.enable=true"
- "traefik.frontend.rule= Host:rainboard.${DOMAIN_NAME:-local}; PathPrefix: /static, /media"
networks:
web:
traefik:
external: true
......@@ -9,13 +9,13 @@ chardet==3.0.4 # via requests
django-autoslug-iplweb==1.9.4.dev0 # via ndh
django-bootstrap4==0.0.6 # via ndh
django-filter==1.1.0
django-tables2==1.19.0
django==2.0.2 # via django-tables2, ndh
django==2.0.3 # via django-tables2, ndh
gitdb2==2.0.3 # via gitpython
gitpython==2.1.8
idna==2.6 # via requests
ndh==3.2.0
ndh==3.2.1
pytz==2018.3 # via django
requests==2.18.4
smmap2==2.0.3 # via gitdb2
urllib3==1.22 # via requests
https://github.com/jieter/django-tables2/archive/two.zip
version: '2'
services:
traefik:
image: traefik:1.5-alpine
restart: always
ports:
- 80:80
networks:
- web
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/traefik.toml
networks:
web:
external: true
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "docker.localhost"
watch = true
exposedbydefault = true
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