crosvm/ci/run_container.sh
Dennis Kempin 191b95b5d7 native and aarch64 cross-compile containers
This CL adds the foundation for running tests consistently
in Kokoro and locally, for both x86 and aarch64.

The crosvm_builder is similar to the original image from
docker/crosvm.Dockerfile.
The main difference is that ChromeOS dependencies are not
compiled into the container, but built at runtime.

The crosvm_aarch64_builder installs the build enviornment
to cross-compile crosvm for aarch64. The tests are run
with user-space emulation using qemu-aarch64-static.

See ci/README.md for instructions on how to use these
builders.

Tests on aarch64 cannot all be run using user-space
emulation. We will need a VM to pass all smoke tests,
this work is tracked in b/177228167.

BUG=b:177133814
TEST=Tested by running
./ci/builder bin/smoke_test
./ci/builder cargo test
./ci/aarch64_builder cargo build
./ci/aarch64_builder cargo test -p tempfile

Change-Id: Iffffcf48894787dd72fff894af351fdaced0b429
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2621994
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-01-20 17:41:27 +00:00

49 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# Copyright 2021 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
#
# Runs a crosvm builder. Will use podman if available, falls back to docker.
crosvm_root=$(realpath "$(dirname $0)/..")
cros_root=$(realpath "${crosvm_root}/../../..")
target=$(
cargo metadata --no-deps --format-version 1 | jq -r ".target_directory"
)
if [ ! -d "${cros_root}/.repo" ]; then
echo "The CI builder must be run from a cros checkout. See ci/README.md"
exit 1
fi
# User podman if available for root-less execution. Fall-back to docker.
if which podman >/dev/null; then
run() {
# The run.oci.keep_original_groups flag allows us to access devices to
# which the calling user only has access via a group membership (i.e.
# /dev/kvm). See: https://github.com/containers/podman/issues/4477
podman run \
--runtime /usr/bin/crun \
--annotation run.oci.keep_original_groups=1 \
--cap-add=ALL \
"$@"
}
else
run() {
docker run --privileged "$@"
}
fi
src="${cros_root}/src"
scratch="${target}/ci/$1"
mkdir -p "${scratch}"
run --rm -it \
--device /dev/net \
--device /dev/kvm \
--device /dev/vhost-net \
--device /dev/vhost-vsock \
--volume /dev/log:/dev/log \
--volume "${src}":/workspace/src:rw \
--volume "${scratch}":/workspace/scratch:rw \
"gcr.io/crosvm-packages/$1" \
"${@:2}"