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

Add static #65

Closed
wants to merge 1 commit into from
Closed

Add static #65

wants to merge 1 commit into from

Conversation

time-less-ness
Copy link
Contributor

I had to run the demo and just randomly go to various pages, examine source, and pull out any CSS, JS, or PNG assets I found. I couldn't list directories, so couldn't get an exhaustive list.

This was after I spent a few hours trying to figure out how to make Django collect static assets. I could never succeed in that. Some Django doc claimed if I did django-admin collectstatic (or something like that) it'd do it.

So I installed Django, ran the command, and couldn't get past finally:

:) django-admin help

Type 'django-admin help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly configured (error: No module named 'slackclient').

There is also obviously nothing about collecting static resources in that list of commands.

@time-less-ness
Copy link
Contributor Author

Note that this PR is part of my efforts at creating a k8s version of this, which requires a static container image. If I can get this working, eventually I'll publish my modified Helm charts that generate the k8s objects, including a ingress --> svc --> pod chain that doesn't quite configure GCE load balancers healthchecks properly.

@milesbxf
Copy link
Contributor

Hey Phil 👋

Thanks for your efforts here. From what I understand, you're having a similar issue to #51 in that you'd like to serve static files using another webserver, and need to put these files somewhere.

You were pretty close with the command, but the script you actually want to run is python manage.py collectstatic, which gathers all static assets and puts them in a single directory, which looks exactly what you'd like:

$ python manage.py collectstatic
 WARNING - workflow   - This will error before workflow migration has been completed (first run)
no such table: response_workflow

152 static files copied to '~/src/github.com/monzo/monzo-incident/static'.

I think we'd be reluctant to vendor these files as part of the repository itself, as they're somewhat dynamic and liable to change (especially if a user customises them), and vendoring would mean we'd need an extra step on every PR to make sure we keep files in sync.

As for a static Docker container in the docker-compose.yml file, we're currently in the process of migrating this repository to a standalone Django app that users can import as a PyPI dependency into their own Django app, which should make it much easier to customise....most users (including ourselves) are currently working with private forks, which are a bit of a pain to keep up to date.

In #57 we moved the docker-compose setup into a demo app, which is intended as a local demonstration using the Django development server, so I'm not sure we'd want a separate nginx container for static files. We definitely should publish some guidance for deploying response to production, and Helm charts will definitely help with that 🙂 feel free to raise any more questions as issues 👍

@time-less-ness
Copy link
Contributor Author

100% of what I'm doing is trying to "productionise" this, so anything you do to make that possible I'll be extremely excited to hear about. I don't mind if this PR isn't accepted, but putting what you wrote into the docs so no-one else has to spend 3hr collecting assets from the demo app by examining page source would be kind!

And also, giving an example of how to generate a static container would also be kind.

Basically, I wish this PR had existed Friday of last week for me to steal ideas from.

Finally,

:) python manage.py collectstatic
  File "manage.py", line 15
    ) from exc
         ^
SyntaxError: invalid syntax

@time-less-ness
Copy link
Contributor Author

Ah, Python 2 vs 3. Still, in 3...

:) python3.7 manage.py collectstatic
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 204, in fetch_command
    app_name = commands[subcommand]
KeyError: 'collectstatic'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 20, in <module>
    main()
  File "manage.py", line 16, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 211, in fetch_command
    settings.INSTALLED_APPS
  File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/tim.ellis/Dev/response/response/settings/prod.py", line 1, in <module>
    from .base import *
  File "/Users/tim.ellis/Dev/response/response/settings/base.py", line 15, in <module>
    from slackclient import SlackClient
ModuleNotFoundError: No module named 'slackclient'

So, basically, same problem as running Django directly. It can't figure out slackclient.

@milesbxf
Copy link
Contributor

100% of what I'm doing is trying to "productionise" this, so anything you do to make that possible I'll be extremely excited to hear about. I don't mind if this PR isn't accepted, but putting what you wrote into the docs so no-one else has to spend 3hr collecting assets from the demo app by examining page source would be kind!

As I've said above, at some point we'll be writing some docs with guidance for deploying to production, and the ideas you've got here are useful 👍

However in future I'd definitely suggest raising a Github issue with problems like these first - that way we can discuss the approach before committing to any potentially wasted work.

Ah, Python 2 vs 3. Still, in 3...

Hmm, that's probably worth documenting too - we're consciously only supporting Python 3.6 for the moment (the new django-incident-response PyPI package enforces this)

So, basically, same problem as running Django directly. It can't figure out slackclient.

slackclient is one of (many) dependencies - you'll want to pip install -r requirements.txt. The startup.sh script should show what's needed to run the dev server locally

@milesbxf
Copy link
Contributor

I'm going to close this anyhow. If you have any more trouble setting things up, please raise an issue and I'll get back to you 🙂

@milesbxf milesbxf closed this Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants