Skip to content

Commit

Permalink
Server javascript catalog dynamically in DEV_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Oct 9, 2024
1 parent d3c1ba6 commit 94e00bb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ jobs:
-
name: Needs Locale Compilation
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: |
make compile_locales
make update_assets
make test_needs_locales_compilation
-
name: Static Assets
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: |
make update_assets
make test_static_assets
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ ENV DOCKER_VERSION=${DOCKER_VERSION}
COPY docker/etc/mime.types /etc/mime.types
# Copy the rest of the source files from the host
COPY --chown=olympia:olympia . ${HOME}
# Copy assets from assets
COPY --from=assets --chown=olympia:olympia ${HOME}/site-static ${HOME}/site-static
COPY --from=assets --chown=olympia:olympia ${HOME}/static-build ${HOME}/static-build

# Set shell back to sh until we can prove we can use bash at runtime
SHELL ["/bin/sh", "-c"]
Expand All @@ -196,6 +193,9 @@ FROM sources AS production

# Copy compiled locales from builder
COPY --from=locales --chown=olympia:olympia ${HOME}/locale ${HOME}/locale
# Copy assets from assets
COPY --from=assets --chown=olympia:olympia ${HOME}/site-static ${HOME}/site-static
COPY --from=assets --chown=olympia:olympia ${HOME}/static-build ${HOME}/static-build
# Copy dependencies from `pip_production`
COPY --from=pip_production --chown=olympia:olympia /deps /deps

Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ services:
]
volumes:
- data_olympia:/data/olympia
# Don't mount generated files. They only exist in the container
# and would otherwiser be deleted by mounbting data_olympia
- /data/olympia/static-build
- /data/olympia/site-static
- storage:/data/olympia/storage
- ./package.json:/deps/package.json
- ./package-lock.json:/deps/package-lock.json
Expand Down
20 changes: 0 additions & 20 deletions docs/topics/development/static-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,3 @@ During development they are served by the django development server.

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.

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.
2 changes: 1 addition & 1 deletion src/olympia/amo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def test_allow_mozilla_collections(self):

@pytest.mark.django_db
def test_fake_fxa_authorization_correct_values_passed():
with override_settings(DEBUG=True): # USE_FAKE_FXA_AUTH is already True
with override_settings(DEV_MODE=True): # USE_FAKE_FXA_AUTH is already True
url = reverse('fake-fxa-authorization')
response = test.Client().get(url, {'state': 'foobar'})
assert response.status_code == 200
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def static_check(app_configs, **kwargs):
errors = []
output = StringIO()

if not settings.DEV_MODE:
if settings.DEV_MODE:
return []

try:
Expand Down
8 changes: 8 additions & 0 deletions src/olympia/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib import admin
from django.shortcuts import redirect
from django.urls import include, re_path, reverse
from django.views.i18n import JavaScriptCatalog
from django.views.static import serve as serve_static

from olympia.amo.utils import urlparams
Expand Down Expand Up @@ -125,6 +126,13 @@ def serve_static_files(request, path, **kwargs):
serve_static,
{'document_root': settings.MEDIA_ROOT},
),
# Specific fallback for statically generated i18n js files
# Not generated in dev mode builds
re_path(
r'^static/js/i18n/.*\.js$',
JavaScriptCatalog.as_view(),
name='js-i18n-catalog',
),
# fallback for static files that are not available directly over nginx.
# Mostly vendor files from python or npm dependencies that are not available
# in the static files directory.
Expand Down

0 comments on commit 94e00bb

Please sign in to comment.