Skip to content

Commit

Permalink
feat: add proto
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <yangpoan@gmail.com>
  • Loading branch information
FrankYang0529 committed Apr 12, 2024
1 parent 0123178 commit 3703d39
Show file tree
Hide file tree
Showing 68 changed files with 38,257 additions and 1 deletion.
90 changes: 90 additions & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
FROM registry.suse.com/bci/bci-base:15.5

ARG DAPPER_HOST_ARCH=amd64
ARG http_proxy
ARG https_proxy
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
ENV PROTOC_VER=24.3
ENV PROTOBUF_VER_PY=4.24.3
ENV PROTOC_GEN_GO_VER=v1.31.0
ENV PROTOC_GEN_GO_GRPC_VER=v1.3.0

# Setup environment
ENV PATH /go/bin:$PATH
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_SOURCE /go/src/github.com/longhorn/types
ENV DAPPER_OUTPUT ./pkg ./generated-py
WORKDIR ${DAPPER_SOURCE}

RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/SLE_15/system:snappy.repo && \
zypper --gpg-auto-import-keys ref

# Install packages
RUN if [ ${ARCH} == "amd64" ]; then \
zypper -n install autoconf libtool libunwind-devel; \
fi

# TODO: replace python311 with python3 if SLE upgrade system python version to python3.10+
RUN zypper -n install wget git tar gzip unzip \
python311 python311-devel python311-pip && \
rm -rf rm -rf /var/cache/zypp/*

# needed for ${!var} substitution
RUN rm -f /bin/sh && ln -s /bin/bash /bin/sh

RUN if [ ${ARCH} == "s390x" ]; then \
ln -s /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc;\
fi

# Install Go
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH_s390x=s390x GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
RUN wget -O - https://storage.googleapis.com/golang/go1.21.7.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local

# protoc
ENV PROTOC_amd64=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-x86_64.zip \
PROTOC_arm64=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-aarch_64.zip \
PROTOC_s390x=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-s390_64.zip \
PROTOC=PROTOC_${ARCH}

RUN cd /usr/src && \
wget ${!PROTOC} -O protoc_${ARCH}.zip && \
unzip protoc_${ARCH}.zip -d /usr/local/

# protoc-gen-go
RUN mkdir -p /go/src/github.com && \
cd /go/src/github.com/ && \
mkdir protocolbuffers/ && \
cd protocolbuffers && \
git clone https://github.com/protocolbuffers/protobuf-go.git && \
cd protobuf-go && \
git checkout ${PROTOC_GEN_GO_VER} && \
cd cmd/protoc-gen-go && \
go build && \
cp protoc-gen-go /usr/local/bin

# protoc-gen-go-grpc
RUN cd /go/src/github.com/ && \
mkdir grpc/ && \
cd grpc && \
git clone https://github.com/grpc/grpc-go.git && \
cd grpc-go && \
git checkout cmd/protoc-gen-go-grpc/${PROTOC_GEN_GO_GRPC_VER} && \
cd cmd/protoc-gen-go-grpc && \
go build && \
cp protoc-gen-go-grpc /usr/local/bin

# use python 3.11, so we can install latest grpcio
RUN ln -sf /usr/bin/python3.11 /usr/bin/python3 & \
ln -sf /usr/bin/pip3.11 /usr/bin/pip3

# python grpc-tools
RUN if [ "${ARCH}" == "s390x" ]; then \
zypper -n in libopenssl-devel && \
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=True pip3 install grpcio==1.58.0 grpcio_tools==1.58.0 protobuf==${PROTOBUF_VER_PY}; \
else \
pip3 install grpcio==1.58.0 grpcio_tools==1.58.0 protobuf==${PROTOBUF_VER_PY}; \
fi

ENTRYPOINT ["./scripts/entry"]
CMD ["ci"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TARGETS := $(shell ls scripts)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

$(TARGETS): .dapper
./.dapper $@

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# types
# longhorn types

## Dependencies

* protoc 24.3
* protoc-gen-go 1.31.0
* protoc-gen-go-grpc 1.3.0
* python protobuf 4.24.3

## Generate protobuf files

```
make generate_grpc
```
66 changes: 66 additions & 0 deletions generated-py/bimrpc/bimrpc_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3703d39

Please sign in to comment.