Status page updated with api version and db version.

This commit is contained in:
Nicholas Staples
2016-01-29 12:51:33 +00:00
parent 2bd244032b
commit 99b849171f
5 changed files with 98 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
import os
import re
import ast
from flask import request, url_for
from flask._compat import string_types
@@ -116,3 +118,22 @@ def convert_to_number(value):
return float(value) if "." in value else int(value)
except (TypeError, ValueError):
return value
def get_api_version():
_version_re = re.compile(r'__version__\s+=\s+(.*)')
version = 'n/a'
dir_path = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(dir_path, 'version.py'), 'rb') as f:
version = str(ast.literal_eval(_version_re.search(
f.read().decode('utf-8')).group(1)))
return version
def get_db_version():
try:
query = 'SELECT version_num FROM alembic_version'
full_name = db.session.execute(query).fetchone()[0]
return full_name.split('_')[0]
except:
return 'n/a'

View File

@@ -6,6 +6,7 @@ status = Blueprint('status', __name__)
@status.route('/_status', methods=['GET', 'POST'])
def show_status():
return jsonify(
status="ok",
), 200
from app import (get_api_version, get_db_version)
return jsonify(status="ok",
api_version=get_api_version(),
db_version=get_db_version()), 200

1
app/version.py Normal file
View File

@@ -0,0 +1 @@
__version__ = '0.1.1'

View File

@@ -4,7 +4,7 @@ from __future__ import print_function
import os
from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand
from app import create_app, db
from app import (create_app, db, get_api_version, get_db_version)
application = create_app(os.getenv('NOTIFY_API_ENVIRONMENT') or 'development')
manager = Manager(application)
@@ -22,5 +22,21 @@ def list_routes():
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
@manager.command
def api_version():
"""
Retrieve the version of the api.
"""
return get_api_version()
@manager.command
def db_version():
"""
Retrieve the db version.
"""
return get_db_version()
if __name__ == '__main__':
manager.run()

55
scripts/push-tag.sh Normal file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
function pretty() {
local blue="\033[34m"
local reset="\033[0m"
while read line; do
echo -e "${blue}[publishing]${reset} ${line}"
done
}
function warn() {
local orange="\033[33m"
local reset="\033[0m"
while read line; do
echo -e "${orange}[warning]${reset} ${line}"
done
}
function get_sha(){
REF=$(git log -n 1 -- VERSION --name-only)
SHA=$(echo $REF | awk '{ print $2 }')
echo "checking out ${SHA}" | pretty
git checkout $SHA
}
function get_version(){
VERSION=$(python setup.py --version)
echo "latest version is ${VERSION}" | pretty
}
function push_tag_or_die(){
TAG_EXISTS=$(git tag | grep -G "^${VERSION}$")
if [ "$TAG_EXISTS" ]; then
echo "Tag already exists, exiting" | warn
exit 0
else
push_tag $VERSION
fi
}
function push_tag(){
git tag -a $VERSION -m "Version tag for ${VERSION}"
echo "Pushing tags to github ${VERSION} to Github" | pretty
git push origin --tags
}
function main(){
get_sha
get_version
push_tag_or_die
}
main