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. BUG=chromium:1149702 TEST=ran it locally Exempt-From-Owner-Approval: got verbal approval from saklein for this approach Change-Id: Idf59c0fcb330473006405eb423834ba382e40426 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2551703 Commit-Queue: Sean Abraham <seanabraham@chromium.org> Tested-by: Sean Abraham <seanabraham@chromium.org> Reviewed-by: Alex Klein <saklein@chromium.org> Reviewed-by: Jared Loucks <jaredloucks@google.com> Reviewed-by: Brigit Rossbach <brigitr@google.com>
diff --git a/OWNERS b/OWNERS index 22f19f2..4b66b87 100644 --- a/OWNERS +++ b/OWNERS
@@ -1,5 +1,6 @@ per-file update_kernel.sh = file:/OWNERS.kernel # remote_access.sh is mostly used by update_kernel.sh. per-file remote_access.sh = file:/OWNERS.kernel +per-file create_remote_test_driver = file:chromiumos/chromite:/OWNERS.testplatform include chromiumos/chromite:/OWNERS.build
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 @@ +#!/bin/bash + +# 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}/common.sh" || exit 1 + +# Script must run inside the chroot +assert_inside_chroot "$@" + +# Do not run as root +assert_not_root_user + +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. +switch_to_strict_mode + +output_dir="${FLAGS_output_dir}" +if [[ -z "${FLAGS_output_dir}" ]]; then + info "No --output_dir provided. Using temp dir instead" + output_dir=$(mktemp -d) +fi + +if [[ ! -d "${output_dir}" ]]; then + error "output_dir ${output_dir} must exist as a directory" + exit 1 +fi + +if [[ -n "$(ls -A "${output_dir}")" ]]; then + error "output_dir ${output_dir} must be empty" + exit 1 +fi + +# Write out a simple Dockerfile. +cat > "${output_dir}/Dockerfile" <<- EOF +FROM ubuntu:bionic +WORKDIR /usr/src/rtd/ +COPY rtd/ . +EOF + +# Create the remote test driver folder and copy test content into it. +rtd_dir="${output_dir}/rtd" +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. + +command_completed +info "Done. Wrote output to ${output_dir}"