Closed Bug 1391125 Opened 7 years ago Closed 7 years ago

fix staticfiles in webapp image so they work with server environment

Categories

(Socorro :: General, task)

task
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: willkg, Unassigned)

References

Details

When the webapp Docker image is built, it runs "manage.py collectstatic" to generate all the static files and puts them in /app/webapp-django/static/ inside the image.

The problem is that the webapp nodes will run nginx on the host which connects to uwsgi in the Docker container and nginx doesn't have access to the static files which are in the Docker container.

This bug covers figuring out how we want to deal with that and implementing the necessary bits.
Miles mentioned a couple of options:

1. during deploy, he can copy the files from the container to the host to serve them with nginx

2. we could use the whitenoise lib and serve the files via Django from inside the container


Are there other viable options?
3. run two webapp containers, one running django, one running nginx

Of these, I like 2 (whitenoise) the best because it pulls this behavior out of deployment code and into the app.
I had forgotten that Standup uses whitenoise, so I've used it before and set it up. Plus I'm pretty sure we use it in other places at Mozilla. I wonder if we'll hit issues trying to use whitenoise and support our RPM/server environment, Docker-based local dev environment, and Docker-based server environment.

Anyhow, I'm inclined to vote for that option until we hit something that makes it difficult because the other two options add another difference between server and local dev.

If Peter gets to this in the next two weeks, that's cool. If not, I can take a stab at it.
Blocks: 1397534
Peter did this PR which landed today: https://github.com/mozilla-services/socorro/pull/3989

That adds whitenoise. So we might be all set with this now.

Tagging Miles to test it with his parallel dimension infrastructure.
Flags: needinfo?(miles)
I tested a new deploy of the parallel dimension infra, getting this:

Sep 15 21:27:04 ip-172-31-54-171 docker[13578]: [pid: 12|app: 0|req: 3/6] 127.0.0.1 () {24 vars in 284 bytes} [Fri Sep 15 21:27:01 2017] GET /__heartbeat__ => generated 0 bytes in 3065 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Sep 15 21:27:56 ip-172-31-54-171 docker[13578]: [pid: 13|app: 0|req: 3/7] 127.0.0.1 () {48 vars in 798 bytes} [Fri Sep 15 21:27:53 2017] GET / => generated 0 bytes in 3026 msecs (HTTP/1.1 302) 6 headers in 570 bytes (1 switches on core 0)
Sep 15 21:28:03 ip-172-31-54-171 docker[13578]: [pid: 16|app: 0|req: 1/8] 127.0.0.1 () {42 vars in 672 bytes} [Fri Sep 15 21:28:00 2017] GET /favicon.ico => generated 1150 bytes in 3399 msecs via sendfile() (HTTP/1.1 200) 7 headers in 570 bytes (0 switches on core 0)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: Traceback (most recent call last):
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: response = self.get_response(request)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 175, in get_response
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: response = self.get_exception_response(request, resolver, 404)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 90, in get_exception_response
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 268, in handle_uncaught_exception
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return callback(request, **param_dict)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/app/webapp-django/crashstats/base/views.py", line 16, in handler500
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return render(request, '500.html', context, status=500)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/shortcuts.py", line 67, in render
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: template_name, context, request=request, using=using)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/template/loader.py", line 99, in render_to_string
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return template.render(context, request)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django_jinja/backend.py", line 105, in render
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return self.template.render(context)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return self.environment.handle_exception(exc_info, True)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: reraise(exc_type, exc_value, tb)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/app/webapp-django/crashstats/base/jinja2/500.html", line 1, in top-level template code
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: {% extends "error.html" %}
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/app/webapp-django/crashstats/base/jinja2/error.html", line 6, in top-level template code
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: {% block site_css %}
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/app/webapp-django/crashstats/base/jinja2/error.html", line 7, in block "site_css"
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: {% stylesheet 'crashstats_base' %}
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/pipeline/jinja2/__init__.py", line 37, in package_css
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return self.render_compressed(package, package_name, 'css')
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/pipeline/templatetags/pipeline.py", line 69, in render_compressed
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: package_type)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/pipeline/templatetags/pipeline.py", line 82, in render_compressed_output
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: return method(package, package.output_filename)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/pipeline/jinja2/__init__.py", line 44, in render_css
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: 'url': staticfiles_storage.url(path)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 131, in url
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: hashed_name = self.stored_name(clean_name)
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 280, in stored_name
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: cache_name = self.clean_name(self.hashed_name(name))
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: File "/usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 94, in hashed_name
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: (clean_name, self))
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: ValueError: The file 'css/crashstats-base.min.css' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x7f53c9beaed0>.
Sep 15 21:28:04 ip-172-31-54-171 docker[13578]: [pid: 12|app: 0|req: 4/9] 127.0.0.1 () {24 vars in 284 bytes} [Fri Sep 15 21:28:01 2017] GET /__heartbeat__ => generated 0 bytes in 3040 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

Looks like a successful request to the favicon, failures for the heartbeat, and a big fat traceback for css. Kicking this back your way :willkg (because :peterbe is gone-zo), what do you think is up with this?
Flags: needinfo?(miles) → needinfo?(willkg)
OK, doing some preliminary spelunking. Looks like $STATIC_ROOT was set to "/app/webapp_django/static" instead of "/app/webapp-django/static". Correcting that to start.
Aaaand that seems like it was it. https://socorro.stage.mozaws.net/home/product/Firefox CHECK IT OUT!

We're just waiting on elasticsearch now. I'm having some really obnoxious struggles with it right now - namely that the NAT instance refuses to deploy and I'm waiting on AWS support to help because the error is opaque (VolumeLimit, even when I just requested and was granted an increase to what I think is the relevant limit).

Sorry for the premature needinfo!
Flags: needinfo?(willkg)
No worries!

Is that STATIC_ROOT set in config files in the Socorro repo or somewhere else? If it's somewhere else, you can nix that setting altogether since it defaults to "/app/webapp-django/static".

A while back you and I talked about building a config file for the -stage environment, but you said I should wait on doing that, so I haven't worked on that. Is that something that's helpful now? If so, I can work on it next week.
OK, I will unset that env var in my configuration. Thanks!
Miles: Is this all set or are there still outstanding bits to be done?
Flags: needinfo?(miles)
As far as I can tell this is all set. Marking this fixed.
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: needinfo?(miles)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.