Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] Removing generated proto files for golang. #3222

Merged
merged 9 commits into from
Dec 13, 2024
Merged
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
37 changes: 37 additions & 0 deletions .github/actions/go/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,41 @@ runs:
- uses: actions/setup-go@v5
with:
cache-dependency-path: go/go.sum

- uses: ariga/setup-atlas@v0

- name: Install protobuf compiler (protoc)
run: |
sudo apt-get update
sudo apt-get install -y wget unzip
wget https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-x86_64.zip
sudo unzip protoc-28.2-linux-x86_64.zip -d /usr/local/
sudo rm protoc-28.2-linux-x86_64.zip
shell: bash

- name: Add Go bin to PATH
run: |
export PATH="$PATH:$(go env GOPATH)/bin"
shell: bash

- name: Install protoc-gen-go
run: |
go install google.golang.org/protobuf/cmd/[email protected]
shell: bash

- name: Install protoc-gen-go-grpc
run: |
go install google.golang.org/grpc/cmd/[email protected]
shell: bash

- name: Add Go bin to PATH
run: |
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash

- name: Verify protoc and plugins
run: |
protoc --version
protoc-gen-go --version
protoc-gen-go-grpc --version
shell: bash
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docker_build(
docker_build(
'local:logservice',
'.',
only=['go/'],
only=['go/', 'idl/'],
dockerfile='./go/Dockerfile',
target='logservice'
)
Expand Down
40 changes: 32 additions & 8 deletions go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
FROM golang:bookworm AS builder
WORKDIR /build-dir
RUN apt-get update && apt-get install -y make git bash
RUN apt-get update && apt-get install -y make git bash protobuf-compiler unzip curl

ADD ./go/go.mod ./go.mod
ADD ./go/go.sum ./go.sum
# Install a specific version of protoc
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-x86_64.zip && \
unzip protoc-28.2-linux-x86_64.zip -d /usr/local/ && \
rm protoc-28.2-linux-x86_64.zip && \
chmod +x /usr/local/bin/protoc

# Set the PATH to include Go binaries
ENV PATH=$PATH:/root/go/bin

# Copy the Go source code and protobuf files
ADD ./go/ ./go
ADD ./idl/ ./idl
ADD ./go/go.mod ./go/go.mod
ADD ./go/go.sum ./go/go.sum
WORKDIR /build-dir/go
RUN go mod download

ADD ./go/ ./
# Install protoc Go plugins
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN go install google.golang.org/grpc/cmd/[email protected]

ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" make

WORKDIR /build-dir/go
# Generate protobuf files
# RUN --mount=type=cache,target="/root/.cache/go-build" go generate ./...
# Run 'make proto' to generate protobuf files
RUN --mount=type=cache,target="/root/.cache/go-build" make proto

# Build the Go binaries
RUN --mount=type=cache,target="/root/.cache/go-build" make build

FROM debian:bookworm-slim AS logservice
COPY --from=builder /build-dir/bin/logservice .
COPY --from=builder /build-dir/go/bin/logservice .
ENV PATH=$PATH:./
CMD ["./logservice"]

FROM debian:bookworm-slim AS sysdb
COPY --from=builder /build-dir/bin/coordinator .
COPY --from=builder /build-dir/go/bin/coordinator .
ENV PATH=$PATH:./
CMD /bin/bash
CMD /bin/bash
28 changes: 26 additions & 2 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
.PHONY: build
build:
.PHONY: build test lint clean docker proto log_db_clean log_db_generate log_db_migration

PROTOC_GEN_GO_BIN_PATH := $(if $(shell which protoc-gen-go),$(shell which protoc-gen-go),"${GOPATH}/bin/protoc-gen-go")
PROTOC_GEN_GO_GRPC_BIN_PATH := $(if $(shell which protoc-gen-go-grpc),$(shell which protoc-gen-go-grpc),"${GOPATH}/bin/protoc-gen-go-grpc")

proto:
@echo "Generating gRPC code for Golang..."
@mkdir -p pkg/proto/coordinatorpb pkg/proto/logservicepb
@protoc \
-I../idl/ \
--go_out=pkg/proto/coordinatorpb \
--go_opt paths=source_relative \
--plugin protoc-gen-go="$(PROTOC_GEN_GO_BIN_PATH)" \
--go-grpc_out=pkg/proto/coordinatorpb \
--go-grpc_opt paths=source_relative \
--plugin protoc-gen-go-grpc="$(PROTOC_GEN_GO_GRPC_BIN_PATH)" \
../idl/chromadb/proto/chroma.proto \
../idl/chromadb/proto/coordinator.proto \
../idl/chromadb/proto/logservice.proto
@mv pkg/proto/coordinatorpb/chromadb/proto/logservice*.go pkg/proto/logservicepb/
@mv pkg/proto/coordinatorpb/chromadb/proto/*.go pkg/proto/coordinatorpb/
@rm -rf pkg/proto/coordinatorpb/chromadb
@echo "Done"

build: proto
go build -v -o bin/coordinator ./cmd/coordinator/
go build -v -o bin/logservice ./cmd/logservice/

Expand All @@ -13,6 +36,7 @@ lint:

clean:
rm -f bin/chroma
rm -rf pkg/proto/coordinatorpb pkg/proto/logservicepb

docker:
docker build -t chroma-coordinator:latest .
Expand Down
Loading
Loading