build-unit-test-docker: Customize image at the end

We no longer rely on the depcache to determine when to rebuild our
packages since they are now built based on the sha hash. We would delete
this but it is still used by some of the unit test scripting for
determining what dependencies our environment already has.

Also, lets do some of the cheap customizations at the end so that
intermediate containers can be more readily re-used.

Change-Id: Ibc9ae9239d693490db85bd1fb78fd8e72f75bde3
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/build-unit-test-docker.sh b/build-unit-test-docker.sh
index b9831d5..ccbfaaf 100755
--- a/build-unit-test-docker.sh
+++ b/build-unit-test-docker.sh
@@ -218,19 +218,6 @@
 make -j$(nproc) && \
 make install
 
-RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
-RUN mkdir -p $(dirname ${HOME})
-RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
-
-RUN echo '${AUTOM4TE}' > ${AUTOM4TE_CFG}
-
-# Sneaky use of Dockerfile semantics! Force a rebuild of the image if master
-# has been updated in any of the repositories in \$PKGS: This happens as a
-# consequence of the ls-remotes above, which will change the contents of
-# \${DEPCACHE_FILE} and therefore trigger rebuilds of all of the following layers.
-# NOTE: The file is sorted to ensure the ordering is stable.
-RUN echo '$(sort "$DEPCACHE_FILE" | tr '\n' ',')' > /root/.depcache
-
 RUN curl -L https://github.com/openbmc/sdbusplus/archive/${PKG_REV['sdbusplus']}.tar.gz | tar -xz && \
 cd sdbusplus-* && \
 ./bootstrap.sh && \
@@ -280,6 +267,18 @@
 make -j$(nproc) && \
 make install
 
+RUN echo '${AUTOM4TE}' > ${AUTOM4TE_CFG}
+
+# Some of our infrastructure still relies on the presence of this file
+# even though it is no longer needed to rebuild the docker environment
+# NOTE: The file is sorted to ensure the ordering is stable.
+RUN echo '$(LC_COLLATE=C sort -s "$DEPCACHE_FILE" | tr '\n' ',')' > /root/.depcache
+
+# Final configuration for the workspace
+RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
+RUN mkdir -p $(dirname ${HOME})
+RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
+
 RUN /bin/bash
 EOF
 )