summaryrefslogtreecommitdiffhomepage
path: root/Makefile
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-05-03 14:11:55 -0700
committerShentubot <shentubot@google.com>2019-05-03 14:13:08 -0700
commit9e1c253fe814c85a316520bd6bd258adaa71df79 (patch)
tree688af9574f7d71aa144c1ba0c74b416542edbb0f /Makefile
parent24d8656585e6072ff7d5a00a7eb4bd25cba42dc4 (diff)
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
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile47
1 files changed, 47 insertions, 0 deletions
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