create_remote_test_driver: add a script to make a buildable RTD image

This is roughly what we'll need our new Build API endpoint to invoke.
It'll poke into the SDK, generate a folder containing a Dockerfile and
supporting source files, then return that folder path back to the
builder. The builder will then somehow build the docker image.

I talked about this with Alex, and we agreed that it makes sense to just
have this as a shell script for now. We can move the whole thing into
chromite as a Python script if that becomes necessary. Even now, the
Build API can just call out to this script if it wants.

TEST=ran it locally

Exempt-From-Owner-Approval: got verbal approval from saklein for this approach
Change-Id: Idf59c0fcb330473006405eb423834ba382e40426
Commit-Queue: Sean Abraham <>
Tested-by: Sean Abraham <>
Reviewed-by: Alex Klein <>
Reviewed-by: Jared Loucks <>
Reviewed-by: Brigit Rossbach <>
diff --git a/OWNERS b/OWNERS
index 22f19f2..4b66b87 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,5 +1,6 @@
 per-file = file:/OWNERS.kernel
 # is mostly used by
 per-file = file:/OWNERS.kernel
+per-file create_remote_test_driver = file:chromiumos/chromite:/OWNERS.testplatform
 include chromiumos/chromite:/
diff --git a/create_remote_test_driver b/create_remote_test_driver
new file mode 100755
index 0000000..1607ddf
--- /dev/null
+++ b/create_remote_test_driver
@@ -0,0 +1,61 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+# Populates a directory with everything necessary to build a remote test driver
+# container.
+readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
+. "${script_dir}/" || exit 1
+# Script must run inside the chroot
+assert_inside_chroot "$@"
+# Do not run as root
+DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies"
+# Parse command line flags
+FLAGS "$@" || exit 1
+eval set -- "${FLAGS_ARGV}"
+# Only now can we die on error.  shflags functions leak non-zero error codes,
+# so will die prematurely if 'switch_to_strict_mode' is specified before now.
+if [[ -z "${FLAGS_output_dir}" ]]; then
+  info "No --output_dir provided. Using temp dir instead"
+  output_dir=$(mktemp -d)
+if [[ ! -d "${output_dir}" ]]; then
+  error "output_dir ${output_dir} must exist as a directory"
+  exit 1
+if [[ -n "$(ls -A "${output_dir}")" ]]; then
+  error "output_dir ${output_dir} must be empty"
+  exit 1
+# Write out a simple Dockerfile.
+cat > "${output_dir}/Dockerfile" <<- EOF
+FROM ubuntu:bionic
+WORKDIR /usr/src/rtd/
+COPY rtd/ .
+# Create the remote test driver folder and copy test content into it.
+mkdir "${rtd_dir}"
+# Build and copy the tnull (fake) RTD.
+sudo emerge tnull
+cp /usr/bin/tnull "${rtd_dir}/"
+# tast and tauto entries will eventually go here.
+info "Done. Wrote output to ${output_dir}"