You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2020/12/31 01:03:18 UTC

[trafficcontrol] branch master updated: TP: Use developer conf for dev build (#5322)

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ccc77a  TP: Use developer conf for dev build (#5322)
5ccc77a is described below

commit 5ccc77a18d2f6ae451b26109895661741257e0c8
Author: Steve Hamrick <sh...@users.noreply.github.com>
AuthorDate: Wed Dec 30 18:03:04 2020 -0700

    TP: Use developer conf for dev build (#5322)
    
    * Add dev config file
    
    * Fix rpm build issue
---
 docs/source/development/traffic_portal.rst      | 12 ++++--------
 traffic_portal/build/traffic_portal.spec        |  3 ++-
 traffic_portal/conf/config.js                   |  2 --
 traffic_portal/conf/{config.js => configDev.js} | 14 ++++++--------
 traffic_portal/server.js                        |  7 +++++--
 5 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/docs/source/development/traffic_portal.rst b/docs/source/development/traffic_portal.rst
index c71872b..24b876b 100644
--- a/docs/source/development/traffic_portal.rst
+++ b/docs/source/development/traffic_portal.rst
@@ -103,14 +103,10 @@ Installing The Traffic Portal Developer Environment
 #. Run ``bower install`` to install client-side dependencies into ``traffic_portal/app/bower_components``. Only needs to be done the first time unless ``traffic_portal/bower.json`` changes.
 #. Make sure that compass is installed and functioning correctly by running ``compass version``. If compass is not available, then it can be installed following the instructions under :ref:`dev-tp-compass`.
 
-#. Run ``grunt`` to package the application into ``traffic_portal/app/dist``, start a local HTTPS server (Express), and start a file watcher.
-#. Modify ``traffic_portal/conf/config.js``:
-
+#. Modify ``traffic_portal/conf/configDev.js``:
 	#. Valid SSL certificates and keys are needed for Traffic Portal to run. Generate these (e.g. using `this SuperUser answer <https://superuser.com/questions/226192/avoid-password-prompt-for-keys-and-prompts-for-dn-information#answer-226229>`_) and update ``ssl``.
 	#. Modify ``api.base_url`` to point to your Traffic Ops API endpoint.
-	#. Modify ``files.static`` to be ``./app/dist/public``.
-	#. Modify ``log.stream`` to be ``./server/log/access.log``. If you have created a ``traffic_portal/log`` directory with ``access.log`` file, use that location.
-    #. Ensure ca_bundle.crt is present at ``/etc/pki/tls/certs``. If not present, use the cmd: ``sudo touch ca_bundle.crt``
-#. Navigate to http(s)://localhost:[port|sslPort defined in ``traffic_portal/conf/config.js``]
+#. Run ``grunt`` to package the application into ``traffic_portal/app/dist``, start a local HTTPS server (Express), and start a file watcher.
+#. Navigate to http(s)://localhost:[port|sslPort defined in ``traffic_portal/conf/configDev.js``]
 
-.. note:: The Traffic Portal consumes the Traffic Ops API. Modify traffic_portal/conf/config.js to specify the location of Traffic Ops.
+.. note:: The Traffic Portal consumes the Traffic Ops API. Modify traffic_portal/conf/configDev.js to specify the location of Traffic Ops.
diff --git a/traffic_portal/build/traffic_portal.spec b/traffic_portal/build/traffic_portal.spec
index 00635c0..6b02866 100644
--- a/traffic_portal/build/traffic_portal.spec
+++ b/traffic_portal/build/traffic_portal.spec
@@ -47,12 +47,13 @@ tar -xzvf $RPM_SOURCE_DIR/traffic_portal-%{version}.tgz
 %install
 		%__mkdir -p ${RPM_BUILD_ROOT}/etc/init.d
 		%__mkdir -p ${RPM_BUILD_ROOT}/etc/logrotate.d
-		%__mkdir -p ${RPM_BUILD_ROOT}/etc/traffic_portal
+		%__mkdir -p ${RPM_BUILD_ROOT}/etc/traffic_portal/conf
 		%__mkdir -p ${RPM_BUILD_ROOT}%{traffic_portal_home}/public
 		%__mkdir -p ${RPM_BUILD_ROOT}%{traffic_portal_home}/server
 		%__mkdir -p ${RPM_BUILD_ROOT}/var/log/traffic_portal
 
 		%__cp ${RPM_BUILD_DIR}/traffic_portal-%{version}/server.js ${RPM_BUILD_ROOT}%{traffic_portal_home}/.
+		%__rm -f ${RPM_BUILD_DIR}/traffic_portal-%{version}/conf/configDev.js
 		%__cp -r ${RPM_BUILD_DIR}/traffic_portal-%{version}/conf ${RPM_BUILD_ROOT}/etc/traffic_portal/.
 		%__cp ${RPM_BUILD_DIR}/traffic_portal-%{version}/build/etc/init.d/traffic_portal ${RPM_BUILD_ROOT}/etc/init.d/.
 		%__cp ${RPM_BUILD_DIR}/traffic_portal-%{version}/build/etc/logrotate.d/traffic_portal ${RPM_BUILD_ROOT}/etc/logrotate.d/.
diff --git a/traffic_portal/conf/config.js b/traffic_portal/conf/config.js
index a2c0762..c184c46 100644
--- a/traffic_portal/conf/config.js
+++ b/traffic_portal/conf/config.js
@@ -34,12 +34,10 @@ module.exports = {
         base_url: 'https://trafficops.CHANGEME.domain.com/api/'
     },
     // default static files location (this is where the traffic portal html, css and javascript was installed. rpm installs these files at /opt/traffic_portal/public
-    // change this to ./app/dist/public/ if you are running locally for development
     files: {
         static: '/opt/traffic_portal/public'
     },
     // default log location (this is where traffic_portal logs are written)
-    // change this to ./server/log/access.log if you are running traffic portal locally for development
     log: {
         stream: '/var/log/traffic_portal/access.log'
     },
diff --git a/traffic_portal/conf/config.js b/traffic_portal/conf/configDev.js
similarity index 77%
copy from traffic_portal/conf/config.js
copy to traffic_portal/conf/configDev.js
index a2c0762..e1c12a0 100644
--- a/traffic_portal/conf/config.js
+++ b/traffic_portal/conf/configDev.js
@@ -25,23 +25,21 @@ module.exports = {
     sslPort: 443, // set to https port
     // if useSSL is true, generate ssl certs and provide the proper locations.
     ssl: {
-        key:    '/etc/pki/tls/private/localhost.key',
-        cert:   '/etc/pki/tls/certs/localhost.crt',
-        ca:     [ '/etc/pki/tls/certs/ca-bundle.crt' ]
+        key:    './localhost.key',
+        cert:   './localhost.crt',
+        ca:     [ './localhost.crt' ]
     },
     // set api 'base_url' to the traffic ops api url (all api calls made from the traffic portal will be proxied to the api base_url)
     api: {
-        base_url: 'https://trafficops.CHANGEME.domain.com/api/'
+        base_url: 'https://localhost:6443/api/'
     },
     // default static files location (this is where the traffic portal html, css and javascript was installed. rpm installs these files at /opt/traffic_portal/public
-    // change this to ./app/dist/public/ if you are running locally for development
     files: {
-        static: '/opt/traffic_portal/public'
+        static: './app/dist/public'
     },
     // default log location (this is where traffic_portal logs are written)
-    // change this to ./server/log/access.log if you are running traffic portal locally for development
     log: {
-        stream: '/var/log/traffic_portal/access.log'
+        stream: './server/log/access.log'
     },
     reject_unauthorized: 0 // 0 if using self-signed certs, 1 if trusted certs
 };
diff --git a/traffic_portal/server.js b/traffic_portal/server.js
index 408c724..f881c32 100644
--- a/traffic_portal/server.js
+++ b/traffic_portal/server.js
@@ -33,7 +33,10 @@ try {
     config = require('/etc/traffic_portal/conf/config');
 }
 catch(e) {
-    config = require('./conf/config');
+    let file = "./conf/config";
+    if((process.env.NODE_ENV || "prod") === "dev")
+        file = './conf/configDev';
+    config = require(file);
 }
 
 var logStream = fs.createWriteStream(config.log.stream, { flags: 'a' }),
@@ -47,7 +50,7 @@ var app = express();
 app.use(function(req, res, next) {
     var err = null;
     try {
-        decodeURIComponent(req.path)
+        decodeURIComponent(req.path);
     }
     catch(e) {
         err = e;