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