dangogh closed pull request #2757: WIP: Add traffic router component to
cdn-in-a-box
URL: https://github.com/apache/trafficcontrol/pull/2757
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/infrastructure/cdn-in-a-box/docker-compose.yml
b/infrastructure/cdn-in-a-box/docker-compose.yml
index 1da6c77cb..8800f4703 100644
--- a/infrastructure/cdn-in-a-box/docker-compose.yml
+++ b/infrastructure/cdn-in-a-box/docker-compose.yml
@@ -160,6 +160,26 @@ services:
ports:
- "8010:80"
+ # trafficrouter
+ trafficrouter:
+ build:
+ context: .
+ dockerfile: traffic_router/Dockerfile
+ args:
+ TRAFFIC_ROUTER_RPM: traffic_router/traffic_router.rpm
+ TOMCAT_RPM: traffic_router/tomcat.rpm
+ domainname: cdn.local
+ env_file:
+ - variables.env
+ hostname: trafficrouter
+ networks:
+ - tcnet
+ ports:
+ - "3053:53"
+ - "3080:80"
+ - "3443:443"
+ - "3333:3333"
+
# Apache Traffic Server (ATS) caches defined here
# edge cache
edge:
diff --git a/infrastructure/cdn-in-a-box/traffic_router/Dockerfile
b/infrastructure/cdn-in-a-box/traffic_router/Dockerfile
new file mode 100644
index 000000000..704fb5b62
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_router/Dockerfile
@@ -0,0 +1,62 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+############################################################
+# Dockerfile to build Traffic Router 3.0
+# Based on CentOS 7.x
+############################################################
+
+FROM centos:7
+MAINTAINER Dan Kirkwood
+
+# Default values for TMCAT RPM and RPM -- override with `docker build
--build-arg JDK=...'
+ARG TRAFFIC_ROUTER_RPM=traffic_router/traffic_router.rpm
+ARG TOMCAT_RPM=traffic_router/tomcat.rpm
+ADD $TRAFFIC_ROUTER_RPM /traffic_router.rpm
+ADD $TOMCAT_RPM /tomcat.rpm
+
+### Common for all sub-component builds
+RUN yum -y install epel-release git rpm-build net-tools iproute nc wget tar
unzip \
+ perl-JSON perl-WWWCurl which tcpdump autoconf automake gcc gcc-c++ \
+ apr apr-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel make \
+ openssl openssl-devel && \
+ yum -y clean all
+
+WORKDIR /opt
+RUN curl -L -b "oraclelicense=a"
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
| tar xzf - && \
+ curl -L
https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz
| tar xzf -
+RUN ln -s jdk* java && ln -s apache-maven* maven
+
+RUN alternatives --install /usr/bin/java java /opt/java/bin/java 2 && \
+ alternatives --install /usr/bin/jar jar /opt/java/bin/jar 2 && \
+ alternatives --install /usr/bin/javac javac /opt/java/bin/javac 2 && \
+ alternatives --set java /opt/java/bin/java && \
+ alternatives --set jar /opt/java/bin/jar && \
+ alternatives --set javac /opt/java/bin/javac && \
+ alternatives --install /usr/bin/mvn mvn /opt/maven/bin/mvn 1
+
+# Install Tomcat and Tomcat Native
+RUN cd / && rpm2cpio /traffic_router.rpm | cpio -ivd && \
+ rpm2cpio /tomcat.rpm | cpio -ivd && \
+ tar -C /opt -xvpf /opt/tomcat/bin/tomcat-native.tar.gz
+
+RUN cd $(find /opt -maxdepth 1 -type d | grep tomcat-native )/native && \
+ ./configure --prefix=/opt/tomcat/lib --with-apr=`which apr-1-config`
--with-java-home=/opt/java --with-ssl && \
+ make install
+
+EXPOSE 53 80 3333
+ADD traffic_router/run.sh traffic_router/to-access.sh /
+CMD /run.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_router/run.sh
b/infrastructure/cdn-in-a-box/traffic_router/run.sh
new file mode 100755
index 000000000..637b5ab94
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_router/run.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+NAME="Traffic Router Application"
+
+CATALINA_HOME=/opt/tomcat
+CATALINA_BASE=/opt/traffic_router
+CATALINA_OUT=$CATALINA_HOME/logs/catalina.log
+CATALINA_PID=$CATALINA_BASE/temp/tomcat.pid
+
+CATALINA_OPTS="\
+ -server -Xms2g -Xmx8g \
+ -Djava.library.path=$CATALINA_HOME/lib \
+ -Dlog4j.configuration=file://$CATALINA_BASE/conf/log4j.properties \
+
-Dorg.apache.catalina.connector.Response.ENFORCE_ENCODING_IN_GET_WRITER=false \
+ -XX:+UseG1GC \
+ -XX:+UnlockExperimentalVMOptions \
+ -XX:InitiatingHeapOccupancyPercent=30"
+
+JAVA_HOME=/opt/java
+JAVA_OPTS="\
+ -Djava.awt.headless=true \
+ -Djava.security.egd=file:/dev/./urandom"
+
+TO_PROPERTIES="$CATALINA_BASE/conf/traffic_ops.properties"
+TM_PROPERTIES="$CATALINA_BASE/conf/traffic_monitor.properties"
+LOGFILE="$CATALINA_BASE/var/log/traffic_router.log"
+ACCESSLOG="$CATALINA_BASE/var/log/access.log"
+
+
+export JAVA_HOME JAVA_OPTS
+export TO_PROPERTIES TM_PROPERTIES
+export CATALINA_HOME CATALINA_BASE CATALINA_OPTS CATALINA_OUT CATALINA_PID
+
+# Wait for Enroller
+export TO_USER=$TO_ADMIN_USER
+export TO_PASSWORD=$TO_ADMIN_PASSWORD
+source /to-access.sh
+to-enroll $(hostname -s)
+
+# Configure TO properties
+# File: /opt/traffic_router/conf/traffic_ops.properties
+echo "" > $TO_PROPERTIES
+echo "traffic_ops.username=$TO_ADMIN_USER" >> $TO_PROPERTIES
+echo "traffic_ops.password=$TO_ADMIN_PASSWORD" >> $TO_PROPERTIES
+
+# Configure TM properties
+# File: /opt/traffic_router/conf/traffic_monitor.properties
+echo "traffic_monitor.bootstrap.hosts=trafficmonitor:80;" >> $TM_PROPERTIES
+echo "traffic_monitor.properties.reload.period=60000" >> $TM_PROPERTIES
+
+touch $LOGFILE $ACCESSLOG
+tail -F $CATALINA_BASE/var/log/traffic_router.log
$CATALINA_BASE/var/log/access.log & \
+ /opt/tomcat/bin/catalina.sh run
diff --git a/infrastructure/cdn-in-a-box/traffic_router/to-access.sh
b/infrastructure/cdn-in-a-box/traffic_router/to-access.sh
new file mode 100644
index 000000000..b1b96731d
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_router/to-access.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+# Defines bash functions to consistently interact with the Traffic Ops API
+
+
+export TO_URL=${TO_URL:-https://$TO_HOST:$TO_PORT}
+export TO_USER=${TO_USER:-$TO_ADMIN_USER}
+export TO_PASSWORD=${TO_PASSWORD:-$TO_ADMIN_PASSWORD}
+
+export CURLOPTS=${CURLOPTS:--LfsS}
+export CURLAUTH=${CURLAUTH:--k}
+export COOKIEJAR=$(mktemp -t XXXX.cookie)
+
+
+login=$(mktemp -t XXXX.login)
+
+cleanup() {
+ rm -f "$COOKIEJAR" "$login"
+}
+
+trap cleanup EXIT
+
+cookie_current() {
+ local cookiefile=$1
+ [[ -s $cookiefile ]] || return 1
+
+ # get expiration from cookiejar -- compare to current time
+ exp=$(awk '/mojolicious/ {print $5}' $cookiefile | tail -n 1)
+ cur=$(date +%s)
+
+ # return value is the comparison itself
+ (( $exp > $cur ))
+}
+
+to-auth() {
+ # These are required
+ if [[ -z $TO_URL || -z $TO_USER || -z $TO_PASSWORD ]]; then
+ echo TO_URL TO_USER TO_PASSWORD must all be set
+ return 1
+ fi
+
+ # if cookiejar is current, nothing to do..
+ cookie_current $COOKIEJAR && return
+
+ local url=$TO_URL/api/1.3/user/login
+ local datatype='Accept: application/json'
+ cat >"$login" <<-CREDS
+{ "u" : "$TO_USER", "p" : "$TO_PASSWORD" }
+CREDS
+ res=$(curl $CURLAUTH $CURLOPTS -H "$datatype" --cookie "$COOKIEJAR"
--cookie-jar "$COOKIEJAR" -X POST --data @"$login" "$url")
+ if [[ $res != *"Successfully logged in."* ]]; then
+ echo "Login failed: $res"
+ return 1
+ fi
+}
+
+to-ping() {
+ # ping endpoint does not require authentication
+ curl $CURLAUTH $CURLOPTS -X GET "$TO_URL/api/1.3/ping"
+}
+
+to-get() {
+ to-auth && \
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X GET
"$TO_URL/$1"
+}
+
+to-post() {
+ if [[ -z "$2" ]]; then
+ data=""
+ elif [[ -f "$2" ]]; then
+ data="--data @$2"
+ else
+ data="--data $2"
+ fi
+ to-auth && \
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X POST $data
"$TO_URL/$1"
+}
+
+to-put() {
+ if [[ -z "$2" ]]; then
+ data=""
+ elif [[ -f "$2" ]]; then
+ data="--data @$2"
+ else
+ data="--data $2"
+ fi
+ to-auth && \
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X PUT $data
"$TO_URL/$1"
+}
+
+to-delete() {
+ to-auth && \
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X DELETE
"$TO_URL/$1"
+}
+
+to-enroll() {
+ local service=$1
+ until nc enroller 443 </dev/null >/dev/null 2>&1; do
+ echo "waiting for enroller"
+ sleep 5
+ done
+
+ action=${service:+?name=$service}
+ curl -k -X POST https://enroller${action}
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services