Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Dockerfile capable of building all targets #170 #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.16-alpine AS builder

RUN apk update && \
apk add \
curl \
git \
nodejs \
npm \
protoc \
python3 \
rsync \
yarn

ADD . /koinos-proto
WORKDIR /koinos-proto

ENV PROTOBUF_VERSION="3.17.3"
ENV PB_EMBEDDED_CPP_VERSION="negative-enums"
ENV NODE_VERSION="16.14.2"
ENV AS_PROTO_VERSION="0.4.2"

RUN /koinos-proto/docker-scripts/install.sh
RUN /koinos-proto/docker-scripts/build.sh
RUN /koinos-proto/docker-scripts/generate_bundle.sh
44 changes: 44 additions & 0 deletions docker-scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

set -e
set -x

mkdir -p \
/koinos-proto-build/cpp \
/koinos-proto-build/go \
/koinos-proto-build/js \
/koinos-proto-build/python \
/koinos-proto-build/eams \
/koinos-proto-build/docs \
/koinos-proto-build/as

KOINOS_PROTOS=$(find /koinos-proto/koinos -name "*.proto")
GOOGLE_PROTOS=$(find /koinos-proto/google -name "*.proto")
RPC_PROTOS=$(find /koinos-proto/koinos -name "*rpc*.proto")

protoc --experimental_allow_proto3_optional \
-I/koinos-proto \
--cpp_out=/koinos-proto-build/cpp/ \
--go_out=/koinos-proto-build/go/ \
--python_out=/koinos-proto-build/python \
--descriptor_set_out=/koinos-proto-build/koinos_descriptors.pb \
--plugin=protoc-gen-as=/koinos-proto-build/js/node_modules/.bin/as-proto-gen \
--as_out=/koinos-proto-build/as \
$KOINOS_PROTOS

protoc --experimental_allow_proto3_optional \
-I/koinos-proto \
--doc_out=/koinos-proto-build/docs --doc_opt=markdown,api.md \
$RPC_PROTOS

protoc --experimental_allow_proto3_optional \
-I/koinos-proto \
--plugin=/koinos-proto/docker-scripts/protoc-gen-eams \
--eams_out=/koinos-proto-build/eams \
$KOINOS_PROTOS

cd /koinos-proto-build/js

yarn pbjs --keep-case --target static-module -o /koinos-proto-build/js/index.js $KOINOS_PROTOS $GOOGLE_PROTOS
yarn pbts -o /koinos-proto-build/js/index.d.ts /koinos-proto-build/js/index.js
yarn pbjs --keep-case --target json -o /koinos-proto-build/js/index.json $KOINOS_PROTOS $GOOGLE_PROTOS
42 changes: 42 additions & 0 deletions docker-scripts/generate_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

set -e
set -x

OUTDIR=/koinos-proto-build/out

# C++
mkdir -p "$OUTDIR/koinos-proto-cpp/libraries/proto/generated/"
rsync -rvm --include "*.pb.h" --include "*.pb.cc" --include "*/" --exclude "*" /koinos-proto-build/cpp/ "$OUTDIR/koinos-proto-cpp/libraries/proto/generated/"

# golang
mkdir -p "$OUTDIR/koinos-proto-golang/"
rsync -rvm --include "*.pb.go" --include "*/" --exclude "*" /koinos-proto-build/go/ "$OUTDIR/koinos-proto-golang/"

# js/ts
mkdir -p "$OUTDIR/koinos-proto-js/"
rsync -vm --include "index.js" --include "index.d.ts" --include="index.json" --exclude "*" /koinos-proto-build/js/ "$OUTDIR/koinos-proto-js/"

# python
mkdir -p "$OUTDIR/koinos-proto-python/"
rsync -rvm --include "*_pb2.py" --include "*/" --exclude "*" /koinos-proto-build/python/ "$OUTDIR/koinos-proto-python/"

# embedded-cpp
mkdir -p "$OUTDIR/koinos-proto-embedded-cpp/libraries/proto_embedded/generated/"
rsync -rvm --include "*.h" --include "*/" --exclude "*" /koinos-proto-build/eams/ "$OUTDIR/koinos-proto-embedded-cpp/libraries/proto_embedded/generated/"
mkdir -p "$OUTDIR/koinos-proto-embedded-cpp/libraries/proto_embedded/src/"
rsync -rvm --include "*.h" --include "*.cpp" --include "*/" --exclude "*" /koinos-proto-build/EmbeddedProto/src/ "$OUTDIR/koinos-proto-embedded-cpp/libraries/proto_embedded/src/"

# docs
mkdir -p "$OUTDIR/koinos-proto-documentation"
rsync -rvm --include "*.md" /koinos-proto-build/docs "$OUTDIR/koinos-proto-documentation"

# descriptors
mkdir -p "$OUTDIR/koinos-proto-descriptors"
cp /koinos-proto-build/koinos_descriptors.pb "$OUTDIR/koinos-proto-descriptors/koinos_descriptors.pb"

# as
mkdir -p "$OUTDIR/koinos-proto-as/assembly/koinos"
rsync -rvm --include "*.ts" --include "*/" --exclude "*" /koinos-proto-build/as/koinos/ "$OUTDIR/koinos-proto-as/assembly/koinos"

(cd /koinos-proto-build/out && tar c * | gzip -c9) > /koinos-proto-generated.tar.gz
22 changes: 22 additions & 0 deletions docker-scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e
set -x

mkdir -p /koinos-proto-build
cd /koinos-proto-build

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/[email protected]

git clone --recursive https://github.com/koinos/EmbeddedProto /koinos-proto-build/EmbeddedProto

cd /koinos-proto-build/EmbeddedProto
git checkout $PB_EMBEDDED_CPP_VERSION
sh ./setup.sh

mkdir -p /koinos-proto-build/js
cd /koinos-proto-build/js
yarn add protobufjs@^6.11.3
yarn add @koinos/as-proto-gen@$AS_PROTO_VERSION
yarn global add @jsdevtools/version-bump-prompt
3 changes: 3 additions & 0 deletions docker-scripts/protoc-gen-eams
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec /koinos-proto-build/EmbeddedProto/venv/bin/python /koinos-proto-build/EmbeddedProto/generator/protoc-gen-eams.py --protoc-plugin