autoland-ui: use a config file which can be managed by puppet to get the url to the api server (bug 1344004). r?davidwalsh draft
authorIsrael Madueme <imadueme@mozilla.com>
Thu, 02 Mar 2017 15:50:58 -0500
changeset 333 9280b01288959e276d43af32290a21e365cce2ce
parent 328 5d23934324a829ad5e0ca7f54eec6c50ab431e62
child 334 12cf0bcd384b783473f228f8e68411dbf90ecd20
push id151
push userbmo:imadueme@mozilla.com
push dateWed, 08 Mar 2017 15:48:54 +0000
reviewersdavidwalsh
bugs1344004
autoland-ui: use a config file which can be managed by puppet to get the url to the api server (bug 1344004). r?davidwalsh The UI can be served from different hosts such as in staging, production, dev, local dev, etc. The API server that it will use in those cases changes, based on where it is hosted. This change adds a environment file that will let puppet (and Cloud Ops) manage that and also lets them manage any DNS changes. When the AUTOLANDUI_CONFIG.API_URL is set to null, it will use the development host for the API which is the same hostname that the UI is served from in development, except at port 9999 per docker-compose. This commit also adds some cleanup to the UI code since we don't need the template.ejs file anymore because of the neutrino upgrade a while back. This also moves our "static static" assets to a folder called "assets" to make the distinction clear. MozReview-Commit-ID: Ku9DXiSleUR
autoland/docker-compose.yml
autoland/ui/Dockerfile-dev
autoland/ui/assets/images/blank.gif
autoland/ui/assets/scripts/environment.js
autoland/ui/conduit-preset.js
autoland/ui/package.json
autoland/ui/src/components/AutolandController.jsx
autoland/ui/src/constants.js
autoland/ui/src/images/blank.gif
autoland/ui/src/template.ejs
--- a/autoland/docker-compose.yml
+++ b/autoland/docker-compose.yml
@@ -8,24 +8,26 @@ services:
     image: nginx:alpine
     ports:
       - "8888:80"
       - "9999:9999"
     volumes:
       - ./docker/web/nginx-conf.d:/etc/nginx/conf.d:ro
     depends_on:
       - webapi
+      - yarn
 
   yarn:
     build:
       context: ./ui
       dockerfile: ./Dockerfile-dev
     command: start
     volumes:
       - ./ui/src:/code/src
+      - ./ui/assets:/code/assets
       - ./ui/build:/code/build
       - ./ui/test:/code/test
 
   mountebank:
     build:
       context: docker/mountebank/
     command: start --logfile /mb.log --debug --mock
 
--- a/autoland/ui/Dockerfile-dev
+++ b/autoland/ui/Dockerfile-dev
@@ -1,20 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 FROM node:7.7-alpine
 
-RUN mkdir -p /code/src
-
 WORKDIR /code
 
+COPY conduit-preset.js /code
 COPY package.json /code
-COPY conduit-preset.js /code
 COPY yarn.lock /code
 RUN yarn --pure-lockfile
 
 # Update $PATH so yarn can find scripts installed by dependencies
 ENV PATH /code/node_modules/.bin:$PATH
 
 EXPOSE 4000
 
new file mode 100644
index 0000000000000000000000000000000000000000..35d42e808f0a8017b8d52a06be2f8fec0b466a66
GIT binary patch
literal 43
sc${<hbhEHbWMp7uXkcLY|NlP&1B2pE7Dgb&paUX6G7L;iE{qJ;0LZEa`2YX_
new file mode 100644
--- /dev/null
+++ b/autoland/ui/assets/scripts/environment.js
@@ -0,0 +1,13 @@
+/*
+ * Do not put private secrets in this file.
+ * This file changes based on the puppet configuration set by Cloud Ops.
+ *
+ * Example configuration from puppet:
+ *   window.AUTOLANDUI_ENV = {
+ *     'API_URL': 'https://api.autoland.service.mozilla.org'
+ *   };
+ */
+
+window.AUTOLANDUI_ENV = {
+  'API_URL': null // Uses the local dev host when null.
+};
--- a/autoland/ui/conduit-preset.js
+++ b/autoland/ui/conduit-preset.js
@@ -1,11 +1,20 @@
+const path = require('path');
+const CopyPlugin = require('copy-webpack-plugin');
+
 module.exports = neutrino => {
   // Ensure the path to JS and CSS starts from root
   neutrino.config.output.publicPath('/');
+
   // Ensure we have custom babel plugins
   neutrino.config.module
     .rule('compile')
     .loader('babel', ({ options }) => {
       options.plugins.unshift(require.resolve('babel-plugin-transform-class-properties'));
       return { options };
     });
+
+  neutrino.config
+    .plugin('copy')
+    .use(CopyPlugin, [{ context: path.join(process.cwd(), 'assets'), from: `**/*` }]);
+
 };
--- a/autoland/ui/package.json
+++ b/autoland/ui/package.json
@@ -6,23 +6,34 @@
     "neutrino-preset-react": "^4.0.1",
     "react-addons-test-utils": "^15.4.2"
   },
   "main": "src/index.js",
   "config": {
     "presets": [
       "neutrino-preset-react",
       "conduit-preset.js"
-    ]
+    ],
+    "html": {
+      "scripts": ["/scripts/environment.js"],
+      "links": [
+        {
+          "href": "/images/blank.gif",
+          "rel": "icon",
+          "type": "image/x-icon"
+        }
+      ]
+    }
   },
   "scripts": {
     "start": "HOST=0.0.0.0 PORT=4000 neutrino start",
     "build": "neutrino build",
     "test": "neutrino test --presets neutrino-preset-node neutrino-preset-jest"
   },
   "dependencies": {
     "babel-plugin-transform-class-properties": "^6.23.0",
+    "copy-webpack-plugin": "3.0.1",
     "react": "^15.4.2",
     "react-addons-css-transition-group": "^15.4.2",
     "react-dom": "^15.4.2",
     "react-router": "^3.0.2"
   }
 }
--- a/autoland/ui/src/components/AutolandController.jsx
+++ b/autoland/ui/src/components/AutolandController.jsx
@@ -1,15 +1,15 @@
 import React from 'react';
 import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
 
 import CommitsTable from './CommitsTable';
 import ActionButtons from './ActionButtons';
 import TryChooser from './TryChooser';
-import { API_HOST, AUTOLAND_POST_ENDPOINT } from '../constants';
+import { API_URL, AUTOLAND_POST_ENDPOINT } from '../constants';
 
 class AutolandController extends React.Component {
 
   defaultState = { data: null, error: null, hideTry: true };
 
   constructor(props) {
     super(props);
     this.state = this.defaultState;
@@ -23,17 +23,17 @@ class AutolandController extends React.C
     this.fetch(nextProps.params.repoId, nextProps.params.splat);
   }
 
   resetStateWithUpdates(stateUpdates) {
     this.setState({ ...this.defaultState, ...stateUpdates });
   }
 
   fetch(repoId, seriesId) {
-    fetch(`${API_HOST}/api/v1/repos/${repoId}/series/${seriesId}`)
+    fetch(`${API_URL}/api/v1/repos/${repoId}/series/${seriesId}`)
       .then(response => {
         if (response.status === 404) {
           this.resetStateWithUpdates({
             error: 'Data for this commit set could not be found.',
           });
           return;
         }
 
--- a/autoland/ui/src/constants.js
+++ b/autoland/ui/src/constants.js
@@ -1,10 +1,7 @@
-const hostname = window.location.hostname;
-
-const UI_PRODUCTION_HOSTNAME = 'autoland.mozilla.org';
-const API_PRODUCTION_ORIGIN = 'https://api.autoland.mozilla.org';
-const API_DEVELOPMENT_ORIGIN = `http://${hostname}:9999`;
-
-export const API_HOST = (hostname === UI_PRODUCTION_HOSTNAME ?
-                                      API_PRODUCTION_ORIGIN :
-                                      API_DEVELOPMENT_ORIGIN);
+// Use a stub config in testing
+const environment = window.AUTOLANDUI_ENV || {
+  'API_URL': null
+};
+export const API_URL = environment.API_URL ||
+                       `http://${window.location.hostname}:9999`;
 export const AUTOLAND_POST_ENDPOINT = '...';
deleted file mode 100644
index 35d42e808f0a8017b8d52a06be2f8fec0b466a66..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/autoland/ui/src/template.ejs
+++ /dev/null
@@ -1,9 +0,0 @@
-<html>
-<head>
-  <title>Loading...</title>
-  <link href="/images/blank.gif" rel="icon" type="image/x-icon" />
-</head>
-<body>
-  <div id="root"></div>
-</body>
-</html>