Skip to content

Commit c6fd883

Browse files
committed
feat: Add environment variables to override common options, closes #498
1 parent 85f3ee3 commit c6fd883

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

docs/config.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ them in order with the latest one taking more priority:
1212
* ``scrapyd.conf``
1313
* ``~/.scrapyd.conf`` (users home directory)
1414

15-
The configuration file supports the following options (see default values in
15+
The configuration file supports the options below (see default values in
1616
the :ref:`example <config-example>`).
1717

18+
The following environment variables override corresponding options:
19+
20+
* ``SCRAPYD_HTTP_PORT`` (``http_port``)
21+
* ``SCRAPYD_BIND_ADDRESS`` (``bind_address``)
22+
* ``SCRAPYD_USERNAME`` (``username``)
23+
* ``SCRAPYD_PASSWORD`` (``password``)
24+
1825
http_port
1926
---------
2027

docs/news.rst

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Release notes
88
Unreleased
99
----------
1010

11+
Added
12+
~~~~~
13+
14+
- Add environment variables to override common options. See :doc:`config`.
15+
1116
Changed
1217
~~~~~~~
1318

scrapyd/app.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23

34
from scrapy.utils.misc import load_object
@@ -16,8 +17,8 @@
1617

1718

1819
def create_wrapped_resource(webcls, config, app):
19-
username = config.get('username', '')
20-
password = config.get('password', '')
20+
username = os.getenv('SCRAPYD_USERNAME') or config.get('username', '')
21+
password = os.getenv('SCRAPYD_PASSWORD') or config.get('password', '')
2122
if ':' in username:
2223
sys.exit("The `username` option contains illegal character ':', "
2324
"check and update the configuration file of Scrapyd")
@@ -35,8 +36,8 @@ def create_wrapped_resource(webcls, config, app):
3536

3637
def application(config):
3738
app = Application("Scrapyd")
38-
http_port = config.getint('http_port', 6800)
39-
bind_address = config.get('bind_address', '127.0.0.1')
39+
http_port = int(os.getenv('SCRAPYD_HTTP_PORT') or config.getint('http_port', 6800))
40+
bind_address = os.getenv('SCRAPYD_BIND_ADDRESS') or config.get('bind_address', '127.0.0.1')
4041
poll_interval = config.getfloat('poll_interval', 5)
4142

4243
poller = QueuePoller(config)

0 commit comments

Comments
 (0)