From 03599e7a99690180cc9a528d74eeafdef41b2e82 Mon Sep 17 00:00:00 2001 From: theoretical Date: Mon, 21 Nov 2022 19:34:43 +0000 Subject: [PATCH] Add a Dockerfile capable of building all targets #170 --- Dockerfile | 24 +++++++++++++++++ docker-scripts/build.sh | 44 +++++++++++++++++++++++++++++++ docker-scripts/generate_bundle.sh | 42 +++++++++++++++++++++++++++++ docker-scripts/install.sh | 22 ++++++++++++++++ docker-scripts/protoc-gen-eams | 3 +++ 5 files changed, 135 insertions(+) create mode 100644 Dockerfile create mode 100755 docker-scripts/build.sh create mode 100755 docker-scripts/generate_bundle.sh create mode 100755 docker-scripts/install.sh create mode 100755 docker-scripts/protoc-gen-eams diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6cf790 --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/docker-scripts/build.sh b/docker-scripts/build.sh new file mode 100755 index 0000000..e8e3a6f --- /dev/null +++ b/docker-scripts/build.sh @@ -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 diff --git a/docker-scripts/generate_bundle.sh b/docker-scripts/generate_bundle.sh new file mode 100755 index 0000000..c207ef3 --- /dev/null +++ b/docker-scripts/generate_bundle.sh @@ -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 diff --git a/docker-scripts/install.sh b/docker-scripts/install.sh new file mode 100755 index 0000000..300bfe6 --- /dev/null +++ b/docker-scripts/install.sh @@ -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/protoc-gen-doc@v1.5.0 + +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 diff --git a/docker-scripts/protoc-gen-eams b/docker-scripts/protoc-gen-eams new file mode 100755 index 0000000..4356f52 --- /dev/null +++ b/docker-scripts/protoc-gen-eams @@ -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