Skip to content

Commit

Permalink
feat: Add environment variables to override common options, closes #498
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed May 31, 2024
1 parent 85f3ee3 commit c6fd883
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <config-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
---------

Expand Down
5 changes: 5 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Release notes
Unreleased
----------

Added
~~~~~

- Add environment variables to override common options. See :doc:`config`.

Changed
~~~~~~~

Expand Down
9 changes: 5 additions & 4 deletions scrapyd/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

from scrapy.utils.misc import load_object
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit c6fd883

Please sign in to comment.