Skip to content

Commit

Permalink
TMP: fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Sep 5, 2024
1 parent 06146a4 commit aec2cbf
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ shellng_local.py
site-static/*
src/olympia/discovery/strings.jinja2
static/css/node_lib/*
static-dist/*
static-build/*
static/js/node_lib/*
storage/files/*
storage/git-storage/*
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ COPY --chown=olympia:olympia . ${HOME}
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-dist ${HOME}/static-dist
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 Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
- 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-dist
- /data/olympia/static-build
- /data/olympia/site-static
- storage:/data/olympia/storage
- data_deps:/deps
Expand Down
3 changes: 3 additions & 0 deletions docker/nginx/addons.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ server {
location /static/ {
alias /srv/site-static/;

# Fallback to the uwsgi server if the file is not found in the static files directory.
# This will happen for vendor files from pytnon or npm dependencies that won't be available
# in the static files directory.
error_page 404 = @olympia;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/topics/development/static-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Static files specific to the addons-server project are stored in the `./static`
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-dist`: Contains static files that are built by `compress_assets`.
- `/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.
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/amo/management/commands/compress_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def handle(self, **options):
for name, files in bundle.items():
# Set the paths to the files.
concatted_file = os.path.join(
settings.STATIC_DIST_PATH,
settings.STATIC_BUILD_PATH,
ftype,
'%s-all.%s'
% (
Expand All @@ -76,7 +76,7 @@ def handle(self, **options):
),
)
compressed_file = os.path.join(
settings.STATIC_DIST_PATH,
settings.STATIC_BUILD_PATH,
ftype,
'%s-min.%s'
% (
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/amo/management/commands/generate_jsi18n_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

class Command(BaseCommand):
help = 'Generate static jsi18n files for each locale we support'
requires_system_checks = [] # Can be ran without the database up yet.s
requires_system_checks = [] # Can be ran without the database up yet.

def handle(self, *args, **options):
fake_request = HttpRequest()
fake_request.method = 'GET'

root = os.path.join(settings.STATIC_DIST_PATH, 'js', 'i18n')
root = os.path.join(settings.STATIC_BUILD_PATH, 'js', 'i18n')

if not os.path.exists(root):
os.makedirs(root)
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/amo/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_compress_assets_correctly_compresses_js(settings, tmpdir):

@pytest.mark.needs_locales_compilation
def test_generate_jsi18n_files():
dirname = os.path.join(settings.STATIC_DIST_PATH, 'js', 'i18n')
dirname = os.path.join(settings.STATIC_BUILD_PATH, 'js', 'i18n')
assert os.path.exists(dirname)
filename = os.path.join(dirname, 'fr.js')
call_command('generate_jsi18n_files')
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/lib/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,11 +1299,11 @@ def read_only_mode(env):
NODE_PACKAGE_JSON = os.path.join('/', 'deps', 'package.json')
NODE_PACKAGE_MANAGER_INSTALL_OPTIONS = ['--dry-run']

STATIC_DIST_PATH = os.path.join('/', 'data', 'olympia', 'static-dist')
STATIC_BUILD_PATH = os.path.join('/', 'data', 'olympia', 'static-build')

STATICFILES_DIRS = (
path('static'),
STATIC_DIST_PATH,
STATIC_BUILD_PATH,
)

STATICFILES_STORAGE = 'olympia.lib.storage.ManifestStaticFilesStorageNotMaps'
Expand Down
3 changes: 3 additions & 0 deletions src/olympia/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def serve_static_files(request, path, **kwargs):
serve_static,
{'document_root': settings.MEDIA_ROOT},
),
# This is a 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.
re_path(r'^static/(?P<path>.*)$', serve_static_files),
]
)
Expand Down
4 changes: 2 additions & 2 deletions tests/js/zamboni/stats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe(__filename, () => {

beforeEach(() => {
stats_stats =
require('../../../static-dist/js/zamboni/stats-all.js').stats_stats;
require('../../../static-build/js/zamboni/stats-all.js').stats_stats;
});

describe('export links', () => {
Expand Down Expand Up @@ -129,7 +129,7 @@ describe(__filename, () => {
let stats_overview_make_handler;

beforeEach(() => {
const stats_all = require('../../../static-dist/js/zamboni/stats-all.js');
const stats_all = require('../../../static-build/js/zamboni/stats-all.js');

stats_overview_make_handler = stats_all.stats_overview_make_handler;
});
Expand Down

0 comments on commit aec2cbf

Please sign in to comment.