Skip to content

Commit

Permalink
Created dockerized workflow for building protobufs. (#734)
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 5, 2024
1 parent 14ca646 commit 2c75d5d
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.21.12-bookworm

# Install core dependencies
RUN apt update
RUN apt install -y wget unzip bash

# Set up user
RUN useradd -m -s /bin/bash user
USER user
WORKDIR /home/user
# Remove default crud
RUN rm .bashrc
RUN rm .bash_logout
RUN rm .profile

# Install protoc
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protoc-23.4-linux-aarch_64.zip
RUN mkdir protoc
RUN cd protoc && unzip ../*.zip
RUN rm ./*.zip

# Setup PATH
RUN touch ~/.bashrc
RUN echo 'export PATH=~/protoc/bin:$PATH' >> ~/.bashrc
RUN echo 'export GOPATH=/go' >> ~/.bashrc
RUN echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.bashrc

# Install go protobuf extensions
RUN bash -c 'source ~/.bashrc && go install google.golang.org/protobuf/cmd/[email protected]'
RUN bash -c 'source ~/.bashrc && go install google.golang.org/grpc/cmd/[email protected]'
23 changes: 23 additions & 0 deletions api/builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This directory contains scripts for building a docker image capable of compiling the EigenDA protobufs. I found
it difficult to control the exact build version of the protobufs, since the version depends on whatever is installed
locally when they are built. This is an attempt to standardize the protobuf build process.

# Usage

To build the docker image, run the following command:

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

Once the docker image is built, you can build the protobufs via the following command:

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

# Caveats

I've tested this on my m3 macbook. It's possible that the docker image may have trouble on other architectures.
Please report any issues you encounter with this build process to the EigenDA team. The goal is to be arcihtecturally
agnostic, but that isn't a priority in the very short term.
12 changes: 12 additions & 0 deletions api/builder/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

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

# Add the --no-cache flag to force a rebuild.
# Add the --progress=plain flag to show verbose output during the build.

docker build \
-f "${SCRIPT_DIR}/Dockerfile" \
--tag pbuf-compiler:latest \
.
10 changes: 10 additions & 0 deletions api/builder/build-protobufs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

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

docker container run \
--rm \
--mount "type=bind,source=${ROOT},target=/home/user/eigenda" \
pbuf-compiler bash -c 'source ~/.bashrc && cd eigenda && make protoc'
5 changes: 5 additions & 0 deletions api/builder/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/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
14 changes: 14 additions & 0 deletions api/builder/debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# This is a handy little script for debugging the docker 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 )
ROOT="${SCRIPT_DIR}/../.."

docker container run \
--rm \
--mount "type=bind,source=${ROOT},target=/home/user/eigenda" \
-it \
pbuf-compiler bash

0 comments on commit 2c75d5d

Please sign in to comment.