#4885 Use WhiteNoise to serve static assets for the Pagure web interface
Merged 3 years ago by pingou. Opened 3 years ago by ngompa.

@@ -33,8 +33,6 @@ 

    #SSLCertificateChainFile /etc/pki/tls/....intermediate.crt

    #SSLCertificateKeyFile /etc/pki/tls/....key

  

-   #Alias /static /usr/lib/pythonX.Y/site-packages/pagure/static/

- 

    #<Location />

      #WSGIProcessGroup paguredocs

      #<IfModule mod_authz_core.c>
@@ -64,7 +62,6 @@ 

    #SSLCertificateChainFile /etc/pki/tls/....intermediate.crt

    #SSLCertificateKeyFile /etc/pki/tls/....key

  

-   #Alias /static /usr/lib/pythonX.Y/site-packages/pagure/static/

    #Alias /releases /var/www/releases

  

    ## Section used to support cloning git repo over http (https in this case)

file modified
-9
@@ -27,11 +27,6 @@ 

          #try_files $uri @pagure_docs;

      #}

  

-     #location /static {

-         #alias /usr/lib/pythonX.Y/site-packages/pagure/static/;

-         #try_files $uri $uri/;

-     #}

- 

  #}

  

  #server {
@@ -63,10 +58,6 @@ 

          #try_files $uri @pagure;

      #}

  

-     #location /static {

-         #alias /usr/lib/pythonX.Y/site-packages/pagure/static/;

-     #}

- 

      #location /releases {

          #alias /var/www/releases/;

          #autoindex on;

file modified
+2 -11
@@ -75,6 +75,7 @@ 

  Requires:           python%{python_pkgversion}-six

  Requires:           python%{python_pkgversion}-sqlalchemy >= 0.8

  Requires:           python%{python_pkgversion}-straight-plugin

+ Requires:           python%{python_pkgversion}-whitenoise

  Requires:           python%{python_pkgversion}-wtforms

  %endif

  
@@ -365,22 +366,12 @@ 

  # Switch interpreter for systemd units

  sed -e "s|/usr/bin/python|%{__python}|g" -i $RPM_BUILD_ROOT/%{_unitdir}/*.service

  

- %if 0%{?rhel} && 0%{?rhel} < 8

- # Change to correct static file path for apache httpd and nginx

- sed -e "s/pythonX.Y/python%{python2_version}/g" -i \

-     $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/pagure.conf \

-     $RPM_BUILD_ROOT/%{_sysconfdir}/nginx/conf.d/pagure.conf

- %else

+ %if ! (0%{?rhel} && 0%{?rhel} < 8)

  # Switch all systemd units to use the correct celery

  sed -e "s|/usr/bin/celery|/usr/bin/celery-3|g" -i $RPM_BUILD_ROOT/%{_unitdir}/*.service

  

  # Switch all systemd units to use the correct gunicorn

  sed -e "s|/usr/bin/gunicorn|/usr/bin/gunicorn-3|g" -i $RPM_BUILD_ROOT/%{_unitdir}/*.service

- 

- # Change to correct static file path for apache httpd and nginx

- sed -e "s/pythonX.Y/python%{python3_version}/g" -i \

-     $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/pagure.conf \

-     $RPM_BUILD_ROOT/%{_sysconfdir}/nginx/conf.d/pagure.conf

  %endif

  

  # Make log directories

file modified
+9
@@ -17,6 +17,7 @@ 

  import pygit2

  

  from binaryornot.helpers import is_binary_string

+ from whitenoise import WhiteNoise

  

  import pagure.config

  import pagure.doc_utils
@@ -29,6 +30,14 @@ 

  # Create the application.

  APP = flask.Flask(__name__)

  

+ # Setup WhiteNoise for serving static files

+ here = os.path.abspath(

+     os.path.join(os.path.dirname(os.path.abspath(__file__)))

+ )

+ APP.wsgi_app = WhiteNoise(

+     APP.wsgi_app, root=os.path.join(here, "static"), prefix="/static"

+ )

+ 

  # set up FAS

  APP.config = pagure.config.reload_config()

  

file modified
+7
@@ -21,6 +21,8 @@ 

  import flask

  import pygit2

  

+ from whitenoise import WhiteNoise

+ 

  import pagure.doc_utils

  import pagure.exceptions

  import pagure.forms
@@ -188,6 +190,11 @@ 

      app.jinja_loader = jinja2.ChoiceLoader(templ_loaders)

      app.register_blueprint(themeblueprint)

  

+     # Setup WhiteNoise for serving static files

+     app.wsgi_app = WhiteNoise(

+         app.wsgi_app, root=os.path.join(here, "static"), prefix="/static"

+     )

+ 

      app.before_request(set_request)

      app.after_request(after_request)

      app.teardown_request(end_request)

file modified
+1
@@ -33,6 +33,7 @@ 

  # 1.4.0 is broken, 1.4.0-post-1 works but gives odd results on newer setuptools

  # the latest version 1.5.0 is also known to work

  straight.plugin

+ whitenoise

  wtforms

  

  # Required only for the `oidc` authentication backend

In order to make it easier to run Pagure in a containerized environment,
the web frontend needs to be capable of serving all of the frontend static
files. This change introduces WhiteNoise as a dependency that would enable
the Flask application itself to serve the static assets correctly.

This makes it possible to run a Pagure server without Apache or Nginx at all
in a containerized environment for all of the main functions.

Note that the releases folder is still not served through WhiteNoise, and
deployments that have uploading releases enabled will need something to
serve them.

Signed-off-by: Neal Gompa ngompa13@gmail.com

There is normally a performance interest in having apache/nginx server the static files

I don't think it'd be any worse than it what it is right now for proxying the Git HTTP push/pull through Pagure. But if you have an idea of how to measure this, we could do that.

rebased onto d22bf0e295f00d863212b6ad94e5cfcdad7e6803

3 years ago

rebased onto 37fea353cdfcc3011d3fed7d4bc1ed130a87211a

3 years ago

rebased onto 6d9ab3337f7fd913a00d1641af729d648eb5a26a

3 years ago

rebased onto 89f18ee38de1e6cb3ac482f865e6352ed340d763

3 years ago

rebased onto ae308ffe623de8c1396c33db7b24f18c9d58bf53

3 years ago

rebased onto ceedaa1bffaec1dd970c5526ea7df21f4bdb7b23

3 years ago

rebased onto 6a01d5897005391a15eb357d26448948569df5fa

3 years ago

rebased onto 7fd79b52d54d029ab8277ccf3d596e21e1dfe407

3 years ago

rebased onto 4be6bdc507422de75e45d4abd4dd84aa9aa67414

3 years ago

rebased onto 4be6bdc507422de75e45d4abd4dd84aa9aa67414

3 years ago

rebased onto ac1781743d35516f8c91f3516a6e3ce977c995fd

3 years ago

rebased onto 83e1979

3 years ago

Pull-Request has been merged by pingou

3 years ago