mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
dev_container: Improve support for podman
Commit 95b80d1
made the dev container persistent between invocations,
but hard-coded `docker` again. This change fixes that and also adds
further improvements:
- Do not use `--privileged` with podman. If the rootless user has
permissions to access `/dev/kvm`, so will the container.
- Map `/dev/vhost-net` and `/dev/vhost-vsock` as well.
- Use `BASH_SOURCE` to find this script's directory. As we're using Bash
to start with, this is more robust than using plain `$0`.
BUG=None
TEST=Run `./tools/dev_container cargo build` with Podman and Docker
Change-Id: I05c699f327c8e1c4f3c4df9679ee92bf7e609e2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3295372
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
This commit is contained in:
parent
2d45b91e00
commit
1a2cfa90c3
1 changed files with 15 additions and 5 deletions
|
@ -21,7 +21,7 @@
|
|||
# ./tools/dev_container --hermetic CMD
|
||||
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
# Allow to override the container CLI tool, similar to the Makefile. Try
|
||||
# "docker" first and fall back to "podman".
|
||||
|
@ -41,13 +41,23 @@ if [ -t 1 ]; then
|
|||
)
|
||||
fi
|
||||
|
||||
# Podman will not share devices when `--privileged` is specified
|
||||
PRIV_ARGS=()
|
||||
if [ "${DOCKER}" != "${podman}" ]; then
|
||||
PRIV_ARGS+=(
|
||||
--privileged
|
||||
)
|
||||
fi
|
||||
|
||||
DOCKER_ARGS=(
|
||||
"${TTY_ARGS[@]}"
|
||||
--volume "$(pwd):/workspace:rw"
|
||||
--device "/dev/net/tun"
|
||||
--device "/dev/kvm"
|
||||
--volume "/dev/log:/dev/log"
|
||||
--privileged
|
||||
--device "/dev/net/tun"
|
||||
--device "/dev/vhost-net"
|
||||
--device "/dev/vhost-vsock"
|
||||
"${PRIV_ARGS[@]}"
|
||||
"gcr.io/crosvm-packages/crosvm_dev:$IMAGE_VERSION"
|
||||
)
|
||||
|
||||
|
@ -62,7 +72,7 @@ docker_run() {
|
|||
}
|
||||
|
||||
get_container_id() {
|
||||
docker ps -q -f name="${CONTAINER_NAME}"
|
||||
"${DOCKER}" ps -q -f name="${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
docker_exec() {
|
||||
|
@ -77,7 +87,7 @@ docker_exec() {
|
|||
main() {
|
||||
if [[ "$1" == "--stop" ]]; then
|
||||
if [ -n "$(get_container_id)" ]; then
|
||||
docker rm -f "$(get_container_id)" >/dev/null
|
||||
"${DOCKER}" rm -f "$(get_container_id)" >/dev/null
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue