Skip to content

Commit

Permalink
Merge pull request #349 from bavix/genproto-v2024
Browse files Browse the repository at this point in the history
[3.x] v0.0.0-20240711142825-46eb208f015d
  • Loading branch information
rez1dent3 authored Jul 17, 2024
2 parents 93ed954 + 4535d08 commit e7dc1a4
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 70 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ on:
jobs:
build:
name: Run example
runs-on: ubuntu-latest
strategy:
matrix:
os:
- ubuntu-latest
#- macos-latest
#- macos-latest-large
#- windows-latest
runs-on: ${{ matrix.os }}
steps:
-
name: Checkout
Expand Down
49 changes: 30 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
FROM golang:1.22-alpine3.20 AS builder

RUN apk --no-cache add git &&\
go install -v -ldflags "-s -w" google.golang.org/protobuf/cmd/protoc-gen-go@latest &&\
go install -v -ldflags "-s -w" google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest &&\
FROM golang:1.22-alpine3.20 as protoc-builder

ENV PROTOC_VERSION=27.2
ARG TARGETARCH

RUN apk --no-cache add git curl unzip \
&& if [ $TARGETARCH = "amd64" ]; then export DL_ARCH=x86_64 ; fi \
&& if [ $TARGETARCH = "arm64" ]; then export DL_ARCH=aarch_64 ; fi \
&& curl -f -L -o /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${DL_ARCH}.zip \
&& unzip /tmp/protoc.zip && rm /tmp/protoc.zip \
&& mv bin/protoc /usr/bin && rm -rf bin include \
&& mkdir -p /usr/include \
# cloning well-known-types
git clone --depth=1 https://github.com/protocolbuffers/protobuf.git /protobuf-repo &&\
mv /protobuf-repo/src/ /protobuf/ &&\
&& git clone --depth=1 https://github.com/protocolbuffers/protobuf.git /protobuf-repo \
&& mv /protobuf-repo/src/ /usr/include/protobuf/ \
# cloning googleapis-types
git clone --depth=1 https://github.com/googleapis/googleapis.git /googleapis &&\
&& git clone --depth=1 https://github.com/googleapis/googleapis.git /usr/include/googleapis \
# cleanup
rm -rf /protobuf-repo &&\
find /protobuf -not -name "*.proto" -type f -delete &&\
find /googleapis -not -name "*.proto" -type f -delete
&& rm -rf /protobuf-repo \
&& find /usr/include/protobuf -not -name "*.proto" -type f -delete \
&& find /usr/include/googleapis -not -name "*.proto" -type f -delete

FROM golang:1.22-alpine3.20 AS builder

RUN go install -v -ldflags "-s -w" google.golang.org/protobuf/cmd/protoc-gen-go@latest &&\
go install -v -ldflags "-s -w" google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

COPY . /go/src/github.com/bavix/gripmock
COPY . /src

WORKDIR /go/src/github.com/bavix/gripmock/protoc-gen-gripmock
WORKDIR /src/protoc-gen-gripmock

RUN go install -v -ldflags "-s -w"

Expand All @@ -27,23 +39,22 @@ LABEL org.opencontainers.image.licenses=Apache-2.0

ARG version

RUN apk --no-cache add protoc curl

COPY --from=builder /protobuf /protobuf
COPY --from=builder /googleapis /googleapis
COPY --from=protoc-builder /usr/bin/protoc /usr/bin/protoc
COPY --from=protoc-builder /usr/include/protobuf /protobuf
COPY --from=protoc-builder /usr/include/googleapis /googleapis

COPY --from=builder $GOPATH/bin/protoc-gen-go $GOPATH/bin/protoc-gen-go
COPY --from=builder $GOPATH/bin/protoc-gen-go-grpc $GOPATH/bin/protoc-gen-go-grpc
COPY --from=builder $GOPATH/bin/protoc-gen-gripmock $GOPATH/bin/protoc-gen-gripmock

COPY . /go/src/github.com/bavix/gripmock
COPY --from=builder /src /go/src/github.com/bavix/gripmock

WORKDIR /go/src/github.com/bavix/gripmock

RUN go install -v -ldflags "-X 'github.com/bavix/gripmock/cmd.version=${version:-dev}' -s -w"

EXPOSE 4770 4771

HEALTHCHECK CMD curl --fail http://127.0.0.1:4771/api/health/readiness
HEALTHCHECK CMD gripmock check --silent

ENTRYPOINT ["gripmock"]
25 changes: 12 additions & 13 deletions cmd/check.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package cmd

import (
"errors"
"time"

"github.com/rs/zerolog"
"github.com/cockroachdb/errors"
"github.com/spf13/cobra"

"github.com/bavix/gripmock/internal/deps"
"github.com/bavix/gripmock/internal/domain/waiter"
)

var (
silenceErrorsFlag bool
pingTimeout time.Duration
errServerIsNotRunning = errors.New("server is not running")
)

const serviceName = "gripmock"

var checkCmd = &cobra.Command{
Use: "check",
Short: "The command checks whether the gripmock server is alive or dead by accessing it via the API",
Use: "check",
Args: cobra.NoArgs,
SilenceUsage: true,
Short: "The command checks whether the gripmock server is alive or dead by accessing it via the API",
RunE: func(cmd *cobra.Command, _ []string) error {
cmd.SilenceErrors = silenceErrorsFlag

builder := deps.NewBuilder(deps.WithDefaultConfig())
ctx, cancel := builder.SignalNotify(cmd.Context())
defer cancel()
Expand All @@ -30,22 +34,16 @@ var checkCmd = &cobra.Command{

pingService, err := builder.PingService()
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("create ping service failed")

return err
return errors.WithStack(err)
}

code, err := pingService.PingWithTimeout(ctx, pingTimeout, serviceName)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("unable to connect to server")

return err
return errors.WithStack(err)
}

if code != waiter.Serving {
zerolog.Ctx(ctx).Error().Uint32("code", uint32(code)).Msg("server is not running")

return errServerIsNotRunning
return errors.Wrapf(errServerIsNotRunning, "code: %d", code)
}

return nil
Expand All @@ -58,4 +56,5 @@ func init() {
const defaultPingTimeout = time.Second * 5

checkCmd.Flags().DurationVarP(&pingTimeout, "timeout", "t", defaultPingTimeout, "timeout")
checkCmd.Flags().BoolVar(&silenceErrorsFlag, "silent", false, "silence errors")
}
2 changes: 1 addition & 1 deletion example/ms/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/ms/stub example/ms/ms.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/ms/client/*.go
2 changes: 1 addition & 1 deletion example/multi-files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ gripmock --stub=example/multi-files/stub example/multi-files/file1.proto \
example/multi-files/file2.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/multi-files/client/*.go
2 changes: 1 addition & 1 deletion example/multi-package/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ gripmock --stub=example/multi-package/stub --imports=example/multi-package/ \
example/multi-package/foo.proto example/multi-package/hello.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/multi-package/client/*.go
2 changes: 1 addition & 1 deletion example/one-of/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/one-of/stub example/one-of/oneof.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/one-of/client/*.go
2 changes: 1 addition & 1 deletion example/simple/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/simple/stub example/simple/simple.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/simple/client/*.go
2 changes: 1 addition & 1 deletion example/stream/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/stream/stub example/stream/stream.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/stream/client/*.go
2 changes: 1 addition & 1 deletion example/stub-subfolders/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/stub-subfolders/stub example/stub-subfolders/stub-subfolders.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/stub-subfolders/client/*.go
2 changes: 1 addition & 1 deletion example/well_known_types/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
gripmock --stub=example/well_known_types/stub example/well_known_types/wkt.proto &

# wait for generated files to be available and gripmock is up
gripmock check --timeout=30s
gripmock check --silent --timeout=30s

go run example/well_known_types/client/*.go
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ require (
github.com/bavix/features v1.0.0
github.com/bavix/gripmock-sdk-go v1.0.4
github.com/bavix/gripmock-ui v1.0.0-alpha7
github.com/bavix/gripmock/protogen v0.0.0-20240711173959-23274b180246
github.com/bavix/gripmock/protogen v0.0.0-20240715054016-3ca5fe7d23ae
github.com/cockroachdb/errors v1.11.3
github.com/cristalhq/base64 v0.1.2
github.com/goccy/go-yaml v1.11.3
github.com/google/uuid v1.6.0
Expand All @@ -31,15 +32,21 @@ require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/bufbuild/protocompile v0.14.0 // indirect
github.com/caarlos0/env/v10 v10.0.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gripmock/deeply v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -48,7 +55,7 @@ require (
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e7dc1a4

Please sign in to comment.