mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Collect static files directly in the location that will be served
We exclude the original source files for minified files by using a custom Finder. (imported from commit a6a25eb6146da53167b71c6d1c44588f75966059)
This commit is contained in:
		@@ -208,10 +208,6 @@ RATE_LIMITING_RULES = [
 | 
			
		||||
 | 
			
		||||
STATIC_URL = '/static/'
 | 
			
		||||
 | 
			
		||||
STATICFILES_FINDERS = (
 | 
			
		||||
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# PipelineCachedStorage inserts a file hash into filenames,
 | 
			
		||||
# to prevent the browser from using stale files from cache.
 | 
			
		||||
#
 | 
			
		||||
@@ -221,11 +217,18 @@ STATICFILES_FINDERS = (
 | 
			
		||||
 | 
			
		||||
if DEBUG:
 | 
			
		||||
    STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
 | 
			
		||||
    STATICFILES_FINDERS = (
 | 
			
		||||
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
 | 
			
		||||
    )
 | 
			
		||||
else:
 | 
			
		||||
    STATICFILES_STORAGE = 'zephyr.storage.HumbugStorage'
 | 
			
		||||
    STATICFILES_FINDERS = (
 | 
			
		||||
        'zephyr.finders.HumbugFinder',
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
STATIC_HEADER_FILE = 'zephyr/static_header.txt'
 | 
			
		||||
STATIC_ROOT = 'prod-static/collected'
 | 
			
		||||
STATIC_ROOT = 'prod-static/serve'
 | 
			
		||||
 | 
			
		||||
# This is the default behavior from Pipeline, but we set it
 | 
			
		||||
# here so that urls.py can read it.
 | 
			
		||||
 
 | 
			
		||||
@@ -12,29 +12,8 @@ exec >update-prod-static.log
 | 
			
		||||
    --output ./zephyr/static/templates/compiled.js \
 | 
			
		||||
    --known if,unless,each,with
 | 
			
		||||
 | 
			
		||||
# Collect both original and minified files.
 | 
			
		||||
#
 | 
			
		||||
# We don't delete the old files, because doing so makes the
 | 
			
		||||
# running app with PipelineCachedStorage unhappy.  So if you
 | 
			
		||||
# remove a static file, you need to manually remove it from
 | 
			
		||||
# prod-static/collected on the app servers.
 | 
			
		||||
# Collect the files that we're going to serve
 | 
			
		||||
rm -rf prod-static/source-map
 | 
			
		||||
mkdir -p prod-static/source-map
 | 
			
		||||
./manage.py collectstatic --noinput
 | 
			
		||||
 | 
			
		||||
# Copy the files we want to expose
 | 
			
		||||
rm -rf prod-static/serve-new
 | 
			
		||||
mkdir -p prod-static/serve-new
 | 
			
		||||
cp -r prod-static/collected/{favicon.ico,robots.txt,html,images,third,min,audio} prod-static/serve-new/
 | 
			
		||||
 | 
			
		||||
# Sync the new directory to the one nginx actually serves.
 | 
			
		||||
# Hopefully this doesn't race too badly for clients loading
 | 
			
		||||
# right as a deploy happens.
 | 
			
		||||
mkdir -p prod-static/serve
 | 
			
		||||
rsync -ar --delete prod-static/serve-new/* prod-static/serve/
 | 
			
		||||
 | 
			
		||||
# Clean up
 | 
			
		||||
rm -rf prod-static/serve-new
 | 
			
		||||
 | 
			
		||||
# Leave the 'collected' directory around or PipelineCachedStorage
 | 
			
		||||
# will fail.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								zephyr/finders.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								zephyr/finders.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.contrib.staticfiles.finders import AppDirectoriesFinder
 | 
			
		||||
 | 
			
		||||
class ExcludeMinifiedMixin(object):
 | 
			
		||||
    def list(self, ignore_patterns):
 | 
			
		||||
        # We can't use ignore_patterns because the patterns are
 | 
			
		||||
        # applied to just the file part, not the entire path
 | 
			
		||||
        to_exclude = set()
 | 
			
		||||
        for collection in (settings.PIPELINE_CSS, settings.PIPELINE_JS):
 | 
			
		||||
            for key in collection:
 | 
			
		||||
                to_exclude.update(collection[key]['source_filenames'])
 | 
			
		||||
 | 
			
		||||
        super_class = super(ExcludeMinifiedMixin, self)
 | 
			
		||||
        for path, storage in super_class.list(ignore_patterns):
 | 
			
		||||
            if not path in to_exclude:
 | 
			
		||||
                yield path, storage
 | 
			
		||||
 | 
			
		||||
class HumbugFinder(ExcludeMinifiedMixin, AppDirectoriesFinder):
 | 
			
		||||
    pass
 | 
			
		||||
		Reference in New Issue
	
	Block a user