Bug 1247168 - Add a script to perform a checkout then run a command; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Thu, 21 Jul 2016 14:57:37 -0700
changeset 392547 407b2c584d56c95e9d9b23781539f2979a775893
parent 392546 db4990bcde0503fd14d82a5d16c71adbb4f92be3
child 392548 2bec5dd9d6fe5565831bb35f195859aa12dd0bf2
push id24050
push userbmo:gps@mozilla.com
push dateMon, 25 Jul 2016 20:07:35 +0000
reviewersdustin
bugs1247168
milestone50.0a1
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
testing/docker/lint/Dockerfile
testing/docker/recipes/checkout-gecko-and-run
--- 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 "${@}"