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

Containerized Protobuf generation #304

Merged
merged 6 commits into from
Nov 11, 2020
Merged
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
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')

# for dockerized protobuf tools
PROTO_CONTAINER := cosmwasm/prototool-docker:latest
DOCKER_BUF := docker run --rm -v $(shell pwd)/buf.yaml:/workspace/buf.yaml -v $(shell go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir -v $(shell pwd):/workspace/wasmd --workdir /workspace $(PROTO_CONTAINER)
HTTPS_GIT := https://github.com/CosmWasm/wasmd.git

export GO111MODULE = on

# process build tags
Expand Down Expand Up @@ -198,16 +203,19 @@ format:
###############################################################################

proto-all: proto-gen proto-lint proto-check-breaking
.PHONY: proto-all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Much better maintainable than a one-line .PHONY. Did now know you can specily multiple .PHONY. But people on the internet say this is how you do it (https://stackoverflow.com/questions/4156382/is-it-possible-to-have-multiple-phony-targets-in-a-gnu-makefile)


proto-gen:
@./scripts/protocgen.sh
proto-gen: proto-lint
@docker run --rm -v $(shell go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir -v $(shell pwd):/workspace --workdir /workspace --env COSMOS_SDK_DIR=/workspace/cosmos_sdk_dir $(PROTO_CONTAINER) ./scripts/protocgen.sh
.PHONY: proto-gen

proto-lint:
@buf check lint --error-format=json
@$(DOCKER_BUF) buf check lint --error-format=json
.PHONY: proto-lint

proto-check-breaking:
@buf check breaking --against-input '.git#branch=master'

@$(DOCKER_BUF) buf check breaking --against-input $(HTTPS_GIT)#branch=master
.PHONY: proto-check-breaking

.PHONY: all build-linux install install-debug \
go-mod-cache draw-deps clean build format \
Expand Down
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Wasm Zone

[![CircleCI](https://circleci.com/gh/cosmwasm/wasmd/tree/master.svg?style=shield)](https://circleci.com/gh/cosmwasm/wasmd/tree/master)
[![CircleCI](https://circleci.com/gh/CosmWasm/wasmd/tree/master.svg?style=shield)](https://circleci.com/gh/CosmWasm/wasmd/tree/master)
[![codecov](https://codecov.io/gh/cosmwasm/wasmd/branch/master/graph/badge.svg)](https://codecov.io/gh/cosmwasm/wasmd)
[![Go Report Card](https://goreportcard.com/badge/github.com/CosmWasm/wasmd)](https://goreportcard.com/report/github.com/CosmWasm/wasmd)
[![license](https://img.shields.io/github/license/cosmwasm/wasmd.svg)](https://github.com/CosmWasm/wasmd/blob/master/LICENSE)
[![LoC](https://tokei.rs/b1/github/cosmwasm/wasmd)](https://github.com/CosmWasm/wasmd)
[![license](https://img.shields.io/github/license/CosmWasm/wasmd.svg)](https://github.com/CosmWasm/wasmd/blob/master/LICENSE)
[![LoC](https://tokei.rs/b1/github/CosmWasm/wasmd)](https://github.com/CosmWasm/wasmd)
<!-- [![GolangCI](https://golangci.com/badges/github.com/CosmWasm/wasmd.svg)](https://golangci.com/r/github.com/CosmWasm/wasmd) -->

This repository hosts `Wasmd`, the first implementation of a cosmos zone with wasm smart contracts enabled.
Expand All @@ -13,7 +13,7 @@ This code was forked from the `cosmos/gaia` repository as a basis and then we ad
many gaia-specific files. However, the `wasmd` binary should function just like `gaiad` except for the
addition of the `x/wasm` module.

**Note**: Requires [Go 1.14+](https://golang.org/dl/)
**Note**: Requires [Go 1.15+](https://golang.org/dl/)

## Supported Systems

Expand Down Expand Up @@ -68,24 +68,11 @@ To set up a single node testnet, [look at the deployment documentation](./docs/d
If you want to deploy a whole cluster, [look at the network scripts](./networks/README.md).

## Protobuf

1. Install [protoc](https://github.com/protocolbuffers/protobuf#protocol-compiler-installation)

2. Install [cosmos-extension](https://github.com/regen-network/cosmos-proto/) for [gogo-protobuf](https://github.com/gogo/protobuf)
```sh
go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos
```
3. Install [grpc gateway extension](github.com/grpc-ecosystem/grpc-gateway)
```go
go install \ upgrade_stargate_rebased 3a8aa77 ✗
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
github.com/golang/protobuf/protoc-gen-go
```
3. Run generator
```sh
make proto-gen
Generate protobuf
```shell script
make proto-gen
```
The generators are executed within a Docker [container](./contrib/prototools-docker), now.

## Dockerized

Expand Down
23 changes: 20 additions & 3 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
version: v1beta1
build:
roots:
- .
# Note: these are not local path. These roots are mounted into the docker container
- wasmd/
- cosmos_sdk_dir/third_party/proto/
- cosmos_sdk_dir/proto/
excludes:
# - cosmos_sdk_dir
lint:
use:
- DEFAULT
Expand All @@ -9,11 +15,22 @@ lint:
except:
- UNARY_RPC
- COMMENT_FIELD
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- PACKAGE_DIRECTORY_MATCH
ignore:
- third_party
- tendermint
- gogoproto
- cosmos_proto
- google
- confio
breaking:
use:
- FILE
ignore:
- third_party
- tendermint
- gogoproto
- cosmos_proto
- google
- confio
51 changes: 51 additions & 0 deletions contrib/prototools-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM golang:1.15.3-alpine3.12 AS build

#ARG PROTOTOOL_VERSION=1.10.0
ARG PROTODOC_VERSION=1.3.2
ARG GRPC_GATEWAY_VERSION=1.16.0
ARG REGEN_GOGOPROTO_VERSION=0.3.0
ARG REGEN_PROTOBUF_VERSION=1.3.2-alpha.regen.4
ARG BUF_VERSION=0.30.0

RUN apk --no-cache add --update curl git libc6-compat make upx

RUN go get -d \
github.com/gogo/protobuf/gogoproto && \
mkdir -p /usr/include/google/protobuf/ && \
mv /go/src/github.com/gogo/protobuf/protobuf/google/protobuf/empty.proto /usr/include/google/protobuf/ && \
mv /go/src/github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto /usr/include/google/protobuf/

RUN GO111MODULE=on go get \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} && \
mv /go/bin/protoc-gen-grpc-gateway /usr/local/bin/ && \
mv /go/bin/protoc-gen-swagger /usr/local/bin/

# Install regen fork of gogo proto
# To install a fix version this can only be done via this go.mod workaround
WORKDIR /work
RUN GO111MODULE=on go mod init foobar && \
go mod edit -replace github.com/gogo/protobuf=github.com/regen-network/protobuf@v${REGEN_PROTOBUF_VERSION} && \
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@v${REGEN_GOGOPROTO_VERSION} && \
mv /go/bin/protoc-gen-gocosmos* /usr/local/bin/

RUN GO111MODULE=on go get \
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v${PROTODOC_VERSION} && \
mv /go/bin/protoc-gen-doc /usr/local/bin/

RUN GO111MODULE=on go get \
github.com/bufbuild/buf/cmd/buf@v${BUF_VERSION} && \
mv /go/bin/buf /usr/local/bin/

RUN upx --lzma /usr/local/bin/*

FROM golang:1.15.3-alpine3.12
ENV LD_LIBRARY_PATH=/lib64:/lib

WORKDIR /work
RUN apk --no-cache add --update curl git libc6-compat make
RUN apk --no-cache add --update ca-certificates libc6-compat protoc

COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /usr/include /usr/include
RUN chmod -R 755 /usr/include
21 changes: 21 additions & 0 deletions contrib/prototools-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Prototool Docker Helper
=======================
Docker container for all the protobuf generation...

Based on the work by @pseudomuto [prototool-docker](https://github.com/charithe/prototool-docker) project:

Installs generators and tools from:

* https://github.com/bufbuild/buf
* https://github.com/grpc-ecosystem
* https://github.com/regen-network/cosmos-proto
* https://github.com/pseudomuto/protoc-gen-doc

### Build
```shell script
docker build -t cosmwasm/prototools-docker -f ./contrib/prototools-docker/Dockerfile .
```

```shell script
docker run -it -v $(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir -v $(pwd):/workspace --workdir /workspace --env COSMOS_SDK_DIR=/cosmos_sdk_dir cosmwasm/prototool-docker sh
```
3 changes: 3 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated doc

Tutorials and project doc is available on https://docs.cosmwasm.com/
Loading