Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gunicorn & docker build; fix admin urls #395

Merged
merged 4 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ RUN apk update && \
ADD Pipfile Pipfile.lock ./
RUN apk add --no-cache mariadb-connector-c-dev && \
apk add --no-cache --virtual _build-deps \
build-base mariadb-dev libjpeg-turbo-dev zlib-dev && \
pipenv install --deploy && \
build-base mariadb-dev libjpeg-turbo-dev zlib-dev py-gevent libffi-dev && \
pipenv install --deploy --system && \
apk del _build-deps

ADD bin ./bin
ADD pykeg ./pykeg
ADD setup.py ./
RUN pipenv run python setup.py develop
RUN pipenv run kegbot collectstatic -v 0 --noinput
RUN python setup.py develop
RUN bin/kegbot collectstatic -v 0 --noinput

VOLUME ["/kegbot-data"]

EXPOSE 8000
CMD ["/usr/local/bin/pipenv", "run", "gunicorn", "pykeg.web.wsgi:application", "-b", "0.0.0.0:8000"]
CMD [ \
"gunicorn", \
"pykeg.web.wsgi:application", \
"--worker-class=gevent", \
"--workers=8", \
"--worker-tmp-dir=/dev/shm", \
"-b", \
"0.0.0.0:8000" \
]
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mysqlclient = "*"
future = "*"
addict = "*"
kegbot-api = "*"
gevent = "*"

[scripts]
kegbot = "python bin/kegbot"
Expand Down
434 changes: 240 additions & 194 deletions Pipfile.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'
services:
kegbot:
build: .
ports:
- "8000:8000"
volumes:
- kegbot-data:/kegbot-data
environment:
KEGBOT_REDIS_URL: redis://redis:6379/0
KEGBOT_DATABASE_URL: mysql://kegbot_dev:changeme@mysql/kegbot_dev
KEGBOT_SETUP_ENABLED: "true"
KEGBOT_DEBUG: "true"

mysql:
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'changeme'
MYSQL_USER: 'kegbot_dev'
MYSQL_PASSWORD: 'changeme'
MYSQL_DATABASE: 'kegbot_dev'
volumes:
- mysql-data:/var/lib/mysql

redis:
image: redis:latest
restart: always

volumes:
mysql-data:
kegbot-data:
10 changes: 5 additions & 5 deletions pykeg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
INTERNAL_IPS = ('127.0.0.1',)

# Set to true if the database admin module should be enabled.
KEGBOT_ENABLE_ADMIN = False
KEGBOT_ENABLE_ADMIN = DEBUG

KEGBOT_PLUGINS = [
'pykeg.contrib.foursquare.plugin.FoursquarePlugin',
Expand Down Expand Up @@ -199,7 +199,7 @@

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'disable_existing_loggers': False,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
Expand Down Expand Up @@ -241,17 +241,17 @@
'propagate': False,
},
'pykeg': {
'level': 'INFO',
'level': 'DEBUG' if DEBUG else 'INFO',
'handlers': ['console', 'redis'],
'propagate': False,
},
'django': {
'level': 'INFO' if DEBUG else 'WARNING',
'level': 'DEBUG' if DEBUG else 'WARNING',
'handlers': ['console', 'redis'],
'propagate': False,
},
'': {
'level': 'INFO' if DEBUG else 'WARNING',
'level': 'DEBUG' if DEBUG else 'WARNING',
'handlers': ['console', 'redis'],
},
},
Expand Down
2 changes: 1 addition & 1 deletion pykeg/web/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def kbsite(request):
'DEBUG': settings.DEBUG,
'VERSION': util.get_version(),
'HAVE_SESSIONS': False,
'HAVE_ADMIN': settings.KEGBOT_ENABLE_ADMIN,
'KEGBOT_ENABLE_ADMIN': settings.KEGBOT_ENABLE_ADMIN,
'ENABLE_SENSING': kbsite.enable_sensing if kbsite else True,
'ENABLE_USERS': kbsite.enable_users if kbsite else True,
'GOOGLE_ANALYTICS_ID': None,
Expand Down
2 changes: 1 addition & 1 deletion pykeg/web/kegadmin/templates/kegadmin/nav-items.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{% navitem "kegadmin-logs" "Logs" %}
{% navitem "kegadmin-bugreport" "Bugreport" %}
{% navitem "kegadmin-export" "Export Data" %}
{% if HAVE_ADMIN %}
{% if KEGBOT_ENABLE_ADMIN %}
{% navitem "kegadmin-workers" "Worker Status" %}
<li><a href='{% url "admin:index" %}' target="_blank">Database Admin &raquo;</a></li>
{% endif %}
Expand Down
32 changes: 15 additions & 17 deletions pykeg/web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,32 @@
from __future__ import absolute_import

from django.conf import settings
from django.conf.urls import include
from django.conf.urls.static import static
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, re_path, include
from django.views.generic.base import RedirectView

admin.autodiscover()
from pykeg.web.account import urls as account_urls
from pykeg.web.api import urls as api_urls
from pykeg.web.kbregistration import urls as kbregistration_urls
from pykeg.web.kegadmin import urls as kegadmin_urls
from pykeg.web.kegweb import urls as kegweb_urls
from pykeg.web.setup_wizard import urls as setup_wizard_urls

urlpatterns = [
# api
url(r'^api/(?:v1/)?', include('pykeg.web.api.urls')),

# kegbot account
url(r'^account/', include('pykeg.web.account.urls')),

# auth account
url(r'^accounts/', include('pykeg.web.kbregistration.urls')),

# kegadmin
url(r'^kegadmin/', include('pykeg.web.kegadmin.urls')),
re_path(r'^api/(?:v1/)?', include(api_urls)),
path('account/', include(account_urls)),
path('accounts/', include(kbregistration_urls)),
path('kegadmin/', include(kegadmin_urls)),

# Shortcuts
url(r'^link/?$', RedirectView.as_view(pattern_name='kegadmin-link-device')),
]

if 'pykeg.web.setup_wizard' in settings.INSTALLED_APPS:
urlpatterns += [
url(r'^setup/', include('pykeg.web.setup_wizard.urls')),
path('setup/', include(setup_wizard_urls)),
]

if settings.DEBUG:
Expand All @@ -55,10 +53,10 @@

if settings.KEGBOT_ENABLE_ADMIN:
urlpatterns += [
url(r'^admin/', include(admin.site.urls)),
path('admin/', admin.site.urls),
]

# main kegweb urls
urlpatterns += [
url(r'^', include('pykeg.web.kegweb.urls')),
path('', include(kegweb_urls)),
]
15 changes: 15 additions & 0 deletions pykeg/web/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@

import os
from django.core.wsgi import get_wsgi_application
from pykeg.core.util import get_version

BANNER = """
██╗ ██╗███████╗ ██████╗ ██████╗ ██████╗ ████████╗
██║ ██╔╝██╔════╝██╔════╝ ██╔══██╗██╔═══██╗╚══██╔══╝
█████╔╝ █████╗ ██║ ███╗██████╔╝██║ ██║ ██║
██╔═██╗ ██╔══╝ ██║ ██║██╔══██╗██║ ██║ ██║
██║ ██╗███████╗╚██████╔╝██████╔╝╚██████╔╝ ██║
╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝
""".strip()

print(BANNER)
print('kegbot-server - version {}'.format(get_version()))
print(' homepage: https://kegbot.org')
print(' discuss: https://forum.kegbot.org')
print('-' * 80)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pykeg.settings")
application = get_wsgi_application()
11 changes: 1 addition & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
kegerator. For more information and documentation, see http://kegbot.org/
"""

from setuptools import setup, find_packages
from setuptools import setup

VERSION = '1.3.0b1'
DOCLINES = __doc__.split('\n')
Expand All @@ -22,16 +22,7 @@
author='Kegbot Project',
author_email='[email protected]',
url='https://kegbot.org/',
packages=find_packages(),
scripts=[
'bin/kegbot',
'bin/setup-kegbot.py',
],
dependency_links=[
'https://github.com/rem/python-protobuf/tarball/master#egg=protobuf-2.4.1',
],
include_package_data=True,
entry_points={
'console_scripts': ['instance=django.core.management:execute_manager'],
},
)