diff options
-rw-r--r-- | Dockerfile | 8 | ||||
-rw-r--r-- | Makefile | 47 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rwxr-xr-x | kokoro/run_tests.sh | 11 | ||||
-rw-r--r-- | test/syscalls/linux/pty.cc | 2 |
5 files changed, 83 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..32ac76f1b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:bionic + +RUN apt-get update && apt-get install -y curl gnupg2 git +RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \ + curl https://bazel.build/bazel-release.pub.gpg | apt-key add - +RUN apt-get update && apt-get install -y bazel && apt-get clean + +WORKDIR /gvisor diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..c70f76504 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +UID := $(shell id -u ${USER}) +GID := $(shell id -g ${USER}) +GVISOR_BAZEL_CACHE := $(shell readlink -f ~/.cache/bazel/) + +all: runsc + +docker-build: + docker build -t gvisor-bazel . + +bazel-shutdown: + docker exec -i gvisor-bazel bazel shutdown && \ + docker kill gvisor-bazel + +bazel-server-start: docker-build + mkdir -p "$(GVISOR_BAZEL_CACHE)" && \ + docker run -d --rm --name gvisor-bazel \ + --user 0:0 \ + -v "$(GVISOR_BAZEL_CACHE):$(HOME)/.cache/bazel/" \ + -v "$(CURDIR):$(CURDIR)" \ + --workdir "$(CURDIR)" \ + --tmpfs /tmp \ + --privileged \ + gvisor-bazel \ + sh -c "while :; do sleep 100; done" && \ + docker exec --user 0:0 -i gvisor-bazel sh -c "groupadd --gid $(GID) gvisor && useradd --uid $(UID) --gid $(GID) -d $(HOME) gvisor" + +bazel-server: + docker exec gvisor-bazel true || \ + $(MAKE) bazel-server-start + +BAZEL_OPTIONS := build runsc +bazel: bazel-server + docker exec -u $(UID):$(GID) -i gvisor-bazel bazel $(BAZEL_OPTIONS) + +bazel-alias: + @echo "alias bazel='docker exec -u $(UID):$(GID) -i gvisor-bazel bazel'" + +runsc: + $(MAKE) BAZEL_OPTIONS="build runsc" bazel + +tests: + $(MAKE) BAZEL_OPTIONS="test --test_tag_filters runsc_ptrace //test/syscalls/..." bazel + +unit-tests: + $(MAKE) BAZEL_OPTIONS="test //pkg/... //runsc/... //tools/..." bazel + +.PHONY: docker-build bazel-shutdown bazel-server-start bazel-server bazel runsc tests @@ -70,6 +70,14 @@ bazel build runsc sudo cp ./bazel-bin/runsc/linux_amd64_pure_stripped/runsc /usr/local/bin ``` +If you don't want to install bazel on your system, you can build runsc in a +Docker container: + +``` +make runsc +sudo cp ./bazel-bin/runsc/linux_amd64_pure_stripped/runsc /usr/local/bin +``` + ### Testing The test suite can be run with Bazel: @@ -78,6 +86,13 @@ The test suite can be run with Bazel: bazel test ... ``` +or in a Docker container: + +``` +make unit-tests +make tests +``` + ### Using remote execution If you have a [Remote Build Execution][rbe] environment, you can use it to speed diff --git a/kokoro/run_tests.sh b/kokoro/run_tests.sh index c5c6a7780..fbe353a1e 100755 --- a/kokoro/run_tests.sh +++ b/kokoro/run_tests.sh @@ -197,6 +197,16 @@ finish() { exit ${exit_code} } +# Run bazel in a docker container +build_in_docker() { + cd ${WORKSPACE_DIR} + bazel clean + bazel shutdown + make + make runsc + make bazel-shutdown +} + ######## # MAIN # ######## @@ -220,6 +230,7 @@ main() { # Build other flavors too. build_everything dbg + build_in_docker # No need to call "finish" here, it will happen at exit. } diff --git a/test/syscalls/linux/pty.cc b/test/syscalls/linux/pty.cc index 0485d187c..f926ac0f9 100644 --- a/test/syscalls/linux/pty.cc +++ b/test/syscalls/linux/pty.cc @@ -18,9 +18,11 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <sys/types.h> #include <termios.h> #include <unistd.h> + #include <iostream> #include "gtest/gtest.h" |