From 4f4e83faafbaea5c91b5a55da9c60964ed500963 Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Mon, 23 Jun 2025 23:22:54 +0100 Subject: [PATCH] Add UID and GID arguments to grpcbox Docker build for user permissions When building on Linux, often git fails to switch to between branches because generated files aren't owned by the user. This PR fixes that by injecting the UID and GID into the docker container --- build.assets/Dockerfile-grpcbox | 5 +++++ build.assets/grpcbox.mk | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build.assets/Dockerfile-grpcbox b/build.assets/Dockerfile-grpcbox index 52e77d45bb996..225c218587fc4 100644 --- a/build.assets/Dockerfile-grpcbox +++ b/build.assets/Dockerfile-grpcbox @@ -40,3 +40,8 @@ RUN \ go -C /teleport-module run -exec true google.golang.org/grpc/cmd/protoc-gen-go-grpc && \ go -C /teleport-module run -exec true google.golang.org/protobuf/cmd/protoc-gen-go && \ rm -rf /teleport-module + + ARG UID + ARG GID + RUN mkdir -p /.cache /.npm && \ + chown -R $UID:$GID /.cache /.npm /go/pkg/mod/ diff --git a/build.assets/grpcbox.mk b/build.assets/grpcbox.mk index 766c1917822f6..c8d193ff37519 100644 --- a/build.assets/grpcbox.mk +++ b/build.assets/grpcbox.mk @@ -19,7 +19,9 @@ DOCKER ?= docker # GRPCBOX_RUN has the necessary invocation to run a command inside the grpcbox. # Use this variable to run it from other Makefiles. -GRPCBOX_RUN := $(DOCKER) run -it --rm -v "$$(pwd)/../:/workdir" -w /workdir $(GRPCBOX) +UID := $$(id -u) +GID := $$(id -g) +GRPCBOX_RUN := $(DOCKER) run -it --rm -u $(UID):$(GID) -v "$$(pwd)/../:/workdir" -w /workdir $(GRPCBOX) # grpcbox builds a codegen-focused buildbox. # It's leaner, meaner, faster and not supposed to compile code. @@ -27,6 +29,7 @@ GRPCBOX_RUN := $(DOCKER) run -it --rm -v "$$(pwd)/../:/workdir" -w /workdir $(GR grpcbox: $(DOCKER) build \ --build-arg BUF_VERSION=$(BUF_VERSION) \ + --build-arg UID=$(UID) --build-arg GID=$(GID) \ -f Dockerfile-grpcbox \ -t "$(GRPCBOX)" \ ../