From 2c75d5d6a7c26e27c09f0e39eca975e34d43e2e6 Mon Sep 17 00:00:00 2001 From: Cody Littley <56973212+cody-littley@users.noreply.github.com> Date: Thu, 5 Sep 2024 08:01:24 -0500 Subject: [PATCH] Created dockerized workflow for building protobufs. (#734) Signed-off-by: Cody Littley --- api/builder/Dockerfile | 30 ++++++++++++++++++++++++++++++ api/builder/README.md | 23 +++++++++++++++++++++++ api/builder/build-docker.sh | 12 ++++++++++++ api/builder/build-protobufs.sh | 10 ++++++++++ api/builder/clean.sh | 5 +++++ api/builder/debug.sh | 14 ++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 api/builder/Dockerfile create mode 100644 api/builder/README.md create mode 100755 api/builder/build-docker.sh create mode 100755 api/builder/build-protobufs.sh create mode 100755 api/builder/clean.sh create mode 100755 api/builder/debug.sh diff --git a/api/builder/Dockerfile b/api/builder/Dockerfile new file mode 100644 index 000000000..97fc309b5 --- /dev/null +++ b/api/builder/Dockerfile @@ -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/protoc-gen-go@v1.28.1' +RUN bash -c 'source ~/.bashrc && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0' diff --git a/api/builder/README.md b/api/builder/README.md new file mode 100644 index 000000000..7e6a5688a --- /dev/null +++ b/api/builder/README.md @@ -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. diff --git a/api/builder/build-docker.sh b/api/builder/build-docker.sh new file mode 100755 index 000000000..1ae4147ba --- /dev/null +++ b/api/builder/build-docker.sh @@ -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 \ + . \ No newline at end of file diff --git a/api/builder/build-protobufs.sh b/api/builder/build-protobufs.sh new file mode 100755 index 000000000..5c0c1fd27 --- /dev/null +++ b/api/builder/build-protobufs.sh @@ -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' diff --git a/api/builder/clean.sh b/api/builder/clean.sh new file mode 100755 index 000000000..2485fc6c5 --- /dev/null +++ b/api/builder/clean.sh @@ -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 \ No newline at end of file diff --git a/api/builder/debug.sh b/api/builder/debug.sh new file mode 100755 index 000000000..2f9cfa73f --- /dev/null +++ b/api/builder/debug.sh @@ -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 +