Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
entrypoint: '/usr/bin/make'
args:
- 'DOCKER_NETWORK=cloudbuild'
- 'BAZEL_CONFIG=${_BAZEL_CONFIG}'
- 'OPTIONS=${_OPTIONS}'
- '${_TARGET}'
substitutions:
_OPTIONS: ''
_BAZEL_CONFIG: ''
_TARGET: 'default'
options:
machineType: 'N1_HIGHCPU_8'
logStreamingOption: STREAM_ON
timeout: 3600s
33 changes: 23 additions & 10 deletions tools/bazel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BRANCH_NAME := $(shell (git branch --show-current 2>/dev/null || \
xargs -n 1 basename 2>/dev/null)

# Bazel container configuration (see below).
USER ?= gvisor
USER ?= $(shell whoami)
HASH ?= $(shell readlink -m $(CURDIR) | md5sum | cut -c1-8)
BUILDER_BASE := gvisor.dev/images/default
BUILDER_IMAGE := gvisor.dev/images/builder
Expand Down Expand Up @@ -53,7 +53,15 @@ ifeq (true,$(shell [[ -t 0 ]] && echo true))
FULL_DOCKER_EXEC_OPTIONS += --tty
endif

# Add our group, if non-root.
ifneq (0,$(GID))
GROUPADD_DOCKER += groupadd --gid $(GID) --non-unique $(USER) &&
endif

# Add docker passthrough options.
ifneq ($(DOCKER_NETWORK),)
FULL_DOCKER_RUN_OPTIONS += --network=$(DOCKER_NETWORK)
endif
ifneq ($(DOCKER_PRIVILEGED),)
FULL_DOCKER_RUN_OPTIONS += -v "$(DOCKER_SOCKET):$(DOCKER_SOCKET)"
FULL_DOCKER_RUN_OPTIONS += $(DOCKER_PRIVILEGED)
Expand All @@ -66,6 +74,18 @@ FULL_DOCKER_RUN_OPTIONS += --group-add $(DOCKER_GROUP)
endif
endif

# Add our user with appropriate options, if non-root.
#
# NOTE: we pass -l to useradd below because otherwise you can hit a bug
# best described here:
# ttps://github.com/moby/moby/issues/5419#issuecomment-193876183
#
# TL;DR: trying to add to /var/log/lastlog (sparse file) runs the machine out
# out of disk space.
ifneq (0,$(UID))
USERADD_DOCKER += useradd -l --uid $(UID) --non-unique --no-create-home --gid $(GID) $(USERADD_OPTIONS) -d $(HOME) $(USER) &&
endif

# Add KVM passthrough options.
ifneq (,$(wildcard /dev/kvm))
FULL_DOCKER_RUN_OPTIONS += --device=/dev/kvm
Expand All @@ -82,19 +102,12 @@ ifneq (,$(BAZEL_CONFIG))
OPTIONS += --config=$(BAZEL_CONFIG)
endif

# NOTE: we pass -l to useradd below because otherwise you can hit a bug
# best described here:
# https://github.com/moby/moby/issues/5419#issuecomment-193876183
# TLDR; trying to add to /var/log/lastlog (sparse file) runs the machine out
# out of disk space.
bazel-image: load-default
@if docker ps --all | grep $(BUILDER_NAME); then docker rm -f $(BUILDER_NAME); fi
docker run --user 0:0 --entrypoint "" --name $(BUILDER_NAME) \
$(BUILDER_BASE) \
sh -c "groupadd --gid $(GID) --non-unique $(USER) && \
$(GROUPADD_DOCKER) \
useradd -l --uid $(UID) --non-unique --no-create-home \
--gid $(GID) $(USERADD_OPTIONS) -d $(HOME) $(USER) && \
sh -c "$(GROUPADD_DOCKER) \
$(USERADD_DOCKER) \
if [[ -e /dev/kvm ]]; then chmod a+rw /dev/kvm; fi"
docker commit $(BUILDER_NAME) $(BUILDER_IMAGE)
@docker rm -f $(BUILDER_NAME)
Expand Down