Cache the status tags and fix the tag for images that were pushed from a build.
This commit is contained in:
parent
270a62b8c1
commit
638dbb3d8d
2 changed files with 21 additions and 13 deletions
24
config.py
24
config.py
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import logstash_formatter
|
||||
import requests
|
||||
import os.path
|
||||
|
||||
from peewee import MySQLDatabase, SqliteDatabase
|
||||
from storage.s3 import S3Storage
|
||||
|
@ -205,9 +206,18 @@ class LargePoolHttpClient(object):
|
|||
HTTPCLIENT = build_requests_session()
|
||||
|
||||
|
||||
class StatusTagConfig(object):
|
||||
STATUS_TAGS = {}
|
||||
|
||||
for tag_name in ['building', 'failed', 'none', 'ready']:
|
||||
tag_path = os.path.join('buildstatus', tag_name + '.svg')
|
||||
with open(tag_path) as tag_svg:
|
||||
STATUS_TAGS[tag_name] = tag_svg.read()
|
||||
|
||||
|
||||
class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles,
|
||||
FakeAnalytics, StripeTestConfig, RedisBuildLogs,
|
||||
UserEventConfig, LargePoolHttpClient):
|
||||
UserEventConfig, LargePoolHttpClient, StatusTagConfig):
|
||||
LOGGING_CONFIG = logs_init_builder(logging.WARN)
|
||||
POPULATE_DB_TEST_DATA = True
|
||||
TESTING = True
|
||||
|
@ -218,7 +228,8 @@ class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles,
|
|||
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
||||
StripeTestConfig, MixpanelTestConfig, GitHubTestConfig,
|
||||
DigitalOceanConfig, BuildNodeConfig, S3Userfiles,
|
||||
UserEventConfig, TestBuildLogs, LargePoolHttpClient):
|
||||
UserEventConfig, TestBuildLogs, LargePoolHttpClient,
|
||||
StatusTagConfig):
|
||||
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
||||
SEND_FILE_MAX_AGE_DEFAULT = 0
|
||||
POPULATE_DB_TEST_DATA = True
|
||||
|
@ -230,7 +241,8 @@ class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,
|
|||
StripeLiveConfig, MixpanelTestConfig,
|
||||
GitHubProdConfig, DigitalOceanConfig,
|
||||
BuildNodeConfig, S3Userfiles, RedisBuildLogs,
|
||||
UserEventConfig, LargePoolHttpClient):
|
||||
UserEventConfig, LargePoolHttpClient,
|
||||
StatusTagConfig):
|
||||
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
||||
SEND_FILE_MAX_AGE_DEFAULT = 0
|
||||
URL_SCHEME = 'http'
|
||||
|
@ -241,8 +253,7 @@ class StagingConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL,
|
|||
StripeLiveConfig, MixpanelProdConfig,
|
||||
GitHubStagingConfig, DigitalOceanConfig, BuildNodeConfig,
|
||||
S3Userfiles, RedisBuildLogs, UserEventConfig,
|
||||
LargePoolHttpClient):
|
||||
|
||||
LargePoolHttpClient, StatusTagConfig):
|
||||
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
||||
SEND_FILE_MAX_AGE_DEFAULT = 0
|
||||
URL_SCHEME = 'https'
|
||||
|
@ -253,8 +264,7 @@ class ProductionConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL,
|
|||
StripeLiveConfig, MixpanelProdConfig,
|
||||
GitHubProdConfig, DigitalOceanConfig, BuildNodeConfig,
|
||||
S3Userfiles, RedisBuildLogs, UserEventConfig,
|
||||
LargePoolHttpClient):
|
||||
|
||||
LargePoolHttpClient, StatusTagConfig):
|
||||
LOGGING_CONFIG = logs_init_builder()
|
||||
SEND_FILE_MAX_AGE_DEFAULT = 0
|
||||
URL_SCHEME = 'https'
|
||||
|
|
|
@ -20,6 +20,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
web = Blueprint('web', __name__)
|
||||
|
||||
STATUS_TAGS = app.config['STATUS_TAGS']
|
||||
|
||||
@web.route('/', methods=['GET'], defaults={'path': ''})
|
||||
@web.route('/organization/<path:path>', methods=['GET'])
|
||||
|
@ -211,7 +212,6 @@ def build_status_badge(namespace, repository):
|
|||
abort(404)
|
||||
|
||||
# Lookup the tags for the repository.
|
||||
tags = model.list_repository_tags(namespace, repository)
|
||||
|
||||
# Lookup the current/recent build.
|
||||
status = 'none'
|
||||
|
@ -220,16 +220,14 @@ def build_status_badge(namespace, repository):
|
|||
if build.phase == 'error':
|
||||
status = 'failed'
|
||||
elif build.phase == 'complete':
|
||||
pass
|
||||
status = 'ready'
|
||||
else:
|
||||
status = 'building'
|
||||
else:
|
||||
tags = model.list_repository_tags(namespace, repository)
|
||||
if list(tags):
|
||||
status = 'ready'
|
||||
|
||||
with open(os.path.join(app.root_path, 'buildstatus', status + '.svg')) as f:
|
||||
svg = f.read()
|
||||
|
||||
response = make_response(svg)
|
||||
response = make_response(STATUS_TAGS[status])
|
||||
response.content_type = 'image/svg+xml'
|
||||
return response
|
||||
|
|
Reference in a new issue