← Back to team overview

yellow team mailing list archive

[Merge] lp:~makyo/charms/precise/juju-gui/serve-static into lp:~juju-gui/charms/precise/juju-gui/trunk

 

Matthew Scott has proposed merging lp:~makyo/charms/precise/juju-gui/serve-static into lp:~juju-gui/charms/precise/juju-gui/trunk.

Requested reviews:
  Juju GUI Hackers (juju-gui)
Related bugs:
  Bug #1083545 in juju-gui: "Juju GUI charm: serve the GUI using static files."
  https://bugs.launchpad.net/juju-gui/+bug/1083545

For more details, see:
https://code.launchpad.net/~makyo/charms/precise/juju-gui/serve-static/+merge/138502

Serve static files using nginx

The charm now serves static files using nginx.  This branch relies on frankban and teknico's branch for building the app to be served as static files.  Until that lands, the following patch should be applied to the config.yaml file of the charm in order to test (the patch changes the repo location of juju-gui from trunk to the pending static files branch): http://pastebin.ubuntu.com/1415026/

https://codereview.appspot.com/6898043/

-- 
https://code.launchpad.net/~makyo/charms/precise/juju-gui/serve-static/+merge/138502
Your team Juju GUI Hackers is requested to review the proposed merge of lp:~makyo/charms/precise/juju-gui/serve-static into lp:~juju-gui/charms/precise/juju-gui/trunk.
=== modified file 'config/juju-gui.conf.template'
--- config/juju-gui.conf.template	2012-11-29 13:24:54 +0000
+++ config/juju-gui.conf.template	2012-12-06 16:31:23 +0000
@@ -4,7 +4,4 @@
 start on runlevel [2345]
 stop on runlevel [!2345]
 
-respawn
-setuid ubuntu
-
-exec nodejs %(juju_gui_dir)s/server.js
+exec service nginx start

=== added file 'config/nginx.conf.template'
--- config/nginx.conf.template	1970-01-01 00:00:00 +0000
+++ config/nginx.conf.template	2012-12-06 16:31:23 +0000
@@ -0,0 +1,26 @@
+server {
+    listen 8888;
+    server_name _;
+    root %(server_root)s;
+
+    index index.html;
+
+    # Serve static assets.
+    location ^~ /juju-ui/ {
+        expires max;
+        root %(server_root)s;
+    }
+    location = /favicon.ico {
+        expires max;
+        root %(server_root)s;
+    }
+    location = /index.html {
+        expires max;
+        root %(server_root)s;
+    }
+
+    # Fall through to the single-page app for all other URLs.
+    location ~ / {
+        rewrite .* /index.html last;
+    }
+}

=== modified file 'hooks/install'
--- hooks/install	2012-11-30 17:00:51 +0000
+++ hooks/install	2012-12-06 16:31:23 +0000
@@ -28,7 +28,8 @@
     """Install required dependencies and retrieve Juju/Juju GUI branches."""
     log('Installing dependencies.')
     install_extra_repositories('ppa:chris-lea/node.js')
-    apt_get_install('bzr', 'imagemagick', 'make', 'nodejs', 'npm', 'zookeeper')
+    apt_get_install('bzr', 'imagemagick', 'make', 'nodejs', 'npm', 'zookeeper',
+                    'nginx')
     log('Retrieving source checkouts.')
     bzr_checkout = command('bzr', 'co', '--lightweight')
     bzr_checkout(juju_gui_branch, 'juju-gui')
@@ -36,10 +37,16 @@
 
 
 def build():
-    """Set up Juju GUI."""
+    """Set up Juju GUI and nginx."""
     log('Building Juju GUI.')
     with cd('juju-gui'):
         run('make')
+    log('Setting up nginx.')
+    run('rm', '/etc/nginx/sites-enabled/default')
+    run('touch', '/etc/nginx/sites-available/juju-gui')
+    run('chown', 'ubuntu:', '/etc/nginx/sites-available/juju-gui')
+    run('ln', '-s', '/etc/nginx/sites-available/juju-gui',
+        '/etc/nginx/sites-enabled/juju-gui')
 
 
 def main():

=== modified file 'hooks/start'
--- hooks/start	2012-12-03 10:02:45 +0000
+++ hooks/start	2012-12-06 16:31:23 +0000
@@ -28,7 +28,7 @@
 JUJU_GUI_DIR = os.path.join(CURRENT_DIR, 'juju-gui')
 
 
-def start_gui(juju_api_port, console_enabled):
+def start_gui(juju_api_port, console_enabled, staging):
     """Set up and start the Juju GUI server."""
     with su('root'):
         run('chown', '-R', 'ubuntu:', JUJU_GUI_DIR)
@@ -45,6 +45,15 @@
     render_to_file(
         'config.js.template', context,
         os.path.join(JUJU_GUI_DIR, 'app', 'config.js'))
+    log('Generating the nginx site configuration file.')
+    build_dir = JUJU_GUI_DIR + '/build-'
+    build_dir += staging and 'debug' or 'prod'
+    context = {
+        'server_root': build_dir
+    }
+    render_to_file(
+        'nginx.conf.template', context,
+        '/etc/nginx/sites-available/juju-gui')
     log('Starting Juju GUI.')
     with su('root'):
         service_control('juju-gui', START)
@@ -98,7 +107,8 @@
 def main():
     config = get_config()
     juju_api_port = config['juju-api-port']
-    start_gui(juju_api_port, config['juju-gui-console-enabled'])
+    start_gui(juju_api_port, config['juju-gui-console-enabled'],
+              config.get('staging'))
     if config.get('staging'):
         start_improv(juju_api_port, config['staging-environment'])
     else:

=== modified file 'revision'
--- revision	2012-11-30 17:36:15 +0000
+++ revision	2012-12-06 16:31:23 +0000
@@ -1,1 +1,1 @@
-12
+16


Follow ups