Skip to content

Commit

Permalink
'make protoc' now utilizes docker workflow by default. (Layr-Labs#748)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley authored Sep 20, 2024
1 parent 09c300e commit 45f6941
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 37 deletions.
29 changes: 7 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,22 @@ endif

RELEASE_TAG := $(or $(RELEASE_TAG),latest)

PROTOS := ./api/proto
PROTOS_DISPERSER := ./disperser/api/proto
PROTO_GEN := ./api/grpc
PROTO_GEN_DISPERSER_PATH = ./disperser/api/grpc

compile-el:
cd contracts && ./compile.sh compile-el

compile-dl:
cd contracts && ./compile.sh compile-dl

clean:
find $(PROTO_GEN) -name "*.pb.go" -type f | xargs rm -rf
mkdir -p $(PROTO_GEN)
find $(PROTO_GEN_DISPERSER_PATH) -name "*.pb.go" -type f | xargs rm -rf
mkdir -p $(PROTO_GEN_DISPERSER_PATH)
./api/builder/clean.sh

# Builds the protobuf files inside a docker container.
protoc: clean
protoc -I $(PROTOS) \
--go_out=$(PROTO_GEN) \
--go_opt=paths=source_relative \
--go-grpc_out=$(PROTO_GEN) \
--go-grpc_opt=paths=source_relative \
$(PROTOS)/**/*.proto
# Generate Protobuf for sub directories of ./api/proto/disperser
protoc -I $(PROTOS_DISPERSER) -I $(PROTOS) \
--go_out=$(PROTO_GEN_DISPERSER_PATH) \
--go_opt=paths=source_relative \
--go-grpc_out=$(PROTO_GEN_DISPERSER_PATH) \
--go-grpc_opt=paths=source_relative \
$(PROTOS_DISPERSER)/**/*.proto
./api/builder/protoc-docker.sh

# Builds the protobuf files locally (i.e. without docker).
protoc-local: clean
./api/builder/protoc.sh

lint:
golint -set_exit_status ./...
Expand Down
2 changes: 1 addition & 1 deletion api/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To build the docker image, run the following command:
Once the docker image is built, you can build the protobufs via the following command:

```bash
./api/builder/build-protobufs.sh
./api/builder/protoc-docker.sh
```

# Caveats
Expand Down
10 changes: 0 additions & 10 deletions api/builder/build-protobufs.sh

This file was deleted.

15 changes: 12 additions & 3 deletions api/builder/clean.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env bash

# Cleans the docker image and all cached steps.
docker image rm pbuf-compiler 2> /dev/null || true
docker builder prune -f
# This script finds and deletes all compiled protobufs.

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

API_DIR="${SCRIPT_DIR}/.."
GRPC_DIR="${API_DIR}/grpc"
find "${GRPC_DIR}" -name '*.pb.go' -type f | xargs rm -rf

DISPERSER_DIR="$SCRIPT_DIR/../../disperser"
DISPERSER_GRPC_DIR="$DISPERSER_DIR/api/grpc"
find "${DISPERSER_GRPC_DIR}" -name '*.pb.go' -type f | xargs rm -rf
2 changes: 1 addition & 1 deletion api/builder/debug.sh → api/builder/debug-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# This is a handy little script for debugging the docker container. Attaches a bash shell to the container.
# This is a handy little script for debugging the pbuf-compiler container. Attaches a bash shell to the container.

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down
18 changes: 18 additions & 0 deletions api/builder/protoc-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# This script builds the eigenDA protobufs. It does this by running protoc.sh inside of the pbuf-compiler container.

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT="${SCRIPT_DIR}/../.."

if [ -z "$(docker images -q pbuf-compiler:latest 2> /dev/null)" ]; then
echo "Docker image pbuf-compiler:latest does not exist. Building it now..."
"${SCRIPT_DIR}"/build-docker.sh
fi


docker container run \
--rm \
--mount "type=bind,source=${ROOT},target=/home/user/eigenda" \
pbuf-compiler bash -c "source ~/.bashrc && eigenda/api/builder/protoc.sh"
34 changes: 34 additions & 0 deletions api/builder/protoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# This script builds the eigenDA protobufs.

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Build protobufs in the api/proto directory.

API_DIR="${SCRIPT_DIR}/.."
PROTO_DIR="${API_DIR}/proto"
GRPC_DIR="${API_DIR}/grpc"
mkdir -p "${GRPC_DIR}"

protoc -I "${PROTO_DIR}" \
--go_out="${GRPC_DIR}" \
--go_opt=paths=source_relative \
--go-grpc_out="${GRPC_DIR}" \
--go-grpc_opt=paths=source_relative \
"${PROTO_DIR}"/**/*.proto

# Build protobufs in the disperser/api/proto directory.

DISPERSER_DIR="$SCRIPT_DIR/../../disperser"
DISPERSER_PROTO_DIR="$DISPERSER_DIR/api/proto"
DISPERSER_GRPC_DIR="$DISPERSER_DIR/api/grpc"
mkdir -p "${DISPERSER_GRPC_DIR}"

protoc -I "${DISPERSER_PROTO_DIR}" -I "${PROTO_DIR}" \
--go_out="${DISPERSER_GRPC_DIR}" \
--go_opt=paths=source_relative \
--go-grpc_out="${DISPERSER_GRPC_DIR}" \
--go-grpc_opt=paths=source_relative \
"${DISPERSER_PROTO_DIR}"/**/*.proto
7 changes: 7 additions & 0 deletions api/builder/rm-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# This script fully deletes the pbuf-compiler docker image and all cached steps.

# Cleans the docker image and all cached steps.
docker image rm pbuf-compiler 2> /dev/null || true
docker builder prune -f

0 comments on commit 45f6941

Please sign in to comment.