You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2016/10/20 19:11:32 UTC

[02/17] incubator-trafficcontrol git commit: adds build files for TOv2

adds build files for TOv2


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/51dae6b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/51dae6b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/51dae6b5

Branch: refs/heads/master
Commit: 51dae6b5cdc6e16298fff9da7ce50fb9618dfd02
Parents: 051b4fb
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Tue Oct 18 13:45:25 2016 -0600
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue Oct 18 13:45:25 2016 -0600

----------------------------------------------------------------------
 traffic_ops/experimental/ui/build/README.md     |  60 +++++++++
 traffic_ops/experimental/ui/build/build_rpm.sh  |  55 ++++++++
 .../ui/build/etc/init.d/traffic_ops_v2          | 135 +++++++++++++++++++
 .../ui/build/etc/logrotate.d/traffic_ops_v2     |   8 ++
 .../build/etc/logrotate.d/traffic_ops_v2-access |   8 ++
 .../experimental/ui/build/traffic_ops_v2.spec   |  90 +++++++++++++
 6 files changed, 356 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/README.md
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/README.md b/traffic_ops/experimental/ui/build/README.md
new file mode 100644
index 0000000..c2bd4d5
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/README.md
@@ -0,0 +1,60 @@
+# Traffic Ops v2 Installation
+
+### 1. Build w/ Docker
+
+* Download Traffic Control repo
+
+    ```
+    $ git clone https://github.com/apache/incubator-trafficcontrol.git
+    ```
+
+* Build the RPM
+
+    ```
+    $ cd traffic_control/build
+    $ ./docker-build.sh -r https://github.com/apache/incubator-trafficcontrol.git -b master traffic_ops_v2
+    ```
+
+### 2. Install
+
+* Install the Node.js JavaScript runtime
+
+    ```
+    $ curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
+    $ sudo yum install -y nodejs
+    ```
+
+* Install the Traffic Ops v2 RPM
+
+    ```
+    $ sudo yum install -y traffic_ops_v2-[version]-[commits].[sha].x86_64.rpm
+    ```
+
+### 3. Configure
+
+* Configure Traffic Ops v2
+
+    ```
+    $ cd /etc/traffic_ops_v2/conf
+    $ sudo cp config-template.js config.js
+    $ sudo vi config.js (read the inline comments)
+    ```
+
+### 4. Run
+
+* Start Traffic Ops v2
+
+    ```
+    $ sudo service traffic_ops_v2 start
+    ```
+
+* Navigate to Traffic Ops v2
+
+    ```
+    $ http://localhost:8080
+    ```
+
+#### Notes
+
+    - Traffic Ops v2 consumes the Traffic Ops API, therefore, an instance of Traffic Ops must be running.
+    - This is known to work with CentOS 6.7 and Centos 7 as the host environment.

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/build_rpm.sh
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/build_rpm.sh b/traffic_ops/experimental/ui/build/build_rpm.sh
new file mode 100755
index 0000000..c6ae21a
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/build_rpm.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+function importFunctions() {
+	local script=$(readlink -f "$0")
+	local scriptdir=$(dirname "$script")
+	export TS_DIR=$(dirname "$scriptdir")
+	export TC_DIR=$(dirname "$TS_DIR")
+	functions_sh="$TC_DIR/build/functions.sh"
+	if [[ ! -r $functions_sh ]]; then
+		echo "error: can't find $functions_sh"
+		exit 1
+	fi
+	. "$functions_sh"
+}
+
+#----------------------------------------
+function initBuildArea() {
+	echo "Initializing the build area."
+	mkdir -p "$RPMBUILD"/{SPECS,SOURCES,RPMS,SRPMS,BUILD,BUILDROOT} || { echo "Could not create $RPMBUILD: $?"; exit 1; }
+
+	# tar/gzip the source
+	local ts_dest=$(createSourceDir traffic_ops_v2)
+	cd "$TS_DIR" || \
+		 { echo "Could not cd to $TS_DIR: $?"; exit 1; }
+	rsync -av ./ "$ts_dest"/ || \
+		 { echo "Could not copy to $to_dest: $?"; exit 1; }
+	cp -r "$TS_DIR"/ "$ts_dest" || { echo "Could not copy $TS_DIR to $ts_dest: $?"; exit 1; }
+
+	tar -czvf "$ts_dest".tgz -C "$RPMBUILD"/SOURCES $(basename $ts_dest) || { echo "Could not create tar archive $ts_dest.tgz: $?"; exit 1; }
+	cp "$TS_DIR"/build/*.spec "$RPMBUILD"/SPECS/. || { echo "Could not copy spec files: $?"; exit 1; }
+
+	echo "The build area has been initialized."
+}
+
+# ---------------------------------------
+
+importFunctions
+checkEnvironment npm node
+initBuildArea
+buildRpm traffic_portal

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/etc/init.d/traffic_ops_v2
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/etc/init.d/traffic_ops_v2 b/traffic_ops/experimental/ui/build/etc/init.d/traffic_ops_v2
new file mode 100755
index 0000000..de0ded5
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/etc/init.d/traffic_ops_v2
@@ -0,0 +1,135 @@
+#!/bin/bash
+#
+# An init.d script for running a Node.js process as a service using Forever as
+# the process monitor. For more configuration options associated with Forever,
+# see: https://github.com/nodejitsu/forever
+#
+# This was written for Debian distributions such as Ubuntu, but should still
+# work on RedHat, Fedora, or other RPM-based distributions, since none of the
+# built-in service functions are used. So information is provided for both.
+#
+### BEGIN INIT INFO
+# Provides:             my-application
+# Required-Start:       $syslog $remote_fs
+# Required-Stop:        $syslog $remote_fs
+# Should-Start:         $local_fs
+# Should-Stop:          $local_fs
+# Default-Start:        2 3 4 5
+# Default-Stop:         0 1 6
+# Short-Description:    My Application
+# Description:          My Application
+### END INIT INFO
+#
+### BEGIN CHKCONFIG INFO
+# chkconfig: 2345 55 25
+# description: My Application
+### END CHKCONFIG INFO
+#
+# An application name to display in echo text.
+# NAME="Traffic Ops v2 Application"
+# The full path to the directory containing the node and forever binaries.
+# Set the NODE_PATH to the Node.js main node_modules directory.
+# The application startup Javascript file path.
+
+# Process ID file path.
+# Log file path.
+# Forever settings to prevent the application spinning if it fails on launch.
+# MIN_UPTIME="5000"
+# SPIN_SLEEP_TIME="2000"
+ 
+NAME="Traffic Ops v2 Application"
+NODE_BIN_DIR="/usr/bin"
+NODE_PATH="/opt/traffic_ops_v2/node_modules"
+FOREVER_BIN_DIR="/opt/traffic_ops_v2/node_modules/forever/bin"
+APPLICATION_PATH="/opt/traffic_ops_v2/server/server.js"
+PIDFILE="/var/run/traffic_ops_v2.pid"
+LOGFILE="/var/log/traffic_ops_v2/traffic_ops_v2.log"
+MIN_UPTIME="5000"
+SPIN_SLEEP_TIME="2000"
+ 
+# Add node to the path for situations in which the environment is passed.
+PATH=$FOREVER_BIN_DIR:$NODE_BIN_DIR:$PATH
+# Export all environment variables that must be visible for the Node.js
+# application process forked by Forever. It will not see any of the other
+# variables defined in this script.
+export NODE_PATH=$NODE_PATH
+ 
+start() {
+    echo "Starting $NAME"
+    # We're calling forever directly without using start-stop-daemon for the
+    # sake of simplicity when it comes to environment, and because this way
+    # the script will work whether it is executed directly or via the service
+    # utility.
+    #
+    # The minUptime and spinSleepTime settings stop Forever from thrashing if
+    # the application fails immediately on launch. This is generally necessary to
+    # avoid loading development servers to the point of failure every time
+    # someone makes an error in application initialization code, or bringing down
+    # production servers the same way if a database or other critical service
+    # suddenly becomes inaccessible.
+    #
+    # The pidfile contains the child process pid, not the forever process pid.
+    # We're only using it as a marker for whether or not the process is
+    # running.
+    #
+    # Note that redirecting the output to /dev/null (or anywhere) is necessary
+    # to make this script work if provisioning the service via Chef.
+    forever \
+      --pidFile $PIDFILE \
+      -a \
+      -l $LOGFILE \
+      --minUptime $MIN_UPTIME \
+      --spinSleepTime $SPIN_SLEEP_TIME \
+      start $APPLICATION_PATH 2>&1 > /dev/null &
+    RETVAL=$?
+}
+ 
+stop() {
+    if [ -f $PIDFILE ]; then
+        echo "Shutting down $NAME"
+        # Tell Forever to stop the process.
+        forever stop $APPLICATION_PATH 2>&1 > /dev/null
+        # Get rid of the pidfile, since Forever won't do that.
+        rm -f $PIDFILE
+        RETVAL=$?
+    else
+        echo "$NAME is not running."
+        RETVAL=0
+    fi
+}
+ 
+restart() {
+    stop
+    start
+}
+ 
+status() {
+    echo `forever list` | grep -q "$APPLICATION_PATH"
+    if [ "$?" -eq "0" ]; then
+        echo "$NAME is running."
+        RETVAL=0
+    else
+        echo "$NAME is not running."
+        RETVAL=3
+    fi
+}
+ 
+case "$1" in
+    start)
+        start
+        ;;
+    stop)
+        stop
+        ;;
+    status)
+        status
+        ;;
+    restart)
+        restart
+        ;;
+    *)
+        echo "Usage: {start|stop|status|restart}"
+        exit 1
+        ;;
+esac
+exit $RETVAL

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2 b/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2
new file mode 100644
index 0000000..229b500
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2
@@ -0,0 +1,8 @@
+/var/log/traffic_ops_v2/traffic_ops_v2.log {
+    daily
+    copytruncate
+    missingok
+    compress
+    maxage 30
+    dateext
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2-access
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2-access b/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2-access
new file mode 100644
index 0000000..89eb341
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/etc/logrotate.d/traffic_ops_v2-access
@@ -0,0 +1,8 @@
+/var/log/traffic_ops_v2/access.log {
+    daily
+    copytruncate
+    missingok
+    compress
+    maxage 30
+    dateext
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/51dae6b5/traffic_ops/experimental/ui/build/traffic_ops_v2.spec
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/build/traffic_ops_v2.spec b/traffic_ops/experimental/ui/build/traffic_ops_v2.spec
new file mode 100644
index 0000000..f9d405e
--- /dev/null
+++ b/traffic_ops/experimental/ui/build/traffic_ops_v2.spec
@@ -0,0 +1,90 @@
+#
+# Copyright 2015 Comcast Cable Communications Management, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# RPM spec file for the Traffic Ops v2
+#
+%define		debug_package %{nil}
+Name:		traffic_ops_v2
+Version:	%{traffic_control_version}
+Release:	%{build_number}
+Summary:	Traffic Ops v2
+Group:		Applications/Communications
+License:	Apache License, Version 2.0
+URL:		https://github.com/Comcast/traffic_control/
+Source:		%{_sourcedir}/traffic_ops_v2-%{traffic_control_version}.tgz
+AutoReqProv: no
+Requires: nodejs
+
+%define traffic_ops_v2_home /opt/traffic_ops_v2
+%description
+Installs Traffic Ops v2
+
+Built: @BUILT@
+
+%prep
+rm -rf $RPM_BUILD_DIR/traffic_ops_v2-%{version}
+tar -xzvf $RPM_SOURCE_DIR/traffic_ops_v2-%{version}.tgz
+
+%setup
+
+%build
+    /usr/bin/npm install
+    /usr/bin/bower install
+    /usr/bin/grunt dist
+
+%install
+    %__mkdir -p ${RPM_BUILD_ROOT}/etc/init.d
+    %__mkdir -p ${RPM_BUILD_ROOT}/etc/logrotate.d
+    %__mkdir -p ${RPM_BUILD_ROOT}/etc/traffic_ops_v2
+    %__mkdir -p ${RPM_BUILD_ROOT}%{traffic_ops_v2_home}/public
+    %__mkdir -p ${RPM_BUILD_ROOT}%{traffic_ops_v2_home}/server
+    %__mkdir -p ${RPM_BUILD_ROOT}/var/log/traffic_ops_v2
+
+    # creates dynamic json file needed at runtime for traffic ops v2 to display release info
+    BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')
+    VERSION="\"Version\":\"$VERSION\""
+    BUILD_NUMBER="\"Build Number\":\"$BUILD_NUMBER\""
+    BUILD_DATE="\"Build Date\":\"$BUILD_DATE\""
+    JSON_VERSION="{\n$VERSION,\n$BUILD_NUMBER,\n$BUILD_DATE\n}"
+    echo -e $JSON_VERSION > ${RPM_BUILD_ROOT}%{traffic_ops_v2_home}/public/traffic_ops_release.json
+
+    %__cp ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/server/server.js ${RPM_BUILD_ROOT}%{traffic_ops_v2_home}/server/.
+    %__cp -r ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/conf ${RPM_BUILD_ROOT}/etc/traffic_ops_v2/.
+    %__cp ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/build/etc/init.d/traffic_ops_v2 ${RPM_BUILD_ROOT}/etc/init.d/.
+    %__cp ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/build/etc/logrotate.d/traffic_ops_v2 ${RPM_BUILD_ROOT}/etc/logrotate.d/.
+    %__cp ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/build/etc/logrotate.d/traffic_ops_v2-access ${RPM_BUILD_ROOT}/etc/logrotate.d/.
+    %__cp -r ${RPM_BUILD_DIR}/traffic_ops_v2-%{version}/app/dist/* ${RPM_BUILD_ROOT}%{traffic_ops_v2_home}/.
+
+%post
+    echo "Successfully installed the traffic_ops_v2 assets to " %{traffic_ops_v2_home}
+    %__chmod +x %{traffic_ops_v2_home}/node_modules/forever/bin/forever
+    %__chmod +x /etc/init.d/traffic_ops_v2
+    echo "Successfully installed the 'traffic_ops_v2' service"
+    /sbin/chkconfig traffic_ops_v2 on
+    echo ""
+    echo "Start with 'service traffic_ops_v2 start'"
+
+%files
+%defattr(644,root,root,755)
+%attr(755,root,root) /etc/init.d/traffic_ops_v2
+%attr(755,root,root) %{traffic_ops_v2_home}/node_modules/forever/bin/*
+%config(noreplace)/etc/traffic_ops_v2/conf/config.js
+%dir /var/log/traffic_ops_v2
+/etc/traffic_ops_v2/conf/config-template.js
+%{traffic_ops_v2_home}/*
+/etc/logrotate.d/traffic_ops_v2
+/etc/logrotate.d/traffic_ops_v2-access
+/etc/init.d/traffic_ops_v2