diff --git a/.dockerignore b/.dockerignore index 3ea2cacf9..6ffcd0ee3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,14 @@ +.* *.db tags tags.tmp backup* masterdb -pgdata +pgdata* venv +orcid +htmlcov +archive +tests +swagger.json + diff --git a/Dockerfile b/Dockerfile index 54d3d2cb2..be0dd6433 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,6 +92,7 @@ RUN yum -y update \ && rm -rf __db* \ && rpm --rebuilddb \ && yum -y clean all \ + && rm -rf /var/cache/yum \ && rm -rf $HOME/.pip/cache \ && rm -rf /var/cache/*/* /anaconda-post.log \ && rm -f /swagger-codegen-cli.jar /orcid_swagger.json \ diff --git a/Dockerfile.dev b/Dockerfile.dev index aa8efd357..4caa0da88 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -6,26 +6,27 @@ LABEL maintainer="The University of Auckland" \ COPY dev_requirements.txt /dev_requirements.txt ADD https://github.com/zaproxy/zaproxy/releases/download/2.6.0/ZAP_2.6.0_Linux.tar.gz ZAP_Linux.tar.gz -ADD http://anduin.linuxfromscratch.org/BLFS/OpenJDK/OpenJDK-1.8.0.141/OpenJDK-1.8.0.141-x86_64-bin.tar.xz OpenJDK.tar.gz.xz +ADD http://anduin.linuxfromscratch.org/BLFS/OpenJDK/OpenJDK-1.8.0.141/OpenJDK-1.8.0.141-x86_64-bin.tar.xz OpenJDK.tar.xz RUN yum -y update \ && yum -y install install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm \ && yum -y install \ - postgresql96 \ + postgresql96 \ python36u-pip \ git \ - && tar -xzf ZAP_Linux.tar.gz -C /tmp \ - && tar -xf OpenJDK.tar.gz.xz -C /tmp \ - && pip3.6 install -U git+https://github.com/Royal-Society-of-New-Zealand/zap-cli \ + && tar -xzf ZAP_Linux.tar.gz -C /tmp \ + && tar -xf OpenJDK.tar.xz -C /tmp \ + && pip3.6 install -U git+https://github.com/Royal-Society-of-New-Zealand/zap-cli \ && pip3.6 install -U flake8_docstrings pytest-cov coveralls pyyaml \ && pip3.6 install -U -r /dev_requirements.txt \ && cd /var/lib/rpm \ && rm -rf __db* \ && rpm --rebuilddb \ && yum -y clean all \ + && rm -rf /var/cache/yum \ && rm -rf $HOME/.pip/cache \ && rm -rf ZAP_Linux.tar.gz \ - && rm -rf OpenJDK.tar.gz.xz \ + && rm -rf OpenJDK.tar.xz \ && rm -rf /var/cache/*/* /anaconda-post.log /dev_requirements.txt diff --git a/Makefile b/Makefile index 9ca2013f8..ca6fbc083 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME = orcidhub/app -VERSION = 0.16 +VERSION = 0.17 .PHONY: all build test tag_latest diff --git a/application.py b/application.py index 87eb20e90..8db3c6ccc 100644 --- a/application.py +++ b/application.py @@ -11,10 +11,7 @@ from config import * # noqa: F401, F403 from failover import PgDbWithFailover - -# from raven.contrib.flask import Sentry - -##from raven.contrib.flask import Sentry +from raven.contrib.flask import Sentry app = Flask(__name__) app.config.from_object(__name__) @@ -34,7 +31,7 @@ app, name="NZ ORCiD Hub", template_mode="bootstrap3", base_template="admin/master.html") # https://sentry.io/orcid-hub/nz-orcid-hub-dev/getting-started/python-flask/ -# sentry = Sentry(app, dsn=SENTRY_DSN) +sentry = Sentry(app, logging=True, level=logging.DEBUG if ENV == "dev" else logging.ERROR) login_manager = flask_login.LoginManager() login_manager.login_view = "login" diff --git a/authcontroller.py b/authcontroller.py index 9293d4d3b..28f4fe3e6 100644 --- a/authcontroller.py +++ b/authcontroller.py @@ -19,7 +19,8 @@ from urllib.parse import quote, unquote, urlparse import requests -from flask import (abort, current_app, flash, redirect, render_template, request, session, url_for) +from flask import (abort, current_app, flash, g, redirect, render_template, request, session, + url_for) from flask_login import current_user, login_required, login_user, logout_user from flask_mail import Message from oauthlib.oauth2 import rfc6749 @@ -27,7 +28,7 @@ from werkzeug.urls import iri_to_uri import orcid_client -from application import app, db, mail +from application import app, db, mail, sentry from config import (APP_DESCRIPTION, APP_NAME, APP_URL, AUTHORIZATION_BASE_URL, CRED_TYPE_PREMIUM, ENV, EXTERNAL_SP, MEMBER_API_FORM_BASE_URL, NOTE_ORCID, ORCID_API_BASE, ORCID_BASE_URL, ORCID_CLIENT_ID, ORCID_CLIENT_SECRET, SCOPE_ACTIVITIES_UPDATE, @@ -773,9 +774,13 @@ def uoa_slo(): @app.errorhandler(500) def internal_error(error): """Handle internal error.""" - app.logger.exception("Unhandle exception occured.") trace = traceback.format_exc() - return render_template("http500.html", error_message=str(error), trace=trace) + return render_template( + "http500.html", + trace=trace, + error_message=str(error), + event_id=g.sentry_event_id, + public_dsn=sentry.client.get_public_dsn("https")) @app.route("/orcid/login/") diff --git a/backup-db.sh b/backup-db.sh index 946a2c47e..5d04c5f59 100755 --- a/backup-db.sh +++ b/backup-db.sh @@ -4,6 +4,7 @@ TS_LABEL=$(date +%FT%s) PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:$HOME/.local/bin:$HOME/bin:$PATH:/usr/local/bin [ ! -f docker-compose.yml ] && cd $HOME -docker-compose exec -T db psql -U postgres -c "VACUUM FULL ANALYZE; SELECT pg_start_backup('$TS_LABEL', false);" +docker-compose exec -T db psql -U postgres -c "VACUUM FULL ANALYZE;" +docker-compose exec -T db psql -U postgres -c "SELECT pg_start_backup('$TS_LABEL', false);" tar cjf ./backup/$TS_LABEL.tar.bz2 ./pgdata ; mv ./backup/$TS_LABEL.tar.bz2 ./archive/ docker-compose exec -T db psql -U postgres -c "SELECT pg_stop_backup();" diff --git a/docker-compose.yml b/docker-compose.yml index 382f9850a..427fca561 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,6 +33,7 @@ services: - SECRET_KEY - ORCID_CLIENT_ID - ORCID_CLIENT_SECRET + - SENTRY_DSN domainname: orcidhub.org.nz hostname: app ports: diff --git a/requirements.txt b/requirements.txt index b16337f1b..c1739831f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,5 @@ wtf-peewee pycountry html2text tablib +raven +raven[flask] diff --git a/templates/http500.html b/templates/http500.html index 7767bf0b0..743579352 100644 --- a/templates/http500.html +++ b/templates/http500.html @@ -6,11 +6,26 @@
{{trace}}