Adds __version__ route (closes #53).

This commit is contained in:
Chuck Harmston 2016-02-26 13:36:02 -07:00
Родитель e1b6e759d8
Коммит b6f32ca368
7 изменённых файлов: 32 добавлений и 4 удалений

Просмотреть файл

Просмотреть файл

@ -14,8 +14,10 @@ dependencies:
# day to keep the cache size down.
- I="image-$(date +%j).tgz"; if [[ -e ~/docker/$I ]]; then echo "Loading $I"; gunzip -c ~/docker/$I | docker load; fi
# Create a version.json file for the app to serve.
- printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s"}\n' "$CIRCLE_SHA1" "$CIRCLE_TAG" "$CIRCLE_PROJECT_USERNAME" "$CIRCLE_PROJECT_REPONAME" > version.json
# Create a version.json file for the app to serve; copy it to the CircleCI
# artifacts directory for debugging.
- printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s"}\n' "$CIRCLE_SHA1" "`python -c 'from recommendation import VERSION;print(VERSION)'`" "$CIRCLE_PROJECT_USERNAME" "$CIRCLE_PROJECT_REPONAME" > recommendation/static/version.json
- cp recommendation/static/version.json $CIRCLE_ARTIFACTS
# build the actual deployment container
- docker build -t app:build .

Просмотреть файл

@ -0,0 +1 @@
VERSION = "0.1.0"

Просмотреть файл

@ -0,0 +1,5 @@
{
"commit": null,
"version": null,
"source": null
}

Просмотреть файл

@ -1,13 +1,21 @@
from os import path
from celery.app.control import Control
from flask import abort, Blueprint
from flask import abort, Blueprint, send_file
from redis.exceptions import ConnectionError as RedisConnectionError
from recommendation.memcached import memcached
from recommendation.views.static import STATIC_DIR
status = Blueprint('status', __name__)
@status.route('/__version__')
def version():
return send_file(path.join(STATIC_DIR, 'version.json'))
@status.route('/__lbheartbeat__')
def lbheartbeat():
return ('', 200)

Просмотреть файл

@ -1,7 +1,11 @@
import json
from os import path
from mock import patch
from nose.tools import eq_, ok_
from redis.exceptions import ConnectionError as RedisError
from recommendation.views.static import STATIC_DIR
from recommendation.views.status import (celery_status, memcached_status,
redis_status, ServiceDown)
from recommendation.tests.util import AppTestCase
@ -28,6 +32,12 @@ MEMCACHED_PING_OK = [MEMCACHED_CLUSTER_OK, MEMCACHED_CLUSTER_OK]
class TestStatusViews(AppTestCase):
def test_version(self):
response = self.client.get('/__version__')
eq_(response.status_code, 200)
with open(path.join(STATIC_DIR, 'version.json')) as file_data:
eq_(json.load(file_data), response.json)
def test_lbheartbeat(self):
response = self.client.get('/__lbheartbeat__')
eq_(response.status_code, 200)

Просмотреть файл

@ -2,6 +2,8 @@ import os
from setuptools import setup, find_packages
from recommendation import VERSION
__dirname = os.path.abspath(os.path.dirname(__file__))
@ -11,7 +13,7 @@ with open(os.path.join(__dirname, 'README.md')) as readme:
setup(
name='universal-search-recommendation',
version='0.1.0',
version=VERSION,
description='Universal Search recommendation server.',
long_description=README,
classifiers=[