Skip to content

Commit

Permalink
docs(swagger): Add generation from proto
Browse files Browse the repository at this point in the history
  • Loading branch information
ivivanov authored and Lockwarr committed Jul 12, 2024
1 parent f8aea92 commit 805de6c
Show file tree
Hide file tree
Showing 14 changed files with 94,884 additions and 19,869 deletions.
41 changes: 12 additions & 29 deletions .github/images/protogen.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
# This Dockerfile is used for proto generation
FROM bufbuild/buf:1.28.0 as BUILDER
FROM ghcr.io/cosmos/proto-builder:0.14.0

FROM golang:1.22-alpine
USER root


RUN apk add --no-cache \
RUN apk update && apk add --no-cache \
nodejs \
npm \
git \
make

ENV GOLANG_PROTOBUF_VERSION=1.28.0 \
GOGO_PROTOBUF_VERSION=1.3.2 \
GRPC_GATEWAY_VERSION=1.16.0


RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION}
RUN go install 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}

# install all gogo protobuf binaries
RUN git clone https://github.com/regen-network/protobuf.git; \
cd protobuf; \
go mod download; \
make install

# we need to use git clone because we use 'replace' directive in go.mod
# protoc-gen-gocosmos was moved to to in cosmos/gogoproto but pending a migration there.
RUN git clone https://github.com/regen-network/cosmos-proto.git; \
cd cosmos-proto/protoc-gen-gocosmos; \
go install .
make \
python3 \
jq \
bash

RUN npm install -g swagger-combine
RUN npm install -g swagger-merger
RUN npm install -g swagger2openapi

COPY --from=golang:1.22-alpine /usr/local/go/ /usr/local/go/

COPY --from=BUILDER /usr/local/bin /usr/local/bin
ENV PATH="/usr/local/go/bin:${PATH}"
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
--region $AWS_REGION \
--image-ids=imageTag=$IMAGE_TAG
# Builds and pushed builder image if it does not exist
# Builds and push builder image if it does not exist
builder-create:
name: Create builder image
needs: builder-exists
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/proto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Protobuf
# Protobuf runs buf (https://buf.build/) lint and check-breakage
# This workflow is only run when a .proto file has been changed
on:
# Allows the workflow to be triggered manually
workflow_dispatch:
pull_request:
paths:
- "proto/**"
Expand All @@ -16,10 +18,11 @@ env:
ERC_REGISTRY: "public.ecr.aws"
ERC_REGISTRY_ALIAS: "nolus"
ERC_REPOSITORY: "protogen"
IMAGE_TAG: "0.1"
IMAGE_TAG: "0.2.0"
DOCKERFILE: ".github/images/protogen.Dockerfile"

jobs:
# Checks if protogen image exists in docker registry
protogen-exists:
name: Check protogen exists
runs-on: ubuntu-latest
Expand All @@ -46,8 +49,9 @@ jobs:
--repository-name $ERC_REPOSITORY \
--region $AWS_REGION \
--image-ids=imageTag=$IMAGE_TAG
protogen-build:
# Builds and push protogen image if it does not exist
protogen-create:
name: Create protogen image
needs: protogen-exists
runs-on: ubuntu-latest
Expand Down Expand Up @@ -79,8 +83,8 @@ jobs:
echo "Image version $IMAGE_TAG exists. Skipping step..."
fi
lint:
name: Lint
proto-lint:
name: Lint protobuf files
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -90,7 +94,7 @@ jobs:
with:
input: "proto"

break-check:
proto-break-check:
name: Detect breaking changes
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,19 @@ test-unit-coverage-report: ## Generate global code coverage report in HTML
###############################################################################
### Proto ###
###############################################################################
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoVer=0.2.0
protoImageName=public.ecr.aws/nolus/protogen:$(protoVer)
protoImage=docker run --rm -v $(CURDIR):/workspace --workdir /workspace --user root $(protoImageName)

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./proto/scripts/protocgen.sh
@$(protoImage) ./proto/scripts/protocgen.sh

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@$(protoImage) sh ./proto/scripts/protoc-swagger-gen.sh
@$(protoImage) ./proto/scripts/protoc-swagger-gen.sh

proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
Expand Down
6 changes: 2 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/Nolus-Protocol/nolus-core/app/keepers"
"github.com/Nolus-Protocol/nolus-core/app/openapiconsole"
appparams "github.com/Nolus-Protocol/nolus-core/app/params"
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
v060 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v060"
Expand Down Expand Up @@ -461,9 +460,8 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register nodeservice grpc-gateway routes.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
// Register app's swagger ui on "/swagger" path
apiSvr.Router.PathPrefix("/swagger").Handler(http.FileServer(http.FS(docs.SwaggerFiles)))
}

// RegisterTxService implements the Application.RegisterTxService method.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package docs

import "embed"

//go:embed static
var Docs embed.FS
//go:embed swagger/*
var SwaggerFiles embed.FS
Loading

0 comments on commit 805de6c

Please sign in to comment.