Skip to content

Commit

Permalink
Merge pull request #9 from RegioneER/app_config
Browse files Browse the repository at this point in the history
Config app by environment variables
  • Loading branch information
cekk authored Apr 24, 2024
2 parents dd144de + 9fee706 commit 22f994a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
bin/
buildout-cache/
buildout.cfg
config.py
develop-eggs/
eggs/
etc/
Expand Down
13 changes: 6 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ And it will start and manage all services.
Custom configurations
---------------------

You can add a ``config.py`` file in the root of the application to add custom configuration for Flask app.
You can add a custom configuration for Flask app by adding the environments variables

For example if you want to addcustomize Flask-Mail mail server address (default is localhost), you can create a file like this::
For example if you want to customize Flask-Mail mail server address (default is localhost), you can create this environment variable::

Class Config(object):
MAIL_SERVER = 'my.custom.server'
export RER_NEWSLETTERDISPATCHER_MAIL_SERVER="myserver.net"

You can set base Flask config parameters and some application-related ones:

- MAIL_SERVER (mailserver address)
- SENTRY_DSN (sentry dsn value)
- REDIS_PORT (port where redis should listen. Default is 6379 but it's better to change it)
- RER_NEWSLETTERDISPATCHER_MAIL_SERVER (mailserver address)
- RER_NEWSLETTERDISPATCHER_SENTRY_DSN (sentry dsn value)
- RER_NEWSLETTERDISPATCHER_REDIS_PORT (port where redis should listen. Default is 6379 but it's better to change it)


Custom buildout configurations
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_app(debug=True):
format="[%(asctime)s] %(levelname)s - %(message)s",
)
try:
app.config.from_object("config.Config")
app.config.from_pyfile("config.py")
except ImportStringError:
logger.error("No config.py file found. Starting with standard configuration.")

Expand Down
1 change: 0 additions & 1 deletion base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ eggs =
rq
sentry-sdk[flask]
raven

11 changes: 11 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
import os

MAIL_SERVER = os.environ.get("RER_NEWSLETTERDISPATCHER_MAIL_SERVER", default="")
SENTRY_DSN = os.environ.get("RER_NEWSLETTERDISPATCHER_SENTRY_DSN", default="")
MAIL_PORT = os.environ.get("RER_NEWSLETTERDISPATCHER_MAIL_PORT", default=25)
MAIL_USERNAME = os.environ.get("RER_NEWSLETTERDISPATCHER_MAIL_USERNAME", default="")
MAIL_PASSWORD = os.environ.get("RER_NEWSLETTERDISPATCHER_MAIL_PASSWORD", default="")

# NOTE: Redis default port is 6379
REDIS_PORT = os.environ.get("RER_NEWSLETTERDISPATCHER_REDIS_PORT", default="6379")

0 comments on commit 22f994a

Please sign in to comment.