Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated settings and requirements to fix deployment issues #447

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

blarghmatey
Copy link
Member

What are the relevant tickets?

#138

What's this PR do?

The file parsing available in uWSGI has a hardcoded line limit which was causing problems with managing the certificate strings via the env file. Added a block to read in the env file and set environment variables automatically as part of settings.py to work around that issue.

Removed the -e flags from the git dependencies so that they get installed to the dist-packages directory instead of the home directory of the user that runs the pip command. This was causing issues with being able to import those packages at runtime.

Added the option to set the celery broker separately from the results backend in order to allow for using RabbitMQ in place of Redis.

How should this be manually tested?

Ensure that the app will start properly with an env file formatted as ENV_VAR=value with no export prefix.

Where should the reviewer start?

odl_video/settings.py and requirements.txt

What GIF best describes this PR or how it makes you feel?

@mbertrand mbertrand self-assigned this Feb 23, 2018
@blarghmatey blarghmatey force-pushed the celery_broker_update branch 2 times, most recently from a04410a to c37d9ef Compare February 23, 2018 20:41
with open(f'{BASE_DIR}/.env') as envsettings:
for line in envsettings:
k, v = line.rstrip('\n').lstrip('export ').split('=', maxsplit=1)
os.environ.setdefault(k=v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws an error: TypeError: setdefault() got an unexpected keyword argument 'k'

This works: os.environ.setdefault(k, v)

@codecov-io
Copy link

codecov-io commented Feb 23, 2018

Codecov Report

Merging #447 into master will decrease coverage by 0.03%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #447      +/-   ##
==========================================
- Coverage   95.27%   95.24%   -0.04%     
==========================================
  Files         136      136              
  Lines        4633     4643      +10     
  Branches      191      192       +1     
==========================================
+ Hits         4414     4422       +8     
- Misses        179      181       +2     
  Partials       40       40
Impacted Files Coverage Δ
odl_video/envs.py 96.72% <75%> (-3.28%) ⬇️
odl_video/settings.py 82.82% <75%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cadbcb3...3c5b5c0. Read the comment docs.

@@ -488,7 +497,7 @@
},
'redis': {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": CELERY_BROKER_URL,
"LOCATION": REDIS_URL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CELERY_BROKER_URL will default to REDIS_URL if the env. variable isn't set, so maybe it might be best to not change this line, @noisecapella do you want to weigh in? That seems to be the pattern used in open-discussions & micromasters as well:

CELERY_BROKER_URL = get_string("CELERY_BROKER_URL", REDIS_URL)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Giovanni added that line in a commit to add mandatory settings, I don't think REDIS_URL has any special meaning to Celery or django-redis. I think the change here makes sense to keep the celery redis broker separate from the redis cache Django

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbertrand if we leave it as is and the CELERY_BROKER_URL gets set to something other than a Redis protocol then that would break the cache config. That's why I broke them out to be separate settings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good to me then

@@ -21,6 +21,14 @@

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a function and write tests for it?

@@ -488,7 +497,7 @@
},
'redis': {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": CELERY_BROKER_URL,
"LOCATION": REDIS_URL,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Giovanni added that line in a commit to add mandatory settings, I don't think REDIS_URL has any special meaning to Celery or django-redis. I think the change here makes sense to keep the celery redis broker separate from the redis cache Django

@blarghmatey blarghmatey force-pushed the celery_broker_update branch 5 times, most recently from 648d89f to f55619d Compare February 26, 2018 20:35


def test_parse_env():
testpath = 'testenv.txt'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a TemporaryFile here or put it into a temporary directory? If it's not done with a context manager or something we should also put the os.remove in a finally block

def test_parse_env():
testpath = 'testenv.txt'
with open(testpath, 'w') as testfile:
testfile.write('FOO_VAR=bar_var\nFOO_NUM=42')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change one of the lines to include an "export ", and have one of the values include its own = sign?

@blarghmatey blarghmatey force-pushed the celery_broker_update branch 5 times, most recently from e2c2359 to 1aa25c5 Compare February 27, 2018 15:29
duplicating across multiple locations and not requiring explicit
sourcing.

:param env_file: path to a file consisting of key=value pairs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blarghmatey The typical format looks like this, can you change it? Otherwise looks good!

The file parsing available in uWSGI has a hardcoded line limit which was causing problems with managing the certificate strings via the env file. Added a block to read in the env file and set environment variables automatically as part of settings.py to work around that issue.

Removed the `-e` flags from the git dependencies so that they get installed to the `dist-packages` directory instead of the home directory of the user that runs the pip command. This was causing issues with being able to import those packages at runtime.

Added the `no-binary` flag for psycopg2 due to issues with how the wheel is linked to OpenSSL for Debian 9 (unbit/uwsgi#1569)

Added the option to set the celery broker separately from the results backend in order to allow for using RabbitMQ in place of Redis.
@blarghmatey blarghmatey merged commit c14046b into master Feb 27, 2018
@blarghmatey blarghmatey deleted the celery_broker_update branch February 27, 2018 16:49
@mbertrand mbertrand mentioned this pull request Mar 14, 2018
@mbertrand mbertrand mentioned this pull request Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants