-
Notifications
You must be signed in to change notification settings - Fork 537
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
Enable Production Mode via DEBUG or docker-compose.ci.yml #22613
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b108311
TMP: clean bake metadata file
KevinMind 62a0f92
SPLIT: Log UWSGI in docker compose console
KevinMind ae7bb74
SPLIT: Raise error in update_assets if file not found
KevinMind fd952c4
Enable Production mode via DEBUG and or docker-compose.ci.yml
KevinMind 8c09946
Option 1: Load node_modules from statifiles directory
KevinMind d3c0369
Option 2: Load node_modules via django-node-asset
KevinMind e84fc20
separate ./static from locally built static files
KevinMind 06146a4
Add docs for static file serving
KevinMind a12799c
TMP: fixes from code review
KevinMind 6485880
Update docs/topics/development/static-files.md
KevinMind 51018da
TMP: update docs
KevinMind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
services: | ||
web: &web | ||
environment: | ||
- HOST_UID=9500 | ||
volumes: | ||
worker: | ||
environment: | ||
- HOST_UID=9500 | ||
- DEBUG= | ||
volumes: | ||
- /data/olympia | ||
|
||
worker: | ||
<<: *web | ||
web: | ||
extends: | ||
service: worker | ||
volumes: | ||
- data_site_static:/data/olympia/site-static | ||
|
||
nginx: | ||
volumes: | ||
- data_site_static:/srv/site-static | ||
|
||
volumes: | ||
data_olympia: | ||
data_site_static: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ branching | |
vpn | ||
acl | ||
logging | ||
static-files | ||
search | ||
docs | ||
waffle | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Static Files in addons-server | ||
|
||
This document explains how static files are served in the addons-server project during local development. | ||
|
||
## Overview | ||
|
||
addons-server uses a combination of nginx and Django's built-in static file serving capabilities to efficiently serve static files. | ||
These files come from multiple sources: | ||
|
||
1. The `./static` folder in the project | ||
2. Python dependencies | ||
3. npm dependencies | ||
|
||
## Static File Servers | ||
|
||
We use a combination of servers to serve static files: | ||
|
||
1. Nginx | ||
2. Django's built-in development server | ||
|
||
In development, the nginx server will attempt to serve static files from the `./static` directory mounted into the nginx cointainer. | ||
If the file cannot be found there the request is forwarded to django. | ||
Nginx serves our own static files quickly and any vendor files can be fetched from django directly during development. | ||
|
||
In production mode, we mount a data volume both to `web` anb `nginx` containers. | ||
The `web` container exposes the `site-static` directory to nginx that includes the collected static files. | ||
|
||
> In actual production environments, we upload the static files to a cloud bucket and serve them directly from the static path. | ||
|
||
## Static File Sources | ||
|
||
### Project Static Files | ||
|
||
Static files specific to the addons-server project are stored in the `./static` directory. These include CSS, JavaScript, images, and other assets used by the application. | ||
|
||
In reality there are 3 static directories in our docker compose container: | ||
|
||
- `/data/olympia/static`: Contains static files that are mounted directly from the host. | ||
- `/data/olympia/static-build`: Contains static files that are built by `compress_assets`. | ||
- `/data/olympia/site-static`: Contains static files that are collected by the `collectstatic` command. | ||
|
||
The only of these directories that is exposed to your host is the `./static` directory. | ||
|
||
### Compressing Static Files | ||
|
||
We currently use a `ducktape` script to compress our static files. | ||
Ideally we would migrate to a modern tool to replace manual scripting, but for now this works. | ||
|
||
Assets are compressed automatically during the docker build, but if you need to manually update files while developing, | ||
the easiest way is to run `make update_assets` which will compress and concatenate static assets as well as collect all static files | ||
to the `site-static` directory. | ||
|
||
### Python Dependencies | ||
|
||
Some Python packages include their own static files. These assets are collected by the `collectstatic` command and included in the final static files directory. | ||
During development they are served by the django development server. | ||
|
||
### npm Dependencies | ||
|
||
We have a (complex) set of npm static assets that are built by the `compress_assets` management command. | ||
During development, these assets are served directly from the node_modules directory using a custom static finder. | ||
|
||
## DEBUG Property and Static File Serving | ||
|
||
The behavior of static file serving can be controlled using the `DEBUG` environment variable or via setting it directly in | ||
the `local_settings.py` file. Be careful directly setting this value, if DEBUG is set to false, and you don't have sufficient | ||
routing setup to serve files fron nginx only, it can cause failure to serve some static files. | ||
|
||
It is best to use the compose file to control DEBUG.a | ||
|
||
This is set in the environment, and in CI environments, it's controlled by the `docker-compose.ci.yml` file. | ||
KevinMind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The `DEBUG` property is what is used by django to determine if it should serve static files or not. In development, | ||
you can manually override this in the make up command, but in general, you should rely on the `docker-compose.ci.yml` file | ||
to set the correct value as this will also set appropriate file mounts. | ||
|
||
```bash | ||
make up COMPOSE_FILE=docker-compose.yml:docker-compose.ci.yml | ||
``` | ||
|
||
This will run addons-server in production mode, serving files from the `site-static` directory. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing me - Why not keep
/srv/static
(and keeping the oldalias
directive intact inaddons.conf
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we mount either "./static" or "/data/olympia/site-static" depending on which set of compose files you use.
As far as nginx is concerned it serves from one location but the source of the files changes.