From c2979adc2b327d9af51efa058a66f810a3b11881 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 2 Nov 2021 18:08:04 +0000 Subject: [PATCH] misc: devcontainer - django debug toolbar profile + dockerfile cleanup - Legacy-Id: 19529 --- .devcontainer/Dockerfile | 16 +------------ .devcontainer/init.sh | 10 ++++++-- .devcontainer/settings_local.py | 6 ++--- .devcontainer/settings_local_debug.py | 33 +++++++++++++++++++++++++++ .vscode/launch.json | 13 +++++++++++ ietf/group/views.py | 3 ++- ietf/urls.py | 8 +++++++ 7 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 .devcontainer/settings_local_debug.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 640444d41..f761d9475 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -64,14 +64,6 @@ RUN apt-get install -qy \ zile \ zlib1g-dev -# Install libyang -# RUN wget -nv http://download.opensuse.org/repositories/home:liberouter/Debian_9.0/Release.key && \ -# apt-key add - < Release.key && \ -# rm Release.key && \ -# echo "deb http://download.opensuse.org/repositories/home:/liberouter/Debian_9.0/ /" >> /etc/apt/sources.list.d/libyang.list && \ -# apt-get update && \ -# apt-get install -qy libyang1 - # Install chromedriver RUN apt-get update && \ apt-get install -y gnupg wget curl unzip --no-install-recommends && \ @@ -120,12 +112,6 @@ RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requ COPY .devcontainer/init.sh /docker-init.sh RUN sed -i 's/\r$//' /docker-init.sh && \ chmod +x /docker-init.sh + # ENTRYPOINT ["/usr/local/share/datatracker/.devcontainer/init.sh"] CMD ["sleep", "infinity"] - -# [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends - -# [Optional] Uncomment this line to install global node packages. -# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh index 9c9e4185f..d29a017bc 100755 --- a/.devcontainer/init.sh +++ b/.devcontainer/init.sh @@ -83,11 +83,16 @@ fi echo "Activating the virtual python environment ..." . $VIRTDIR/bin/activate -if [ ! -f $WORKSPACEDIR/ietf/settings_local.py ]; then +if [ ! -f "$WORKSPACEDIR/ietf/settings_local.py" ]; then echo "Setting up a default settings_local.py ..." cp $WORKSPACEDIR/.devcontainer/settings_local.py $WORKSPACEDIR/ietf/settings_local.py fi +if [ ! -f "$WORKSPACEDIR/ietf/settings_local_debug.py" ]; then + echo "Setting up a default settings_local_debug.py ..." + cp $WORKSPACEDIR/.devcontainer/settings_local_debug.py $WORKSPACEDIR/ietf/settings_local_debug.py +fi + for sub in test/id/ test/staging/ test/archive/ test/rfc test/media test/wiki/ietf; do dir="$WORKSPACEDIR/$sub" if [ ! -d "$dir" ]; then @@ -141,7 +146,6 @@ chmod -R g+w /usr/local/lib/ # so we can patch libs if needed cd "$WORKSPACEDIR" || cd "/home/$USER/" -echo "Done!" if ! echo "$LANG" | grep "UTF-8"; then echo "" echo "Make sure you export LANG=en_GB.UTF-8 (or another UTF-8 locale) in your .bashrc" @@ -153,6 +157,8 @@ HOME=/opt/home/$USER /usr/local/bin/python $WORKSPACEDIR/ietf/manage.py check --settings=settings_local +echo "Done!" + # su -p $USER exec "$@" \ No newline at end of file diff --git a/.devcontainer/settings_local.py b/.devcontainer/settings_local.py index 708ac61f9..ca1b0ce6d 100644 --- a/.devcontainer/settings_local.py +++ b/.devcontainer/settings_local.py @@ -5,13 +5,15 @@ import six if six.PY3: from typing import Collection, Dict, List, Tuple # pyflakes:ignore +from ietf.settings import * # pyflakes:ignore + ALLOWED_HOSTS = ['*'] SECRET_KEY = 'jzv$o93h_lzw4a0%0oz-5t5lk+ai=3f8x@uo*9ahu8w4i300o6' DATABASES = { 'default': { - 'HOST': 'localhost', + 'HOST': 'db', 'PORT': 3306, 'NAME': 'ietf_utf8', 'ENGINE': 'django.db.backends.mysql', @@ -61,5 +63,3 @@ SUBMIT_YANG_DRAFT_MODEL_DIR = 'data/developers/ietf-ftp/yang/draftmod/' SUBMIT_YANG_INVAL_MODEL_DIR = 'data/developers/ietf-ftp/yang/invalmod/' SUBMIT_YANG_IANA_MODEL_DIR = 'data/developers/ietf-ftp/yang/ianamod/' SUBMIT_YANG_RFC_MODEL_DIR = 'data/developers/ietf-ftp/yang/rfcmod/' - - diff --git a/.devcontainer/settings_local_debug.py b/.devcontainer/settings_local_debug.py new file mode 100644 index 000000000..4c8a22ce8 --- /dev/null +++ b/.devcontainer/settings_local_debug.py @@ -0,0 +1,33 @@ +# Copyright The IETF Trust 2007-2019, All Rights Reserved +# -*- coding: utf-8 -*- + +from ietf.settings import INSTALLED_APPS, MIDDLEWARE +from ietf.settings_local import * # pyflakes:ignore + +USE_DEBUG_TOOLBAR = True + +INSTALLED_APPS = INSTALLED_APPS + ['debug_toolbar', ] + +MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware', ] + MIDDLEWARE + +LOGGING = { + 'version': 1, + 'filters': { + 'require_debug_true': { + '()': 'django.utils.log.RequireDebugTrue', + } + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'filters': ['require_debug_true'], + 'class': 'logging.StreamHandler', + } + }, + 'loggers': { + 'django.db.backends': { + 'level': 'DEBUG', + 'handlers': ['console'], + } + } +} diff --git a/.vscode/launch.json b/.vscode/launch.json index fb7ccb05a..8176b4395 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,19 @@ "--settings=settings_local" ], "django": true + }, + { + "name": "Run Server with Debug Toolbar", + "type": "python", + "request": "launch", + "python": "/usr/local/bin/python", + "program": "${workspaceFolder}/ietf/manage.py", + "args": [ + "runserver", + "0.0.0.0:8000", + "--settings=settings_local_debug" + ], + "django": true } ] } \ No newline at end of file diff --git a/ietf/group/views.py b/ietf/group/views.py index d41a925f3..8c8cd238d 100644 --- a/ietf/group/views.py +++ b/ietf/group/views.py @@ -39,6 +39,7 @@ import datetime import itertools import io import json +from traceback import print_list import markdown import math import os @@ -63,7 +64,7 @@ import debug # pyflakes:ignore from ietf.community.models import CommunityList, EmailSubscription from ietf.community.utils import docs_tracked_by_community_list -from ietf.doc.models import DocTagName, State, DocAlias, RelatedDocument, Document +from ietf.doc.models import DocTagName, State, DocAlias, RelatedDocument, Document, Person from ietf.doc.templatetags.ietf_filters import clean_whitespace from ietf.doc.utils import get_chartering_type, get_tags_for_stream_id from ietf.doc.utils_charter import charter_name_for_group, replace_charter_of_replaced_group diff --git a/ietf/urls.py b/ietf/urls.py index 91e3920bc..fbf1c1b34 100644 --- a/ietf/urls.py +++ b/ietf/urls.py @@ -9,6 +9,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views import static as static_view from django.views.generic import TemplateView from django.views.defaults import server_error +from django.urls import path import debug # pyflakes:ignore @@ -89,3 +90,10 @@ if settings.SERVER_MODE in ('development', 'test'): urlpatterns += static_url(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) settings.DEBUG = save_debug +# Debug Toolbar +if hasattr(settings, 'USE_DEBUG_TOOLBAR') and settings.USE_DEBUG_TOOLBAR: + try: + import debug_toolbar + path('__debug__/', include(debug_toolbar.urls)), + except ImportError: + pass