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 a9525fd commit 10cb877
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,35 @@ dev-deploy: deploy-cluster dev-infra dev-dracon
dev-teardown:
@kind delete clusters dracon-demo

build_buf_container:
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)

fmt-proto: build_buf_container
run-buf: build-buf-container
$(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
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
generate-proto: build-buf-container
@echo "Generating Proto files"
$(MAKE) run_buf ARGS="generate"
$(MAKE) run-buf ARGS="generate"

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

########################################
########### RELEASE UTILITIES ##########
Expand Down
12 changes: 7 additions & 5 deletions containers/Dockerfile.buf
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Setup Go alpine to install buf protoc-gen-go plugin.
# At the time of this changes, the buf image doesn't have a way to customise the plugins, so this is a more concise
# solution.
FROM golang:alpine AS golang
ENV GO111MODULE=on

RUN go install github.com/bufbuild/buf/cmd/[email protected]
RUN go install google.golang.org/protobuf/cmd/[email protected]

FROM bufbuild/buf:1.45.0 AS buf

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

0 comments on commit 10cb877

Please sign in to comment.