Sean Abraham | 12ebc39 | 2020-11-19 15:45:30 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # Populates a directory with everything necessary to build a remote test driver |
| 8 | # container. |
| 9 | |
Seewai Fu | 3f930a3 | 2020-12-29 17:27:29 -0800 | [diff] [blame] | 10 | # BuildAndCopyTastItems builds and copies all Tast related executables |
| 11 | # and data to targets. |
| 12 | BuildAndCopyTastItems() { |
| 13 | # Emerge tast related executables. |
| 14 | sudo emerge tast-cmd |
| 15 | sudo emerge tast-remote-tests-cros |
| 16 | local tast_dir="$1/tast" |
| 17 | local tast_bin_dir="${tast_dir}/bin" |
| 18 | # Copy tast related items. |
| 19 | mkdir -p "${tast_bin_dir}" |
| 20 | cp /usr/bin/tast "${tast_bin_dir}" |
| 21 | cp /usr/bin/tast_rtd "${tast_bin_dir}" |
| 22 | cp /usr/bin/remote_test_runner "${tast_bin_dir}" |
| 23 | cp -pdr /usr/libexec/tast/bundles "${tast_dir}" |
| 24 | cp -pdr /usr/share/tast/data "${tast_dir}" |
| 25 | cp -pdr /etc/tast/vars "${tast_dir}" |
| 26 | cp -pdr /home/"${USER}"/trunk/chromite/ssh_keys "${tast_dir}" |
| 27 | } |
| 28 | |
Sean Abraham | 12ebc39 | 2020-11-19 15:45:30 -0700 | [diff] [blame] | 29 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
| 30 | . "${script_dir}/common.sh" || exit 1 |
| 31 | |
| 32 | # Script must run inside the chroot |
| 33 | assert_inside_chroot "$@" |
| 34 | |
| 35 | # Do not run as root |
| 36 | assert_not_root_user |
| 37 | |
| 38 | DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies" |
| 39 | |
| 40 | # Parse command line flags |
| 41 | FLAGS "$@" || exit 1 |
| 42 | eval set -- "${FLAGS_ARGV}" |
| 43 | |
| 44 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 45 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 46 | switch_to_strict_mode |
| 47 | |
| 48 | output_dir="${FLAGS_output_dir}" |
| 49 | if [[ -z "${FLAGS_output_dir}" ]]; then |
| 50 | info "No --output_dir provided. Using temp dir instead" |
| 51 | output_dir=$(mktemp -d) |
| 52 | fi |
| 53 | |
| 54 | if [[ ! -d "${output_dir}" ]]; then |
| 55 | error "output_dir ${output_dir} must exist as a directory" |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | if [[ -n "$(ls -A "${output_dir}")" ]]; then |
| 60 | error "output_dir ${output_dir} must be empty" |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | # Write out a simple Dockerfile. |
| 65 | cat > "${output_dir}/Dockerfile" <<- EOF |
| 66 | FROM ubuntu:bionic |
| 67 | WORKDIR /usr/src/rtd/ |
| 68 | COPY rtd/ . |
| 69 | EOF |
| 70 | |
| 71 | # Create the remote test driver folder and copy test content into it. |
| 72 | rtd_dir="${output_dir}/rtd" |
| 73 | mkdir "${rtd_dir}" |
| 74 | # Build and copy the tnull (fake) RTD. |
| 75 | sudo emerge tnull |
| 76 | cp /usr/bin/tnull "${rtd_dir}/" |
Seewai Fu | 3f930a3 | 2020-12-29 17:27:29 -0800 | [diff] [blame] | 77 | |
Sean Abraham | 12ebc39 | 2020-11-19 15:45:30 -0700 | [diff] [blame] | 78 | # tast and tauto entries will eventually go here. |
Seewai Fu | 3f930a3 | 2020-12-29 17:27:29 -0800 | [diff] [blame] | 79 | BuildAndCopyTastItems "${rtd_dir}" |
Sean Abraham | 12ebc39 | 2020-11-19 15:45:30 -0700 | [diff] [blame] | 80 | |
| 81 | command_completed |
| 82 | info "Done. Wrote output to ${output_dir}" |