Add global build script.

This splits out the somewhat messy docker build command into its own script and 
adds a global build script.
There’s still work to be done to clean up docker build scripts, but this 
provides a basic way to build top to bottom
In a single, simple command.

This is a step toward addressing TC-180, but falls short of cleaning up 
everything that requires cleaning up.

(cherry picked from commit 63c019e9a2372d704ec68b6c9956d8a9ffed552b)


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

Branch: refs/heads/2.0.x
Commit: 7604dfb7bba43c7485394a4523c1541a9143a761
Parents: 05664d6
Author: Chris Lemmons <alfic...@gmail.com>
Authored: Fri Mar 10 11:18:57 2017 -0700
Committer: Eric Friedrich <fri...@apache.org>
Committed: Mon May 22 22:10:32 2017 -0400

----------------------------------------------------------------------
 .gitignore                                      |  1 +
 .../docker/build/Dockerfile-traffic_monitor     |  7 +-
 .../build/Dockerfile-traffic_monitor_golang     |  8 +--
 .../docker/build/Dockerfile-traffic_ops         |  7 +-
 .../docker/build/Dockerfile-traffic_portal      |  7 +-
 .../docker/build/Dockerfile-traffic_router      |  7 +-
 .../docker/build/Dockerfile-traffic_stats       |  7 +-
 infrastructure/docker/build/clean_build.sh      |  8 +++
 pkg                                             | 72 ++++++++++++++++++++
 9 files changed, 93 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 834456e..aa8a73d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,4 @@ misc/traffic-control-cdn/downloads/*.rpm
 traffic_router/*/*.log
 traffic_router/*.log
 .dbInfo
+/dist

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_monitor
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_monitor 
b/infrastructure/docker/build/Dockerfile-traffic_monitor
index 0341f21..985fa63 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_monitor
+++ b/infrastructure/docker/build/Dockerfile-traffic_monitor
@@ -48,10 +48,7 @@ RUN alternatives --install /usr/bin/java java 
/opt/java/bin/java 2 && \
     alternatives --set javac /opt/java/bin/javac && \
     alternatives --install /usr/bin/mvn mvn /opt/maven/bin/mvn 1
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_monitor 2>&1 | tee 
./dist/build-traffic_monitor.log && \
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_monitor* /trafficcontrol/dist
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_monitor
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_monitor_golang
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_monitor_golang 
b/infrastructure/docker/build/Dockerfile-traffic_monitor_golang
index 52d2dd0..aa44bef 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_monitor_golang
+++ b/infrastructure/docker/build/Dockerfile-traffic_monitor_golang
@@ -35,11 +35,7 @@ RUN  yum -y install \
        yum -y clean all
 ###
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_monitor_golang 2>&1 | tee 
./dist/build-traffic_monitor_golang.log && \
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_monitor_golang* /trafficcontrol/dist
-
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_monitor_golang
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_ops
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_ops 
b/infrastructure/docker/build/Dockerfile-traffic_ops
index 82dc1a7..107480d 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_ops
+++ b/infrastructure/docker/build/Dockerfile-traffic_ops
@@ -41,10 +41,7 @@ RUN  yum -y install \
                tar && \
        yum -y clean all
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_ops 2>&1 | tee ./dist/build-traffic_ops.log && 
\
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_ops* /trafficcontrol/dist
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_ops
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_portal
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_portal 
b/infrastructure/docker/build/Dockerfile-traffic_portal
index 7c2a78e..978d836 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_portal
+++ b/infrastructure/docker/build/Dockerfile-traffic_portal
@@ -47,11 +47,8 @@ RUN  echo '{ "allow_root": true }' > /root/.bowerrc
 
 ###
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_portal 2>&1 | tee 
./dist/build-traffic_portal.log && \
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_portal* /trafficcontrol/dist
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_portal
 
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_router
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_router 
b/infrastructure/docker/build/Dockerfile-traffic_router
index 842e6c6..5c6b278 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_router
+++ b/infrastructure/docker/build/Dockerfile-traffic_router
@@ -47,10 +47,7 @@ RUN alternatives --install /usr/bin/java java 
/opt/java/bin/java 2 && \
     alternatives --install /usr/bin/mvn mvn /opt/maven/bin/mvn 1
 ###
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_router 2>&1 | tee 
./dist/build-traffic_router.log && \
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_router* /trafficcontrol/dist
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_router
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/Dockerfile-traffic_stats
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/Dockerfile-traffic_stats 
b/infrastructure/docker/build/Dockerfile-traffic_stats
index 84bfa49..a0e6721 100644
--- a/infrastructure/docker/build/Dockerfile-traffic_stats
+++ b/infrastructure/docker/build/Dockerfile-traffic_stats
@@ -35,11 +35,8 @@ RUN  yum -y install \
        yum -y clean all
 ###
 
-CMD set -x; cp -a /trafficcontrol /tmp/. && \
-       cd /tmp/trafficcontrol && rm -rf dist && mkdir -p dist && \
-       ./build/build.sh traffic_stats 2>&1 | tee 
./dist/build-traffic_stats.log && \
-       mkdir -p /trafficcontrol/dist && \
-       cp dist/*traffic_stats* /trafficcontrol/dist
+ADD infrastructure/docker/build/clean_build.sh /
+CMD /clean_build.sh traffic_stats
 
 
 # vi:syntax=Dockerfile

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/infrastructure/docker/build/clean_build.sh
----------------------------------------------------------------------
diff --git a/infrastructure/docker/build/clean_build.sh 
b/infrastructure/docker/build/clean_build.sh
new file mode 100755
index 0000000..02bfec5
--- /dev/null
+++ b/infrastructure/docker/build/clean_build.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env sh
+
+set -x
+cp -a /trafficcontrol /tmp/. && \
+       cd /tmp/trafficcontrol && \
+       rm -rf dist && \
+       ln -fs /trafficcontrol/dist dist &&
+       ((((./build/build.sh $1 2>&1; echo $? >&3) | tee ./dist/build-$1.log 
>&4) 3>&1) | (read x; exit $x)) 4>&1

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7604dfb7/pkg
----------------------------------------------------------------------
diff --git a/pkg b/pkg
new file mode 100755
index 0000000..818d71e
--- /dev/null
+++ b/pkg
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+
+# Files are relative to this script directory.
+SELF="${BASH_SOURCE[0]}"
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+COMPOSE_FILE=./infrastructure/docker/build/docker-compose.yml
+
+# Check for dependencies
+if ! which docker-compose >/dev/null 2>&1; then
+       echo "Error: docker-compose is required for a docker build." >&2
+       exit 1
+fi
+
+# Parse command line arguments
+verbose=0
+while getopts lvq? opt; do
+       case $opt in
+               \?)
+                       echo "Usage: $SELF [options] [projects]"
+                       echo "  -q      Quiet mode. Supresses output."
+                       echo "  -v      Verbose mode. Lists all build output."
+                       echo "  -l      List available projects."
+                       echo
+                       echo "  If no projects are listed, all projects will be 
packaged."
+                       echo "  Valid projects:"
+                       $SELF -l | sed "s/^/            - /"
+                       exit 0
+                       ;;
+               q)
+                       exec >/dev/null 2>&1
+                       ;;
+               v)
+                       verbose=1
+                       ;;
+               l)
+                       docker-compose -f $COMPOSE_FILE config --services
+                       exit $?
+                       ;;
+       esac
+done
+
+shift $((OPTIND-1))
+
+# If no specific packages are listed, run them all.
+if (( ! "$#" )); then
+       set -- `$SELF -l`
+fi
+
+# Build each project in turn.
+failure=0
+badproj=""
+while (( "$#" )); do
+       echo Building $1.
+       (
+               if (( "$verbose" == 0 )); then
+                       exec >/dev/null 2>&1
+               fi
+               docker-compose -f $COMPOSE_FILE build $1 || exit 1
+               docker-compose -f $COMPOSE_FILE run --rm $1 || exit 1
+       ) || {
+               # Don't totally bail out, but make note of the failures.
+               failure=1
+               badproj="$badproj $1"
+       }
+       shift
+done
+
+if (( $failure )); then
+       echo "Failed to build$badproj."
+fi
+
+exit $failure

Reply via email to