From a753bf68dc2c94a37116acc97058848c6855d3d9 Mon Sep 17 00:00:00 2001 From: nothink Date: Thu, 26 Jul 2018 00:05:10 +0900 Subject: [PATCH] Check Travis-CI env --- .travis.yml | 5 ++++- server/szurubooru/config.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 29aedd79..a54c7e82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ matrix: - language: python python: - "3.5" + - "3.6" before_install: - sudo apt-get -y install software-properties-common - sudo add-apt-repository -y ppa:mc3man/trusty-media @@ -32,7 +33,9 @@ matrix: - pip install -r requirements.txt - pip install -r dev-requirements.txt script: -# - pycodestyle szurubooru/ + - pycodestyle wait-for-es + - pycodestyle generate-thumb + - pycodestyle szurubooru/ - ./wait-for-es - alembic upgrade head - py.test diff --git a/server/szurubooru/config.py b/server/szurubooru/config.py index c23eacf0..c0e4605a 100644 --- a/server/szurubooru/config.py +++ b/server/szurubooru/config.py @@ -16,12 +16,43 @@ def merge(left: Dict, right: Dict) -> Dict: return left +def docker_config() -> Dict: + for key in [ + 'POSTGRES_USER', + 'POSTGRES_PASSWORD', + 'POSTGRES_HOST', + 'ESEARCH_HOST' + ]: + if not os.getenv(key, False): + raise errors.ConfigError(f'Environment variable "{key}" not set') + return { + 'debug': True, + 'show_sql': int(os.getenv('LOG_SQL', 0)), + 'data_url': os.getenv('DATA_URL', '/data/'), + 'data_dir': '/data/', + 'database': 'postgres://%(user)s:%(pass)s@%(host)s:%(port)d/%(db)s' % { + 'user': os.getenv('POSTGRES_USER'), + 'pass': os.getenv('POSTGRES_PASSWORD'), + 'host': os.getenv('POSTGRES_HOST'), + 'port': int(os.getenv('POSTGRES_PORT', 5432)), + 'db': os.getenv('POSTGRES_DB', os.getenv('POSTGRES_USER')) + }, + 'elasticsearch': { + 'host': os.getenv('ESEARCH_HOST'), + 'port': int(os.getenv('ESEARCH_PORT', 9200)), + 'index': os.getenv('ESEARCH_INDEX', 'szurubooru') + } + } + + def read_config() -> Dict: with open('../config.yaml.dist') as handle: ret = yaml.load(handle.read()) if os.path.exists('../config.yaml'): with open('../config.yaml') as handle: ret = merge(ret, yaml.load(handle.read())) + if os.path.exists('/.dockerenv') and not os.getenv(CI, False): + ret = merge(ret, docker_config()) return ret