Skip to content

Instantly share code, notes, and snippets.

@sebnyberg
Created September 29, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebnyberg/55ee930d1d982c3bac122f0ee5431d05 to your computer and use it in GitHub Desktop.
Save sebnyberg/55ee930d1d982c3bac122f0ee5431d05 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
rm -rf out
rm -rf docs
mkdir out
protofiles=$(find . -type f -regextype posix-extended -regex ".*.proto")
mkdir -p out/{go,openapi,py,cs,js}
for f in ${protofiles}; do
# Go
protoc \
--go_out ./out/go \
--go_opt paths=source_relative \
--go-grpc_out ./out/go \
--go-grpc_opt paths=source_relative \
--grpc-gateway_out ./out/go \
--grpc-gateway_opt paths=source_relative,logtostderr=true \
--openapiv2_out ./out/openapi \
--openapiv2_opt logtostderr=true \
"$f"
# generate python files
python3 -m grpc_tools.protoc \
-I . \
--python_out ./out/py \
--grpc_python_out ./out/py \
2>/dev/null \
"$f"
# C# manages compilation with MSBuild, so there is no need to run protoc here
# Typescript
# See https://github.com/improbable-eng/ts-protoc-gen#generating-typescript-definitions-for-commonjs-modules-generated-by-protoc
PROTOC_GEN_TS_PATH="./node_modules/.bin/protoc-gen-ts"
protoc \
--plugin "protoc-gen-ts=${PROTOC_GEN_TS_PATH}" \
--js_out import_style=commonjs,binary:./out/js \
--ts_out ./out/js \
"$f"
done
# generate docs
dirs=$(
find sis/rp -type f -regextype posix-extended -regex ".*.proto" \
| xargs dirname | uniq
)
for d in $dirs; do
docsdir="./docs/$d"
mkdir -p $docsdir
docsfile="reference.md"
protos=$(find $d -type f)
protoc \
--doc_out $docsdir \
--doc_opt markdown,$docsfile \
$protos
done
FROM golang:1.15 as protobuilder
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
curl \
unzip \
gcc \
g++ \
make \
python3 \
python3-pip \
python3-setuptools \
python3-wheel \
python3-dev \
&& pip3 install grpcio-tools googleapis-common-protos
# Install NodeJS, Yarn and ts-protoc-gen
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - \
&& curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y nodejs yarn --no-install-recommends \
&& yarn global add ts-protoc-gen@v0.12.0
# Install protoc
RUN cd $(mktemp -d) \
&& PROTOC_ZIP=protoc-3.13.0-linux-x86_64.zip \
&& curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protoc-3.13.0-linux-x86_64.zip \
&& echo "4a3b26d1ebb9c1d23e933694a6669295f6a39ddc64c3db2adf671f0a6026f82e protoc-3.13.0-linux-x86_64.zip" \
| sha256sum -c --status \
&& unzip -o $PROTOC_ZIP -d /usr/local bin/protoc \
&& unzip -o $PROTOC_ZIP -d /usr/local 'include/*' \
&& rm -f $PROTOC_ZIP \
&& cd -
# protoc-gen-go-grpc, required by --go-grpc_out
# grpc is undergoing some (unorthodox) changes
# check the pinned version in grpc-gateways go.mod when updating:
# https://github.com/grpc-ecosystem/grpc-gateway/blob/v2/go.mod
RUN GO111MODULE=on go get -u google.golang.org/protobuf/cmd/protoc-gen-go@v1.25.0 \
google.golang.org/grpc/cmd/protoc-gen-go-grpc@v0.0.0-20200527211525-6c9e30c09db2 \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.0.0-beta.5 \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.0.0-beta.5 \
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.3.2
# Install grpc_csharp_plugin
RUN curl -sSL https://www.nuget.org/api/v2/package/Grpc.Tools/2.32.0 -o temp.zip \
&& unzip -p temp.zip tools/linux_x64/grpc_csharp_plugin > /usr/local/bin/grpc_csharp_plugin \
&& chmod +x /usr/local/bin/grpc_csharp_plugin \
&& rm temp.zip
# Install buf
RUN cd $(mktemp -d) \
&& BUF_GZ=buf-Linux-x86_64.tar.gz \
&& curl -sSLO https://github.com/bufbuild/buf/releases/download/v0.24.0/buf-Linux-x86_64.tar.gz \
&& echo "8539cac0f20dd22f88b1c13bd24c4f0adf8811d5f80deb799e87d294ee3238d6 buf-Linux-x86_64.tar.gz" \
| sha256sum -c --status \
&& tar -xzf $BUF_GZ \
&& cp -r buf/bin /usr/local \
&& rm -rf $BUF_GZ buf \
&& cd -
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Add Tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini.asc /tini.asc
RUN gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7 \
&& gpg --batch --verify /tini.asc /tini \
&& chmod +x /tini
ENTRYPOINT ["/tini", "--"]
FROM protobuilder
WORKDIR /src
COPY . .
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
export $( cat .env | xargs )
rm -rf repo
mkdir -p repo
commit() {
cd "$1"
git config user.name "Protobuf autocommit"
git config user.email "sebastian.nyberg@securitas.com"
git add --all
# try to commit - if there is nothing to commit, simply skip this update
# 2>&1 -> redirect output on stderr channel (2) to stdout (1)
# >/dev/null -> redirect stdout to /dev/null (drop message)
( git commit -m "sispb/autocommit: $(git rev-parse HEAD)" 2>&1 >/dev/null \
&& git push origin master ) \
|| echo "skipping commit, no changes made"
cd -
}
for lang in go py; do
git clone "https://build:${GITPAT}@some-private-repo.com/sispb${lang}" "repo/${lang}"
cp -rv "out/${lang}/sis" "repo/${lang}/"
commit "repo/${lang}"
done
# For C#, compilation is managed by the repository itself
lang=cs
git clone "https://build:${GITPAT}@some-private-repo.com/sispb${lang}" "repo/${lang}"
cp -rv sis "repo/${lang}/"
cp -rv google/api "repo/${lang}/google/api"
commit "repo/${lang}"
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
export $( cat .env | xargs )
rm -rf repo
mkdir -p repo
for lang in go py cs; do
git clone "https://build:${GITPAT}@some-private-repo.com/sispb${lang}" "repo/${lang}"
cd "repo/${lang}"
git config user.name "Protobuf autocommit"
git config user.email "sebastian.nyberg@securitas.com"
./release.sh ${VERSION}
cd -
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment