diff --git a/docs/config.rst b/docs/config.rst index f07105c6..8e7fd34d 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -12,9 +12,16 @@ them in order with the latest one taking more priority: * ``scrapyd.conf`` * ``~/.scrapyd.conf`` (users home directory) -The configuration file supports the following options (see default values in +The configuration file supports the options below (see default values in the :ref:`example `). +The following environment variables override corresponding options: + +* ``SCRAPYD_HTTP_PORT`` (``http_port``) +* ``SCRAPYD_BIND_ADDRESS`` (``bind_address``) +* ``SCRAPYD_USERNAME`` (``username``) +* ``SCRAPYD_PASSWORD`` (``password``) + http_port --------- diff --git a/docs/news.rst b/docs/news.rst index f7b86eb1..be748f34 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -8,6 +8,11 @@ Release notes Unreleased ---------- +Added +~~~~~ + +- Add environment variables to override common options. See :doc:`config`. + Changed ~~~~~~~ diff --git a/scrapyd/app.py b/scrapyd/app.py index 4b784718..9ca6eecc 100644 --- a/scrapyd/app.py +++ b/scrapyd/app.py @@ -1,3 +1,4 @@ +import os import sys from scrapy.utils.misc import load_object @@ -16,8 +17,8 @@ def create_wrapped_resource(webcls, config, app): - username = config.get('username', '') - password = config.get('password', '') + username = os.getenv('SCRAPYD_USERNAME') or config.get('username', '') + password = os.getenv('SCRAPYD_PASSWORD') or config.get('password', '') if ':' in username: sys.exit("The `username` option contains illegal character ':', " "check and update the configuration file of Scrapyd") @@ -35,8 +36,8 @@ def create_wrapped_resource(webcls, config, app): def application(config): app = Application("Scrapyd") - http_port = config.getint('http_port', 6800) - bind_address = config.get('bind_address', '127.0.0.1') + http_port = int(os.getenv('SCRAPYD_HTTP_PORT') or config.getint('http_port', 6800)) + bind_address = os.getenv('SCRAPYD_BIND_ADDRESS') or config.get('bind_address', '127.0.0.1') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config)