You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2021/04/16 17:17:56 UTC

[trafficcontrol] branch master updated: Combine CDN in a Box Dockerfiles using build stage targets where possible (#5710)

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

rawlin 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 c1b7b10  Combine CDN in a Box Dockerfiles using build stage targets where possible (#5710)
c1b7b10 is described below

commit c1b7b10781653675fd4c9407ce9cd048b11e901a
Author: Zach Hoffman <zr...@apache.org>
AuthorDate: Fri Apr 16 11:17:39 2021 -0600

    Combine CDN in a Box Dockerfiles using build stage targets where possible (#5710)
    
    * Make trafficops-debug a build target of the trafficops Dockerfile
    
    * Make trafficmonitor-debug a build target of the trafficmonitor Dockerfile
    
    * Make trafficstats-debug a build target of the trafficstats Dockerfile
    
    * Move mid dockerfile to cache directory
    
    * Make `edge` and `mid` targets of a single Dockerfile
    
    * Remove reference to nonexistent JSON file
    
    * Remove redundant build args
    
    * Remove references to nonexistent services in the documentation
    
    * Update code link line numbers for RELEASE-5.1.1
    
    * Add option to debug the CDN in a Box Enroller
    
    * Fix some typos
    
    * Revert accidental commit
    
    * Add an -f for each compose file specified
    
    * Refer to the service as Enroller, not Traffic Monitor
    
    * Add an "r"
    
    * Mentioned the need to set ENROLLER_DEBUG_ENABLE
    
    * Fix debug configuration paths
---
 docs/source/development/debugging.rst              |  76 +++++++---
 .../cdn-in-a-box/{edge => cache}/Dockerfile        |   7 +-
 infrastructure/cdn-in-a-box/docker-compose.yml     |  19 ++-
 infrastructure/cdn-in-a-box/enroller/Dockerfile    |  27 +++-
 infrastructure/cdn-in-a-box/enroller/run.sh        |  19 ++-
 infrastructure/cdn-in-a-box/mid/Dockerfile         | 158 ---------------------
 .../optional/docker-compose.debugging.yml          |  52 ++-----
 .../cdn-in-a-box/traffic_monitor/Dockerfile        |  13 +-
 .../cdn-in-a-box/traffic_monitor/Dockerfile-debug  |  36 -----
 infrastructure/cdn-in-a-box/traffic_ops/Dockerfile |  12 +-
 .../cdn-in-a-box/traffic_ops/Dockerfile-debug      |  34 -----
 infrastructure/cdn-in-a-box/traffic_ops/config.sh  |   3 -
 .../cdn-in-a-box/traffic_stats/Dockerfile          |  13 +-
 .../cdn-in-a-box/traffic_stats/Dockerfile-debug    |  36 -----
 infrastructure/cdn-in-a-box/variables.env          |   2 +
 15 files changed, 163 insertions(+), 344 deletions(-)

diff --git a/docs/source/development/debugging.rst b/docs/source/development/debugging.rst
index c5d98fd..41aeae1 100644
--- a/docs/source/development/debugging.rst
+++ b/docs/source/development/debugging.rst
@@ -24,11 +24,51 @@ Debugging inside CDN-in-a-Box
 
 Some CDN-in-a-Box components can be used with a debugger to step through lines of code, set breakpoints, see the state of all variables in each scope, etc. at runtime. Components that support debugging:
 
+* `Enroller`_
 * `Traffic Monitor`_
 * `Traffic Ops`_
 * `Traffic Router`_
 * `Traffic Stats`_
 
+Enroller
+========
+
+* In ``infrastructure/cdn-in-a-box``, open ``variables.env`` and set ``ENROLLER_DEBUG_ENABLE`` to ``true``.
+
+* Stop CDN-in-a-Box if it is running and remove any existing volumes. Build/rebuild the ``enroller-debug`` image each time you have changed :atc-file:`infrastructure/cdn-in-a-box/enroller/enroller.go`. Then, start CDN-in-a-Box.
+
+.. code-block:: shell
+	:caption: docker-compose command for debugging the CDN in a Box Enroller
+
+	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml -f optional/docker-compose.debugging.yml'
+	mydc down -v
+	mydc build enroller
+	mydc up
+
+* Install `an IDE that supports delve <https://github.com/go-delve/delve/blob/master/Documentation/EditorIntegration.md>`_ and create a debugging configuration over port 2343. If you are using VS Code, the configuration should look like this:
+
+.. code-block:: json
+	:caption: VS Code launch.json for debugging the CDN in a Box Enroller
+
+	{
+		"version": "0.2.0",
+		"configurations": [
+			{
+				"name": "Enroller",
+				"type": "go",
+				"request": "attach",
+				"mode": "remote",
+				"port": 2343,
+				"cwd": "${workspaceRoot}/",
+				"remotePath": "/go/src/github.com/apache/trafficcontrol/",
+			}
+		]
+	}
+
+* Use the debugging configuration you created to start debugging the Enroller. It should connect without first breaking at any line.
+
+For an example of usage, set a breakpoint at `the toSession.CreateDeliveryServiceV30() call in enrollDeliveryService() <https://github.com/apache/trafficcontrol/blob/RELEASE-5.1.1/infrastructure/cdn-in-a-box/enroller/enroller.go#L209>`_, then wait for the Enroller to process a file from ``/shared/enroller/deliveryservices/`` (only exists within the Docker container).
+
 Traffic Monitor
 ===============
 
@@ -44,14 +84,14 @@ Traffic Monitor
 
 * Still in ``infrastructure/cdn-in-a-box``, open ``variables.env`` and set ``TM_DEBUG_ENABLE`` to ``true``.
 
-* Stop CDN-in-a-Box if it is running and remove any existing volumes. Rebuild the ``trafficmonitor`` image to make sure it uses our fresh ``traffic_monitor.rpm``. Then, start CDN-in-a-Box.
+* Stop CDN-in-a-Box if it is running and remove any existing volumes. Build the ``trafficmonitor-debug`` image to make sure it uses our fresh ``traffic_monitor.rpm``. Then, start CDN-in-a-Box:
 
 .. code-block:: shell
 	:caption: docker-compose command for debugging Traffic Monitor
 
-	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml optional/docker-compose.debugging.yml'
+	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml -f optional/docker-compose.debugging.yml'
 	mydc down -v
-	mydc build trafficmonitor-nondebug trafficmonitor
+	mydc build trafficmonitor
 	mydc up
 
 * Install `an IDE that supports delve <https://github.com/go-delve/delve/blob/master/Documentation/EditorIntegration.md>`_ and create a debugging configuration over port 2344. If you are using VS Code, the configuration should look like this:
@@ -68,15 +108,15 @@ Traffic Monitor
 				"request": "attach",
 				"mode": "remote",
 				"port": 2344,
-				"cwd": "${workspaceRoot}/traffic_monitor",
-				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol/traffic_monitor",
+				"cwd": "${workspaceRoot}",
+				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol",
 			}
 		]
 	}
 
 * Use the debugging configuration you created to start debugging Traffic Monitor. It should connect without first breaking at any line.
 
-For an example of usage, set a breakpoint at `the o.m.RLock() call in ThreadsafeEvents.Get() <https://github.com/apache/trafficcontrol/blob/RELEASE-4.0.0-RC3/traffic_monitor/health/event.go#L69>`_, then visit http://trafficmonitor.infra.ciab.test/publish/EventLog (see :ref:`Traffic Monitor APIs: /publish/EventLog <tm-publish-EventLog>`).
+For an example of usage, set a breakpoint at `the o.m.RLock() call in ThreadsafeEvents.Get() <https://github.com/apache/trafficcontrol/blob/RELEASE-5.1.1/traffic_monitor/health/event.go#L71>`_, then visit http://trafficmonitor.infra.ciab.test/publish/EventLog (see :ref:`Traffic Monitor APIs: /publish/EventLog <tm-publish-EventLog>`).
 
 Traffic Ops
 ===========
@@ -93,14 +133,14 @@ Traffic Ops
 
 * Still in ``infrastructure/cdn-in-a-box``, open ``variables.env`` and set ``TO_DEBUG_ENABLE`` to ``true``.
 
-* Stop CDN-in-a-Box if it is running and remove any existing volumes. Rebuild the ``trafficops-go`` image to make sure it uses our fresh ``traffic_ops.rpm``. Then, start CDN-in-a-Box.
+* Stop CDN-in-a-Box if it is running and remove any existing volumes. Build the ``trafficops-debug`` image to make sure it uses our fresh ``traffic_ops.rpm``. Then, start CDN-in-a-Box:
 
 .. code-block:: shell
 	:caption: docker-compose command for debugging Traffic Ops
 
-	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml optional/docker-compose.debugging.yml'
+	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml -f optional/docker-compose.debugging.yml'
 	mydc down -v
-	mydc build trafficops-nondebug trafficops
+	mydc build trafficops
 	mydc up
 
 * Install `an IDE that supports delve <https://github.com/go-delve/delve/blob/master/Documentation/EditorIntegration.md>`_ and create a debugging configuration over port 2345. If you are using VS Code, the configuration should look like this:
@@ -117,15 +157,15 @@ Traffic Ops
 				"request": "attach",
 				"mode": "remote",
 				"port": 2345,
-				"cwd": "${workspaceRoot}/traffic_ops/traffic_ops_golang",
-				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang",
+				"cwd": "${workspaceRoot}",
+				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol",
 			}
 		]
 	}
 
 * Use the debugging configuration you created to start debugging Traffic Ops. It should connect without first breaking at any line.
 
-For an example of usage, set a breakpoint at `the log.Debugln() call in TOProfile.Read() <https://github.com/apache/trafficcontrol/blob/RELEASE-4.0.0-RC3/traffic_ops/traffic_ops_golang/profile/profiles.go#L129>`_, then visit https://trafficportal.infra.ciab.test/api/1.5/profiles (after logging into :ref:`tp-overview`).
+For an example of usage, set a breakpoint at `the log.Debugln() call in TOProfile.Read() <https://github.com/apache/trafficcontrol/blob/RELEASE-5.1.1/traffic_ops/traffic_ops_golang/profile/profiles.go#L148>`_, then visit https://trafficportal.infra.ciab.test/api/1.5/profiles (after logging into :ref:`tp-overview`).
 
 Traffic Router
 ==============
@@ -241,14 +281,14 @@ Traffic Stats
 
 * Still in ``infrastructure/cdn-in-a-box``, open ``variables.env`` and set ``TS_DEBUG_ENABLE`` to ``true``.
 
-* Stop CDN-in-a-Box if it is running and remove any existing volumes. Rebuild the ``trafficstats`` image to make sure it uses our fresh ``traffic_stats.rpm``. Then, start CDN-in-a-Box.
+* Stop CDN-in-a-Box if it is running and remove any existing volumes. Build the ``trafficstats-debug`` image to make sure it uses our fresh ``traffic_stats.rpm``. Then, start CDN-in-a-Box:
 
 .. code-block:: shell
 	:caption: docker-compose command for debugging Traffic Stats
 
-	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml optional/docker-compose.debugging.yml'
+	alias mydc='docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml -f optional/docker-compose.debugging.yml'
 	mydc down -v
-	mydc build trafficstats-nondebug trafficstats
+	mydc build trafficstats
 	mydc up
 
 * Install `an IDE that supports delve <https://github.com/go-delve/delve/blob/master/Documentation/EditorIntegration.md>`_ and create a debugging configuration over port 2346. If you are using VS Code, the configuration should look like this:
@@ -265,15 +305,15 @@ Traffic Stats
 				"request": "attach",
 				"mode": "remote",
 				"port": 2346,
-				"cwd": "${workspaceRoot}/traffic_stats",
-				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol/traffic_stats",
+				"cwd": "${workspaceRoot}",
+				"remotePath": "/tmp/go/src/github.com/apache/trafficcontrol",
 			}
 		]
 	}
 
 * Use the debugging configuration you created to start debugging Traffic Stats. It should connect without first breaking at any line.
 
-For an example of usage, set a breakpoint at `the http.Get() call in main.getURL() <https://github.com/apache/trafficcontrol/blob/RELEASE-4.1.0/traffic_stats/traffic_stats.go#L727>`_, then wait 10 seconds for the breakpoint to be hit.
+For an example of usage, set a breakpoint at `the http.Get() call in main.getURL() <https://github.com/apache/trafficcontrol/blob/RELEASE-5.1.1/traffic_stats/traffic_stats.go#L706>`_, then wait 10 seconds for the breakpoint to be hit.
 
 Troubleshooting
 ===============
diff --git a/infrastructure/cdn-in-a-box/edge/Dockerfile b/infrastructure/cdn-in-a-box/cache/Dockerfile
similarity index 98%
rename from infrastructure/cdn-in-a-box/edge/Dockerfile
rename to infrastructure/cdn-in-a-box/cache/Dockerfile
index f4e50cb..2c0ba7d 100644
--- a/infrastructure/cdn-in-a-box/edge/Dockerfile
+++ b/infrastructure/cdn-in-a-box/cache/Dockerfile
@@ -150,9 +150,10 @@ ARG ORT_RPM=infrastructure/cdn-in-a-box/cache/traffic_ops_ort.rpm
 ADD $ORT_RPM /
 RUN rpm -Uvh --nodeps /$(basename $ORT_RPM) &&\
     rm /$(basename $ORT_RPM)
+CMD /run.sh
 
-FROM common-cache-server-layers AS edge
+FROM common-cache-server-layers AS mid
+COPY infrastructure/cdn-in-a-box/mid/init.d/ /opt/init.d/
 
+FROM common-cache-server-layers AS edge
 COPY infrastructure/cdn-in-a-box/edge/init.d/ /opt/init.d/
-
-CMD /run.sh
diff --git a/infrastructure/cdn-in-a-box/docker-compose.yml b/infrastructure/cdn-in-a-box/docker-compose.yml
index 4ab76ee..f3e5df0 100644
--- a/infrastructure/cdn-in-a-box/docker-compose.yml
+++ b/infrastructure/cdn-in-a-box/docker-compose.yml
@@ -137,6 +137,7 @@ services:
       dockerfile: traffic_stats/Dockerfile
       args:
         RHEL_VERSION: ${RHEL_VERSION:-8}
+        TRAFFIC_TS_RPM: traffic_stats/traffic_stats.rpm
     image: trafficstats
     depends_on:
       - enroller
@@ -185,7 +186,11 @@ services:
     privileged: True
     build:
       context: ../..
-      dockerfile: infrastructure/cdn-in-a-box/edge/Dockerfile
+      dockerfile: infrastructure/cdn-in-a-box/cache/Dockerfile
+      target: edge
+      args:
+        RHEL_VERSION: ${RHEL_VERSION:-8}
+        ORT_RPM: infrastructure/cdn-in-a-box/cache/traffic_ops_ort.rpm
     domainname: infra.ciab.test
     env_file:
       - variables.env
@@ -198,7 +203,11 @@ services:
     privileged: True
     build:
       context: ../..
-      dockerfile: infrastructure/cdn-in-a-box/mid/Dockerfile
+      dockerfile: infrastructure/cdn-in-a-box/cache/Dockerfile
+      target: mid
+      args:
+        RHEL_VERSION: ${RHEL_VERSION:-8}
+        ORT_RPM: infrastructure/cdn-in-a-box/cache/traffic_ops_ort.rpm
     domainname: infra.ciab.test
     env_file:
       - variables.env
@@ -211,7 +220,11 @@ services:
     privileged: True
     build:
       context: ../..
-      dockerfile: infrastructure/cdn-in-a-box/mid/Dockerfile
+      dockerfile: infrastructure/cdn-in-a-box/cache/Dockerfile
+      target: mid
+      args:
+        RHEL_VERSION: ${RHEL_VERSION:-8}
+        ORT_RPM: infrastructure/cdn-in-a-box/cache/traffic_ops_ort.rpm
     domainname: infra.ciab.test
     env_file:
       - variables.env
diff --git a/infrastructure/cdn-in-a-box/enroller/Dockerfile b/infrastructure/cdn-in-a-box/enroller/Dockerfile
index 419dad8..82efaca 100644
--- a/infrastructure/cdn-in-a-box/enroller/Dockerfile
+++ b/infrastructure/cdn-in-a-box/enroller/Dockerfile
@@ -16,6 +16,7 @@
 # under the License.
 
 FROM debian:buster AS enroller-builder
+ARG ENROLLER_DEBUG_BUILD=false
 
 RUN apt-get update && \
     apt-get install -y --no-install-recommends \
@@ -41,9 +42,25 @@ COPY ./traffic_ops/v4-client/ /go/src/github.com/apache/trafficcontrol/traffic_o
 COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
 
 WORKDIR /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/enroller
-RUN go clean && go mod vendor -v && go build
+RUN set -o errexit -o nounset; \
+    go clean; \
+    go mod vendor -v; \
+    gcflags= ldflags=; \
+    tags='usergo netgo'; \
+    if [ "$ENROLLER_DEBUG_BUILD" = true ]; then \
+        apt-get install -y --no-install-recommends gcc libstdc++-8-dev; \
+        echo 'Building Enroller without optimization or inlining'; \
+        gcflags='all=-N -l'; \
+    else \
+        echo 'Optimizing Enroller build'; \
+        ldflags='-s -w'; \
+    fi; \
+    go build -ldflags "$ldflags" -gcflags "$gcflags" -tags "$tags"
 
-FROM debian:buster
+FROM enroller-builder as get-delve
+RUN go get -u github.com/go-delve/delve/cmd/dlv
+
+FROM debian:buster AS enroller
 
 RUN apt-get update && apt-get install -y \
         netcat curl dnsutils net-tools \
@@ -63,3 +80,9 @@ COPY infrastructure/cdn-in-a-box/dns/set-dns.sh \
 
 WORKDIR /shared/enroller
 CMD /run.sh
+
+FROM enroller AS enroller-debug
+COPY --from=get-delve /go/bin /usr/bin
+
+# Makes enroller the last/default stage in the Dockerfile
+FROM enroller AS enroller
diff --git a/infrastructure/cdn-in-a-box/enroller/run.sh b/infrastructure/cdn-in-a-box/enroller/run.sh
index 6e8a57b..5721827 100755
--- a/infrastructure/cdn-in-a-box/enroller/run.sh
+++ b/infrastructure/cdn-in-a-box/enroller/run.sh
@@ -33,8 +33,8 @@ export TO_PASSWORD=$TO_ADMIN_PASSWORD
 # Wait on SSL certificate generation
 until [[ -f "$X509_CA_ENV_FILE" ]]
 do
-     echo "Waiting on Shared SSL certificate generation"
-     sleep 3
+  echo "Waiting on Shared SSL certificate generation"
+  sleep 3
 done
 
 # Source the CIAB-CA shared SSL environment
@@ -51,20 +51,25 @@ update-ca-certificates
 
 # Traffic Ops must be accepting connections before enroller can start
 until nc -z $TO_FQDN $TO_PORT </dev/null >/dev/null && to-ping; do
-    echo "Waiting for $TO_URL"
-    sleep 5
+  echo "Waiting for $TO_URL"
+  sleep 5
 done
 
 mkdir -p "$ENROLLER_DIR"
 if [[ ! -d $ENROLLER_DIR ]]; then
-     echo "enroller dir ${ENROLLER_DIR} not found or not a directory"
-     exit 1
+  echo "enroller dir ${ENROLLER_DIR} not found or not a directory"
+  exit 1
 fi
 
 # clear out the enroller dir first so no files left from previous run
 rm -rf ${ENROLLER_DIR}/*
 
-/enroller -dir "$ENROLLER_DIR" &
+enroller_command=(/enroller -dir "$ENROLLER_DIR");
+if [[ "$ENROLLER_DEBUG_ENABLE" == true ]]; then
+  enroller_command=(dlv '--continue' '--listen=:2343' '--accept-multiclient=true' '--headless=true' '--api-version=2' exec \
+  "${enroller_command[0]}" -- "${enroller_command[@]:1}")
+fi;
+"${enroller_command[@]}" &
 
 source /to-access.sh
 # Enroll with traffic ops
diff --git a/infrastructure/cdn-in-a-box/mid/Dockerfile b/infrastructure/cdn-in-a-box/mid/Dockerfile
deleted file mode 100644
index 591a3eb..0000000
--- a/infrastructure/cdn-in-a-box/mid/Dockerfile
+++ /dev/null
@@ -1,158 +0,0 @@
-# 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 Edge-Tier Cache container images for
-# Apache Traffic Control
-# Based on CentOS 8
-############################################################
-
-ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION} AS common-cache-server-layers
-ARG RHEL_VERSION=8
-
-RUN if [[ "${RHEL_VERSION%%.*}" -eq 7 ]]; then \
-        yum -y install dnf || exit 1; \
-    fi
-
-EXPOSE 80
-
-RUN dnf -y install epel-release && \
-    if [[ "${RHEL_VERSION%%.*}" -ge 8 ]]; then \
-        additional_packages='compat-openssl10 pkgconf-pkg-config' || \
-        exit 1; \
-    else \
-        additional_packages=openssl || \
-        exit 1; \
-    fi && \
-    dnf -y install              \
-        GeoIP                   \
-        groff-base              \
-        hwloc                   \
-        hwloc-libs              \
-        kyotocabinet-libs       \
-        libtool-ltdl            \
-        libunwind               \
-        lzo                     \
-        make                    \
-        numactl-libs            \
-        perl                    \
-        perl-Carp               \
-        perl-constant           \
-        perl-Data-Dumper        \
-        perl-Encode             \
-        perl-Exporter           \
-        perl-File-Path          \
-        perl-File-Temp          \
-        perl-Filter             \
-        perl-Getopt-Long        \
-        perl-HTTP-Tiny          \
-        perl-libs               \
-        perl-macros             \
-        perl-parent             \
-        perl-PathTools          \
-        perl-Pod-Escapes        \
-        perl-podlators          \
-        perl-Pod-Perldoc        \
-        perl-Pod-Simple         \
-        perl-Pod-Usage          \
-        perl-Scalar-List-Utils  \
-        perl-Socket             \
-        perl-Storable           \
-        perl-Text-ParseWords    \
-        perl-threads            \
-        perl-threads-shared     \
-        perl-Time-HiRes         \
-        perl-Time-Local         \
-        perl-URI                \
-        tcl                     \
-        $additional_packages && \
-    if [[ "${RHEL_VERSION%%.*}" -eq 8 ]]; then \
-        set -- \
-            # Pretend that we have the right library versions.
-            # TODO: Use a proper CentOS 7 or 8 RPM once trafficserver
-            # is in EPEL again (see apache/trafficserver#6855)
-            libtcl8.6.so        libtcl8.5.so     \
-            libncursesw.so.6    libncursesw.so.5 \
-            libtinfo.so.6       libtinfo.so.5    \
-            || exit 1; \
-    fi && \
-    cd /usr/lib64 && \
-    while [[ $# -gt 0 ]]; do \
-        source="$1" && \
-        shift && \
-        target="$1" && \
-        shift && \
-        ln -s "$source" "$target" || exit 1; \
-    done
-
-ADD https://ci.trafficserver.apache.org/RPMS/CentOS7/trafficserver-7.1.4-2.el7.x86_64.rpm /trafficserver.rpm
-ADD https://ci.trafficserver.apache.org/RPMS/CentOS7/trafficserver-devel-7.1.4-2.el7.x86_64.rpm /trafficserver-devel.rpm
-
-RUN rpm -Uvh --nodeps /trafficserver.rpm /trafficserver-devel.rpm && \
-    dnf install -y jq python3-psutil python3-setuptools python3-pip logrotate && \
-    dnf clean all
-
-RUN dnf install -y bind-utils kyotocabinet-libs initscripts iproute net-tools nmap-ncat gettext autoconf automake libtool gcc-c++ cronie glibc-devel openssl-devel
-
-RUN python3 -m pip install --upgrade pip && python3 -m pip install requests urllib3 distro
-
-ADD traffic_server/plugins/astats_over_http/astats_over_http.c traffic_server/plugins/astats_over_http/Makefile.am /
-
-RUN tsxs -v -c astats_over_http.c -o astats_over_http.so
-
-# The symbolic link here is a shim for broken atstccfg behavior - remove when it's fixed.
-RUN mkdir -p /usr/libexec/trafficserver /opt/ort /opt/trafficserver/etc/trafficserver/ /opt/init.d && ln -s /opt/trafficserver/etc/trafficserver/ssl /etc/trafficserver/ssl && tsxs -v -o astats_over_http.so -i
-
-RUN dnf remove -y gcc-c++ glibc-devel autoconf automake libtool && rm -f /astats_over_http.c /Makefile.am
-
-# You need to do this because the RPM in the ATS archives is just all kinds of messed-up
-RUN chmod 755 /usr/lib64/trafficserver /etc/trafficserver/body_factory /etc/trafficserver/body_factory/default
-RUN mkdir -p /var/trafficserver /opt/ort && \
-    dd if=/dev/zero bs=1M count=1000 of=/var/trafficserver/cache && \
-    chown -R ats:ats /etc/trafficserver/ /var/trafficserver/ /opt/ort /usr/lib64/trafficserver/ && \
-    sed -i 's/STRING 8080 8080:ipv6/STRING 80 80:ipv6/' /etc/trafficserver/records.config
-
-RUN setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_server && setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_manager && setcap CAP_NET_BIND_SERVICE=+eip /bin/trafficserver && setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_cop
-
-WORKDIR /opt
-
-ADD infrastructure/cdn-in-a-box/ort /opt/ort/
-ADD traffic_control/clients/python /opt/Apache-TrafficControl/
-
-RUN touch /var/log/ort.log && \
-	pip3 install ./Apache-TrafficControl && \
-	pip3 install ./ort && \
-	cp ort/traffic_ops_ort.crontab /etc/cron.d/traffic_ops_ort-cron-template && \
-	cp ort/traffic_ops_ort.logrotate /etc/logrotate.d/ort
-
-ADD infrastructure/cdn-in-a-box/cache/run.sh infrastructure/cdn-in-a-box/traffic_ops/to-access.sh infrastructure/cdn-in-a-box/enroller/server_template.json /
-
-COPY infrastructure/cdn-in-a-box/dns/set-dns.sh \
-     infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh \
-     /usr/local/sbin/
-
-ARG ORT_RPM=infrastructure/cdn-in-a-box/cache/traffic_ops_ort.rpm
-ADD $ORT_RPM /
-RUN rpm -Uvh --nodeps /$(basename $ORT_RPM) &&\
-    rm /$(basename $ORT_RPM)
-
-FROM common-cache-server-layers AS mid
-
-COPY infrastructure/cdn-in-a-box/mid/init.d/ /opt/init.d/
-
-CMD /run.sh
diff --git a/infrastructure/cdn-in-a-box/optional/docker-compose.debugging.yml b/infrastructure/cdn-in-a-box/optional/docker-compose.debugging.yml
index 2447bd2..ae60501 100644
--- a/infrastructure/cdn-in-a-box/optional/docker-compose.debugging.yml
+++ b/infrastructure/cdn-in-a-box/optional/docker-compose.debugging.yml
@@ -21,62 +21,32 @@
 version: '2.1'
 
 services:
+  enroller:
+    build:
+      target: enroller-debug
+      args:
+        ENROLLER_DEBUG_BUILD: 'true'
+    image: enroller-debug
+    ports:
+      - "2343:2343" #Delve debugging port
   trafficmonitor:
     build:
-      context: .
-      dockerfile: traffic_monitor/Dockerfile-debug
+      target: trafficmonitor-debug
     image: trafficmonitor-debug
     ports:
       - "2344:2344" #Delve debugging port
-    depends_on:
-      - trafficmonitor-nondebug
   trafficops:
     build:
-      context: .
-      dockerfile: traffic_ops/Dockerfile-debug
+      target: trafficops-debug
     image: trafficops-debug
     ports:
       - "2345:2345" #Delve debugging port
-    depends_on:
-      - trafficops-nondebug
   trafficrouter:
     ports:
       - "5005:5005" # JPDA debugging port
   trafficstats:
     build:
-      context: .
-      dockerfile: traffic_stats/Dockerfile-debug
+      target: trafficstats-debug
     image: trafficstats-debug
     ports:
       - "2346:2346" #Delve debugging port
-    depends_on:
-      - trafficstats-nondebug
-
-  # The trafficmonitor-nondebug service exists to ensure that the trafficmonitor
-  # base image exists before building trafficmonitor-debug.
-  trafficmonitor-nondebug:
-    image: trafficmonitor
-    build:
-      context: .
-      dockerfile: traffic_monitor/Dockerfile
-      args:
-        TRAFFIC_MONITOR_RPM: traffic_monitor/traffic_monitor.rpm
-    command: /usr/bin/true
-  # The trafficops-nondebug service ensures that the trafficops base image
-  # exists before trying to build trafficops-debug.
-  trafficops-nondebug:
-    image: trafficops
-    build:
-      context: ../../
-      dockerfile: infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
-    command: /usr/bin/true
-  # The trafficstats-nondebug service exists to ensure that the trafficstats
-  # base image exists before building trafficstats-debug.
-  trafficstats-nondebug:
-    image: trafficstats
-    build:
-      context: .
-      dockerfile: traffic_stats/Dockerfile
-      args:
-        TRAFFIC_STATS_RPM: traffic_stats/traffic_stats.rpm
-    command: /usr/bin/true
diff --git a/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile b/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile
index ffa9ab2..6961700 100644
--- a/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile
@@ -20,7 +20,7 @@
 ############################################################
 
 ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION}
+FROM centos:${RHEL_VERSION} as trafficmonitor
 ARG RHEL_VERSION=8
 
 RUN if [[ "${RHEL_VERSION%%.*}" -eq 7 ]]; then \
@@ -62,3 +62,14 @@ ADD traffic_monitor/run.sh /
 CMD /run.sh
 HEALTHCHECK --interval=10s --timeout=1s \
     CMD bash -c 'source /to-access.sh && [[ "$(curl -s http://trafficmonitor.infra.ciab.test/api/traffic-ops-uri)" == "$TO_URL" ]]'
+
+FROM trafficmonitor as get-delve
+
+RUN dnf -y install golang git && \
+    go get -u github.com/go-delve/delve/cmd/dlv
+
+FROM trafficmonitor as trafficmonitor-debug
+COPY --from=get-delve /root/go/bin /usr/bin
+
+# Makes trafficmonitor the last/default stage in the Dockerfile
+FROM trafficmonitor as trafficmonitor
diff --git a/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile-debug b/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile-debug
deleted file mode 100644
index 4a8a4fe..0000000
--- a/infrastructure/cdn-in-a-box/traffic_monitor/Dockerfile-debug
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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 Monitor debugging container image
-# Based on CentOS
-############################################################
-
-ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION} as get-delve
-ARG RHEL_VERSION=8
-
-RUN if [[ "${RHEL_VERSION%%.*}" -eq 7 ]]; then \
-        yum -y install dnf || exit 1; \
-    fi
-
-RUN dnf -y install epel-release && \
-    dnf -y install golang git && \
-    go get -u github.com/go-delve/delve/cmd/dlv
-
-FROM trafficmonitor
-COPY --from=get-delve /root/go/bin /usr/bin
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
index 2cca7bb..4214f6d 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
@@ -21,7 +21,7 @@
 ############################################################
 
 ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION}
+FROM centos:${RHEL_VERSION} as trafficops
 ARG RHEL_VERSION=8
 # Makes RHEL_VERSION available in later layers without needing to specify it again
 ENV RHEL_VERSION=$RHEL_VERSION
@@ -124,3 +124,13 @@ EXPOSE 443
 CMD /run-go.sh
 HEALTHCHECK --interval=10s --timeout=1s \
 	CMD bash -c 'source /to-access.sh && [[ "$(curl -sk "https://${TO_FQDN}/api/${TO_API_VERSION}/ping" | jq .ping)" == \"pong\" ]]'
+
+FROM trafficops as get-delve
+
+RUN go get -u github.com/go-delve/delve/cmd/dlv
+
+FROM trafficops AS trafficops-debug
+COPY --from=get-delve /root/go/bin /usr/bin
+
+# Makes trafficops the last/default stage in the Dockerfile
+FROM trafficops AS trafficops
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-debug b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-debug
deleted file mode 100644
index 3023bfd..0000000
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-debug
+++ /dev/null
@@ -1,34 +0,0 @@
-# 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 Ops container images
-# Based on CentOS 8
-############################################################
-ARG CENTOS_VERSION=8
-FROM centos:${CENTOS_VERSION} as get-delve
-
-RUN if [[ "${CENTOS_VERSION%%.*}" -eq 7 ]]; then \
-		yum -y install dnf || exit 1; \
-	fi
-
-RUN dnf -y install epel-release && \
-    dnf -y install golang git && \
-    go get -u github.com/go-delve/delve/cmd/dlv
-
-FROM trafficops
-COPY --from=get-delve /root/go/bin /usr/bin
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/config.sh b/infrastructure/cdn-in-a-box/traffic_ops/config.sh
index 264763b..c5bb745 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/config.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/config.sh
@@ -66,9 +66,6 @@ if [[ "$TO_DEBUG_ENABLE" == true ]]; then
   DEBUGGING_TIMEOUT=$(( 60 * 60 * 24 )); # Timing out debugging after 1 day seems fair
 fi;
 
-
-echo "$(<postinstall.json envsubst)" >postinstall.json
-
 cdn_conf=/opt/traffic_ops/app/conf/cdn.conf
 >"$cdn_conf" echo "$(jq -s '.[0] * .[1]' "$cdn_conf" <(cat <<-EOF
 {
diff --git a/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile b/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile
index 1f09127..0bcd37f 100644
--- a/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile
@@ -20,7 +20,7 @@
 ############################################################
 
 ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION}
+FROM centos:${RHEL_VERSION} AS trafficstats
 ARG RHEL_VERSION=8
 
 RUN if [[ "${RHEL_VERSION%%.*}" -eq 7 ]]; then \
@@ -54,3 +54,14 @@ COPY dns/set-dns.sh \
      /usr/local/sbin/
 
 ENTRYPOINT /run.sh
+
+FROM trafficstats AS get-delve
+
+RUN dnf -y install golang git && \
+    go get -u github.com/go-delve/delve/cmd/dlv
+
+FROM trafficstats AS trafficstats-debug
+COPY --from=get-delve /root/go/bin /usr/bin
+
+# Makes trafficstats the last/default stage in the Dockerfile
+FROM trafficstats AS trafficstats
diff --git a/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile-debug b/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile-debug
deleted file mode 100644
index 976e0c4..0000000
--- a/infrastructure/cdn-in-a-box/traffic_stats/Dockerfile-debug
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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 Monitor debugging container image
-# Based on CentOS
-############################################################
-
-ARG RHEL_VERSION=8
-FROM centos:${RHEL_VERSION} as get-delve
-ARG RHEL_VERSION=8
-
-RUN if [[ "${RHEL_VERSION%%.*}" -eq 7 ]]; then \
-        yum -y install dnf || exit 1; \
-    fi
-
-RUN dnf -y install epel-release && \
-    dnf -y install golang git && \
-    go get -u github.com/go-delve/delve/cmd/dlv
-
-FROM trafficstats
-COPY --from=get-delve /root/go/bin /usr/bin
diff --git a/infrastructure/cdn-in-a-box/variables.env b/infrastructure/cdn-in-a-box/variables.env
index c9777b5..8b28e9d 100644
--- a/infrastructure/cdn-in-a-box/variables.env
+++ b/infrastructure/cdn-in-a-box/variables.env
@@ -72,6 +72,8 @@ TM_LOG_DEBUG=stdout
 TO_ADMIN_PASSWORD=twelve12
 TO_ADMIN_USER=admin
 TO_ADMIN_FULL_NAME=James Cole
+# Set ENROLLER_DEBUG_ENABLE to true`to debug the enroller with Delve
+ENROLLER_DEBUG_ENABLE=false
 # Set TM_DEBUG_ENABLE to true`to debug Traffic Monitor with Delve
 TM_DEBUG_ENABLE=false
 # Set TO_DEBUG_ENABLE to true`to debug Traffic Ops with Delve