gvisor: run bazel in a docker container

bazel has a lot of dependencies and users don't want to install them
just to build gvisor.

These changes allows to run bazel in a docker container.
A bazel cache is on the local file system (~/.cache/bazel), so
incremental builds should be fast event after recreating a bazel
container.

Here is an example how to build runsc:
make BAZEL_OPTIONS="build runsc:runsc" bazel

Change-Id: I8c0a6d0c30e835892377fb6dd5f4af7a0052d12a
PiperOrigin-RevId: 246570877
This commit is contained in:
Andrei Vagin
2019-05-03 14:13:08 -07:00
committed by Shentubot
parent 24d8656585
commit 9e1c253fe8
5 changed files with 83 additions and 0 deletions
+8
View File
@@ -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
+47
View File
@@ -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
+15
View File
@@ -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
+11
View File
@@ -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.
}
+2
View File
@@ -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"