Skip to content

Commit

Permalink
Adding utilities to run buf in Docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
andream16 committed Oct 14, 2024
1 parent a3ac4e8 commit bfff3bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,32 @@ build_buf_container:
$(DOCKER) build . -t $(BUF_CONTAINER) -f containers/Dockerfile.buf

run_buf: build_buf_container
$(DOCKER) run --volume "$(shell pwd):/workspace" --workdir /workspace $(BUF_CONTAINER) $(ARGS)
$(eval BUF_TMP_DP_FOLDER:=buf-tmp)
@if [ ! -d "$(BUF_TMP_DP_FOLDER)" ]; then mkdir $(BUF_TMP_DP_FOLDER); fi
$(DOCKER) run \
--volume "$(shell pwd):/workspace" \
--volume $(BUF_TMP_DP_FOLDER):/tmp \
--workdir /workspace \
$(BUF_CONTAINER) \
$(ARGS)
@rm -rf $(BUF_TMP_DP_FOLDER)

fmt-proto: build_buf_container
@echo "Tidying up Proto files"
$(MAKE) run_buf ARGS="format -w"
$(MAKE) run_buf ARGS="format -w --exclude-path vendor/"

lint-proto: build_buf_container
@echo "Linting Proto files"
$(MAKE) run_buf ARGS="lint --exclude-path vendor"
$(MAKE) run_buf ARGS="lint --exclude-path vendor/"

generate-proto: build_buf_container
@echo "Generating Proto files"
$(MAKE) run_buf ARGS="generate"

dep-update-proto:
@echo "Updating buf.lock deps"
$(MAKE) run_buf ARGS="dep update"

########################################
########### RELEASE UTILITIES ##########
########################################
Expand Down
11 changes: 10 additions & 1 deletion containers/Dockerfile.buf
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Setup Go alpine to install protoc-gen-go plugin.
FROM golang:alpine AS golang
ENV GO111MODULE=on

RUN go install google.golang.org/protobuf/cmd/[email protected]

# Setup Buf to have buf available.
FROM bufbuild/buf:1.45.0 AS buf

# Add diffutils and its dependencies, which are needed by buf format.
FROM alpine AS diffutils
RUN apk add --no-cache diffutils
RUN mkdir /deps && ldd /usr/bin/diff | tr -s '[:blank:]' '\n' | grep '^/' | xargs -I '{}' cp --parents '{}' /deps

# Wrap everything together in a scratch container to do all things buf.
FROM scratch
COPY --from=golang /go/bin/protoc-gen-go /go/bin/protoc-gen-go
COPY --from=buf /usr/local/bin/buf /usr/local/bin/buf
COPY --from=diffutils /usr/bin/diff /usr/bin/diff
COPY --from=diffutils /deps /
ENV PATH="/go/bin:${PATH}"
ENTRYPOINT ["/usr/local/bin/buf"]

0 comments on commit bfff3bc

Please sign in to comment.