Bug 1247168 - Add a script to perform a checkout then run a command; r?dustin
The script will be used as the main command in task YAML files.
It changes ownership of caches. Then switches to the "worker" user.
Then performs a Gecko checkout. Then executes whatever command was
requested via its arguments.
The script has been added to the shared recipes directory so it can
eventually be used by other Docker images. This means if we e.g. want
to add Git support, we only need to update one file in the tree.
MozReview-Commit-ID: Fuy1VrdSGYn
--- a/testing/docker/lint/Dockerfile
+++ b/testing/docker/lint/Dockerfile
@@ -8,16 +8,20 @@ RUN mkdir /build
# %include testing/docker/decision/tooltool.py
ADD topsrcdir/testing/docker/decision/tooltool.py /build/tooltool.py
# %include testing/docker/recipes/install-mercurial.sh
ADD topsrcdir/testing/docker/recipes/install-mercurial.sh /build/install-mercurial.sh
ADD system-setup.sh /tmp/system-setup.sh
RUN bash /tmp/system-setup.sh
+# %include testing/docker/recipes/checkout-gecko-and-run
+ADD topsrcdir/testing/docker/recipes/checkout-gecko-and-run /home/worker/bin/checkout-gecko-and-run
+RUN chown -R worker:worker /home/worker/bin && chmod 755 /home/worker/bin/*
+
# Set variable normally configured at login, by the shells parent process, these
# are taken from GNU su manual
ENV HOME /home/worker
ENV SHELL /bin/bash
ENV USER worker
ENV LOGNAME worker
ENV HOSTNAME taskcluster-worker
ENV LANG en_US.UTF-8
new file mode 100755
--- /dev/null
+++ b/testing/docker/recipes/checkout-gecko-and-run
@@ -0,0 +1,37 @@
+#!/bin/bash
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+set -ex
+
+# The script starts executing as root. We need to change ownership
+# of the caches because they are initially owned by root:root. There
+# may not be a cache mount/directory on some instances. So create the
+# directory if missing.
+if [ $(id -u) = 0 ]; then
+ mkdir -p /home/worker/workspace
+ chown worker:worker /home/worker/hg-shared /home/worker/workspace
+
+ exec sudo -E -u worker ${0} "${@}"
+fi
+
+DEST=$1
+shift
+
+# We set the base repository to mozilla-central so tc-vcs doesn't get
+# confused. Switch to mozilla-unified because robustcheckout works best
+# with it.
+if [ "${GECKO_BASE_REPOSITORY}" = "https://hg.mozilla.org/mozilla-central" ]; then
+ GECKO_BASE_REPOSITORY=https://hg.mozilla.org/mozilla-unified
+fi
+
+/usr/bin/hg robustcheckout \
+ --sharebase /home/worker/hg-shared \
+ --purge \
+ --upstream ${GECKO_BASE_REPOSITORY} \
+ --revision ${GECKO_HEAD_REV} \
+ ${GECKO_HEAD_REPOSITORY} \
+ ${DEST}
+
+exec "${@}"