From 41d7d9b7ae2a4f4eebfafec7c9d7dc14d1aa7311 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 18:32:52 +0800 Subject: [PATCH 01/29] test echo server ci --- .../workflows/publish-upi-echo-server.yaml | 41 +++++++++++++ example/go/simple/Dockerfile | 18 ++++++ example/go/simple/Dockerfilebu | 40 +++++++++++++ example/go/simple/client/main.go | 58 +++++++++++++++++++ example/go/simple/go.mod | 18 ++++++ example/go/simple/go.sum | 25 ++++++++ example/go/simple/server/main.go | 53 +++++++++++++++++ 7 files changed, 253 insertions(+) create mode 100644 .github/workflows/publish-upi-echo-server.yaml create mode 100644 example/go/simple/Dockerfile create mode 100644 example/go/simple/Dockerfilebu create mode 100644 example/go/simple/client/main.go create mode 100644 example/go/simple/go.mod create mode 100644 example/go/simple/go.sum create mode 100644 example/go/simple/server/main.go diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml new file mode 100644 index 0000000..64dcd9b --- /dev/null +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -0,0 +1,41 @@ +name: publish-python-sdk +on: + workflow_dispatch: +jobs: + create-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.create_version.outputs.version }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - id: create_version + name: Create version string + run: | + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + [ "$VERSION" == "main" ] && VERSION=$(git describe --tags --always --first-parent) + # Strip "v" prefix + [[ "${VERSION}" == "v"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # If it's pull request the version string is prefixed by 0.0.0- + [ ${{ github.event_name}} == "pull_request" ] && VERSION="0.0.0-${{ github.event.pull_request.head.sha }}" + echo ${VERSION} + echo "::set-output name=version::${VERSION}" + + build-upi-echo-server: + runs-on: ubuntu-latest + needs: + - create-version + steps: + - uses: actions/checkout@v2 + - name: Build Docker image + run: docker build -t upi-echo-server.${{ needs.create-version.outputs.version }} -f example/go/simple/Dockerfile . + - name: Save Docker image + run: docker image save --output upi-echo-server.${{ needs.create-version.outputs.version }}.tar upi-echo-server:${{ needs.create-version.outputs.version }} + - name: Publish Docker Artifact + uses: actions/upload-artifact@v2 + with: + name: upi-echo-server.${{ needs.create-version.outputs.version }}.tar + path: upi-echo-server.${{ needs.create-version.outputs.version }}.tar + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} diff --git a/example/go/simple/Dockerfile b/example/go/simple/Dockerfile new file mode 100644 index 0000000..043cc84 --- /dev/null +++ b/example/go/simple/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.18-alpine as build + +WORKDIR /app + +COPY example/go/simple ./ +RUN go mod download +RUN go build -o /upi-echo-server ./server + +# Build the application image +FROM alpine:latest + +RUN addgroup -S app && adduser -S app -G app +WORKDIR /app +RUN chown -R app:app /app + +COPY --chown=app:app --from=build /upi-echo-server /upi-echo-server +USER app +ENTRYPOINT ["/upi-echo-server"] \ No newline at end of file diff --git a/example/go/simple/Dockerfilebu b/example/go/simple/Dockerfilebu new file mode 100644 index 0000000..96b9264 --- /dev/null +++ b/example/go/simple/Dockerfilebu @@ -0,0 +1,40 @@ +# Build application binary +FROM golang:1.18-alpine as builder +ARG BIN_NAME=turing-router +ARG VERSION +ARG USER +ARG HOST +ARG BRANCH +ARG NOW + +ENV GO111MODULE=on \ +GOOS=linux \ +GOARCH=amd64 + +ENV PROJECT_ROOT=github.com/caraml-dev/universal-prediction-interface/go/simple + +WORKDIR /app +COPY . . + +RUN go build \ +-mod=vendor \ +-tags musl \ +-o ./bin/${BIN_NAME} \ +-ldflags "\ +-X ${PROJECT_ROOT}/internal.Version=${VERSION} \ +-X ${PROJECT_ROOT}/internal.Branch=${BRANCH} \ +-X ${PROJECT_ROOT}/internal.BuildUser=${USER}@${HOST} \ +-X ${PROJECT_ROOT}/internal.BuildDate=${NOW}" \ +-v ${PROJECT_ROOT}/cmd + +# Build the application image +FROM alpine:latest +ARG BIN_NAME=turing-router +ENV BIN_NAME ${BIN_NAME} + +RUN addgroup -S app && adduser -S app -G app +WORKDIR /app +RUN chown -R app:app /app +COPY --chown=app:app --from=builder /app/bin/* ./ +USER app +ENTRYPOINT ./${BIN_NAME} diff --git a/example/go/simple/client/main.go b/example/go/simple/client/main.go new file mode 100644 index 0000000..58852df --- /dev/null +++ b/example/go/simple/client/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "context" + "flag" + "log" + "time" + + upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +const ( + defaultName = "world" +) + +var ( + addr = flag.String("addr", "localhost:50051", "the address to connect to") +) + +func main() { + flag.Parse() + // Set up a connection to the server. + conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + c := upiv1.NewUniversalPredictionServiceClient(conn) + + // Contact the server and print out its response. + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.PredictValues(ctx, &upiv1.PredictValuesRequest{ + PredictionTable: &upiv1.Table{ + Name: "Test", + Columns: []*upiv1.Column{ + { + Name: "col1", + Type: upiv1.Type_TYPE_DOUBLE, + }, + }, + Rows: []*upiv1.Row{ + { + RowId: "1", + Values: []*upiv1.Value{ + {}, + }, + }, + }, + }, + }) + if err != nil { + log.Fatalf("could not call upi server: %v", err) + } + log.Printf("Response: %s", r.String()) +} diff --git a/example/go/simple/go.mod b/example/go/simple/go.mod new file mode 100644 index 0000000..0cbd292 --- /dev/null +++ b/example/go/simple/go.mod @@ -0,0 +1,18 @@ +module github.com/caraml-dev/universal-prediction-interface/example/simple + +go 1.18 + +require ( + github.com/caraml-dev/universal-prediction-interface v0.0.0-20220913065109-8170722e7551 + google.golang.org/grpc v1.49.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2 // indirect + golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect + google.golang.org/protobuf v1.28.1 // indirect +) diff --git a/example/go/simple/go.sum b/example/go/simple/go.sum new file mode 100644 index 0000000..15fc643 --- /dev/null +++ b/example/go/simple/go.sum @@ -0,0 +1,25 @@ +github.com/caraml-dev/universal-prediction-interface v0.0.0-20220913065109-8170722e7551 h1:nK41mSx5EZWigXbqDropyQLUegcYlV7CUGXjwBYRj0w= +github.com/caraml-dev/universal-prediction-interface v0.0.0-20220913065109-8170722e7551/go.mod h1:dVNvxu+vducr8/hF2g4HUJ51dwV+fJhUd/TizJYWiO4= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2 h1:BqHID5W5qnMkug0Z8UmL8tN0gAy4jQ+B4WFt8cCgluU= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2/go.mod h1:ZbS3MZTZq/apAfAEHGoB5HbsQQstoqP92SjAqtQ9zeg= +golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw= +golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c h1:IooGDWedfLC6KLczH/uduUsKQP42ZZYhKx+zd50L1Sk= +google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= +google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/example/go/simple/server/main.go b/example/go/simple/server/main.go new file mode 100644 index 0000000..b1601dd --- /dev/null +++ b/example/go/simple/server/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "flag" + "fmt" + "log" + "net" + + upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +var ( + port = flag.Int("port", 50051, "The server port") +) + +type server struct { + upiv1.UnimplementedUniversalPredictionServiceServer +} + +func (s *server) PredictValues( + _ context.Context, + req *upiv1.PredictValuesRequest, +) (*upiv1.PredictValuesResponse, error) { + return &upiv1.PredictValuesResponse{ + Metadata: &upiv1.ResponseMetadata{ + Models: []*upiv1.ModelMetadata{ + { + Name: "Echo Request Table", + Version: "1", + }, + }, + }, + PredictionResultTable: req.GetPredictionTable(), + }, nil +} + +func main() { + flag.Parse() + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + upiv1.RegisterUniversalPredictionServiceServer(s, &server{}) + reflection.Register(s) + log.Printf("listening on port %d", *port) + if err := s.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} From 98c217d474794049544ef89e62364c292a4dc1c8 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 18:33:48 +0800 Subject: [PATCH 02/29] test echo server ci - fix name --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 64dcd9b..c5a480b 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,4 +1,4 @@ -name: publish-python-sdk +name: publish-upi-echo-server on: workflow_dispatch: jobs: From 3163d282e106696c50bcf14da39b98c69cac5be7 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 18:34:57 +0800 Subject: [PATCH 03/29] test echo server ci - add on push --- .github/workflows/publish-upi-echo-server.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index c5a480b..25079aa 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,5 +1,6 @@ name: publish-upi-echo-server on: + push: workflow_dispatch: jobs: create-version: From 95a061cf86788d45edfc38949c875bf6300747bc Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 18:40:24 +0800 Subject: [PATCH 04/29] test echo server ci - fix typo --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 25079aa..9cc5f4c 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build Docker image - run: docker build -t upi-echo-server.${{ needs.create-version.outputs.version }} -f example/go/simple/Dockerfile . + run: docker build -t upi-echo-server:${{ needs.create-version.outputs.version }} -f example/go/simple/Dockerfile . - name: Save Docker image run: docker image save --output upi-echo-server.${{ needs.create-version.outputs.version }}.tar upi-echo-server:${{ needs.create-version.outputs.version }} - name: Publish Docker Artifact From ddfb3cadac5eaf1bd79fed1910e5728d4075d6f9 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 19:23:31 +0800 Subject: [PATCH 05/29] test echo server ci - add publish --- .../workflows/publish-upi-echo-server.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 9cc5f4c..2de7cbd 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -2,6 +2,16 @@ name: publish-upi-echo-server on: push: workflow_dispatch: + workflow_call: + inputs: + container_registry: + type: string + required: false + default: ghcr.io + secrets: + ghcr_token: + required: true + jobs: create-version: runs-on: ubuntu-latest @@ -40,3 +50,31 @@ jobs: name: upi-echo-server.${{ needs.create-version.outputs.version }}.tar path: upi-echo-server.${{ needs.create-version.outputs.version }}.tar retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + publish-upi-echo-server: + runs-on: ubuntu-latest + needs: + - create-version + steps: + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ inputs.container_registry }} + username: ${{ github.actor }} + password: ${{ secrets.ghcr_token }} + + - name: Download API Docker Artifact + uses: actions/download-artifact@v2 + with: + name: upi-echo-server.${{ needs.create-version.outputs.version }}.tar + + - name: Publish Docker Image + env: + DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} + run: | + docker image load --input upi-echo-server.${{ inputs.router_version }}.tar + docker tag \ + upi-echo-server:${{ needs.create-version.outputs.version }} \ + ${{ env.DOCKER_REPOSITORY }}/upi-echo-server:${{ needs.create-version.outputs.version }} + + docker push ${{ env.DOCKER_REPOSITORY }}/upi-echo-server:${{ needs.create-version.outputs.version }} From 7328476bbd4a483a1a7b2f190a2cbc0e4221d03f Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 19:35:21 +0800 Subject: [PATCH 06/29] test echo server ci - update secret --- .github/workflows/publish-upi-echo-server.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 2de7cbd..fbd0679 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -8,9 +8,6 @@ on: type: string required: false default: ghcr.io - secrets: - ghcr_token: - required: true jobs: create-version: @@ -61,7 +58,7 @@ jobs: with: registry: ${{ inputs.container_registry }} username: ${{ github.actor }} - password: ${{ secrets.ghcr_token }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Download API Docker Artifact uses: actions/download-artifact@v2 From eebe6be11b3a829a38bcc5aea726e0fc5c2ca9db Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 19:54:27 +0800 Subject: [PATCH 07/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index fbd0679..d80b83b 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -9,6 +9,9 @@ on: required: false default: ghcr.io +env: + DOCKER_REGISTRY: ghcr.io + jobs: create-version: runs-on: ubuntu-latest @@ -56,7 +59,7 @@ jobs: - name: Log in to the Container registry uses: docker/login-action@v1 with: - registry: ${{ inputs.container_registry }} + registry: ${{ env.DOCKER_REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} @@ -66,12 +69,8 @@ jobs: name: upi-echo-server.${{ needs.create-version.outputs.version }}.tar - name: Publish Docker Image - env: - DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} run: | + IMAGE_TAG="${{ env.DOCKER_REGISTRY }}/caraml/upi-echo-server:${{ inputs.version }}" docker image load --input upi-echo-server.${{ inputs.router_version }}.tar - docker tag \ - upi-echo-server:${{ needs.create-version.outputs.version }} \ - ${{ env.DOCKER_REPOSITORY }}/upi-echo-server:${{ needs.create-version.outputs.version }} - - docker push ${{ env.DOCKER_REPOSITORY }}/upi-echo-server:${{ needs.create-version.outputs.version }} + docker tag upi-echo-server:${{ needs.create-version.outputs.version }} ${IMAGE_TAG} + docker push ${IMAGE_TAG} From 4d325ae300efbc921a8bae31bd0841b92afac532 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:05:10 +0800 Subject: [PATCH 08/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index d80b83b..ef37b10 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -11,6 +11,7 @@ on: env: DOCKER_REGISTRY: ghcr.io + ARTIFACT_RETENTION_DAYS: 1 jobs: create-version: From 7701a05cd51159fa55b11cfd89528eb3c22e7ae4 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:07:06 +0800 Subject: [PATCH 09/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index ef37b10..074733d 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -56,6 +56,7 @@ jobs: runs-on: ubuntu-latest needs: - create-version + - build-upi-echo-server steps: - name: Log in to the Container registry uses: docker/login-action@v1 From abaa7722aab94e0163a69c57541af6fc09309f1e Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:09:50 +0800 Subject: [PATCH 10/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 074733d..52dddef 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -73,6 +73,6 @@ jobs: - name: Publish Docker Image run: | IMAGE_TAG="${{ env.DOCKER_REGISTRY }}/caraml/upi-echo-server:${{ inputs.version }}" - docker image load --input upi-echo-server.${{ inputs.router_version }}.tar + docker image load --input upi-echo-server.${{ needs.create-version.outputs.version }}.tar docker tag upi-echo-server:${{ needs.create-version.outputs.version }} ${IMAGE_TAG} docker push ${IMAGE_TAG} From 3cb691d656564f980f1d3e5c0b7069c130f10436 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:15:04 +0800 Subject: [PATCH 11/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 52dddef..f5488df 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -72,7 +72,7 @@ jobs: - name: Publish Docker Image run: | - IMAGE_TAG="${{ env.DOCKER_REGISTRY }}/caraml/upi-echo-server:${{ inputs.version }}" + IMAGE_TAG="${{ env.DOCKER_REGISTRY }}/caraml/upi-echo-server:${{ needs.create-version.outputs.version }}" docker image load --input upi-echo-server.${{ needs.create-version.outputs.version }}.tar docker tag upi-echo-server:${{ needs.create-version.outputs.version }} ${IMAGE_TAG} docker push ${IMAGE_TAG} From 967184b9ad2f334ffbf2902222f29e81bb1016b6 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:19:49 +0800 Subject: [PATCH 12/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index f5488df..428409f 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -71,8 +71,10 @@ jobs: name: upi-echo-server.${{ needs.create-version.outputs.version }}.tar - name: Publish Docker Image + env: + CONTAINER_REGISTRY: ${{ env.DOCKER_REGISTRY }}//${{ github.repository_owner }} run: | - IMAGE_TAG="${{ env.DOCKER_REGISTRY }}/caraml/upi-echo-server:${{ needs.create-version.outputs.version }}" + IMAGE_TAG="${{ env.CONTAINER_REGISTRY }}/upi-echo-server:${{ needs.create-version.outputs.version }}" docker image load --input upi-echo-server.${{ needs.create-version.outputs.version }}.tar docker tag upi-echo-server:${{ needs.create-version.outputs.version }} ${IMAGE_TAG} docker push ${IMAGE_TAG} From bb54f9d078fb05eba1185e492160b1d890a0f531 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:25:04 +0800 Subject: [PATCH 13/29] test echo server ci - update publish --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 428409f..0f841a0 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -72,7 +72,7 @@ jobs: - name: Publish Docker Image env: - CONTAINER_REGISTRY: ${{ env.DOCKER_REGISTRY }}//${{ github.repository_owner }} + CONTAINER_REGISTRY: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }} run: | IMAGE_TAG="${{ env.CONTAINER_REGISTRY }}/upi-echo-server:${{ needs.create-version.outputs.version }}" docker image load --input upi-echo-server.${{ needs.create-version.outputs.version }}.tar From fb11f01b459e018c2193fc66c219f6c96010c2de Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 20:58:39 +0800 Subject: [PATCH 14/29] add test to ci --- .../workflows/publish-upi-echo-server.yaml | 22 ++++++++ example/go/simple/Dockerfilebu | 40 --------------- example/go/simple/client/main.go | 4 -- example/go/simple/server/main.go | 36 +------------ example/go/simple/server/server.go | 46 +++++++++++++++++ example/go/simple/server/server_test.go | 51 +++++++++++++++++++ 6 files changed, 121 insertions(+), 78 deletions(-) delete mode 100644 example/go/simple/Dockerfilebu create mode 100644 example/go/simple/server/server.go create mode 100644 example/go/simple/server/server_test.go diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 0f841a0..5de6816 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -12,6 +12,7 @@ on: env: DOCKER_REGISTRY: ghcr.io ARTIFACT_RETENTION_DAYS: 1 + GO_VERSION: 1.18 jobs: create-version: @@ -52,11 +53,32 @@ jobs: path: upi-echo-server.${{ needs.create-version.outputs.version }}.tar retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + test-upi-echo-server: + runs-on: ubuntu-latest + defaults: + run: + working-directory: example/go/simple + env: + GOPATH: ${{ github.workspace }}/example/go/simple/.go + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Test + run: | + go mod tidy + go test ./... + + publish-upi-echo-server: runs-on: ubuntu-latest needs: - create-version - build-upi-echo-server + - test-upi-echo-server steps: - name: Log in to the Container registry uses: docker/login-action@v1 diff --git a/example/go/simple/Dockerfilebu b/example/go/simple/Dockerfilebu deleted file mode 100644 index 96b9264..0000000 --- a/example/go/simple/Dockerfilebu +++ /dev/null @@ -1,40 +0,0 @@ -# Build application binary -FROM golang:1.18-alpine as builder -ARG BIN_NAME=turing-router -ARG VERSION -ARG USER -ARG HOST -ARG BRANCH -ARG NOW - -ENV GO111MODULE=on \ -GOOS=linux \ -GOARCH=amd64 - -ENV PROJECT_ROOT=github.com/caraml-dev/universal-prediction-interface/go/simple - -WORKDIR /app -COPY . . - -RUN go build \ --mod=vendor \ --tags musl \ --o ./bin/${BIN_NAME} \ --ldflags "\ --X ${PROJECT_ROOT}/internal.Version=${VERSION} \ --X ${PROJECT_ROOT}/internal.Branch=${BRANCH} \ --X ${PROJECT_ROOT}/internal.BuildUser=${USER}@${HOST} \ --X ${PROJECT_ROOT}/internal.BuildDate=${NOW}" \ --v ${PROJECT_ROOT}/cmd - -# Build the application image -FROM alpine:latest -ARG BIN_NAME=turing-router -ENV BIN_NAME ${BIN_NAME} - -RUN addgroup -S app && adduser -S app -G app -WORKDIR /app -RUN chown -R app:app /app -COPY --chown=app:app --from=builder /app/bin/* ./ -USER app -ENTRYPOINT ./${BIN_NAME} diff --git a/example/go/simple/client/main.go b/example/go/simple/client/main.go index 58852df..433b8bb 100644 --- a/example/go/simple/client/main.go +++ b/example/go/simple/client/main.go @@ -11,10 +11,6 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -const ( - defaultName = "world" -) - var ( addr = flag.String("addr", "localhost:50051", "the address to connect to") ) diff --git a/example/go/simple/server/main.go b/example/go/simple/server/main.go index b1601dd..76c9bb8 100644 --- a/example/go/simple/server/main.go +++ b/example/go/simple/server/main.go @@ -1,15 +1,9 @@ package main import ( - "context" "flag" "fmt" - "log" - "net" - upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" ) var ( @@ -20,34 +14,8 @@ type server struct { upiv1.UnimplementedUniversalPredictionServiceServer } -func (s *server) PredictValues( - _ context.Context, - req *upiv1.PredictValuesRequest, -) (*upiv1.PredictValuesResponse, error) { - return &upiv1.PredictValuesResponse{ - Metadata: &upiv1.ResponseMetadata{ - Models: []*upiv1.ModelMetadata{ - { - Name: "Echo Request Table", - Version: "1", - }, - }, - }, - PredictionResultTable: req.GetPredictionTable(), - }, nil -} - func main() { flag.Parse() - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - s := grpc.NewServer() - upiv1.RegisterUniversalPredictionServiceServer(s, &server{}) - reflection.Register(s) - log.Printf("listening on port %d", *port) - if err := s.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } + upiServer := UpiServer{} + upiServer.Run(fmt.Sprintf(":%d", *port)) } diff --git a/example/go/simple/server/server.go b/example/go/simple/server/server.go new file mode 100644 index 0000000..4bc6466 --- /dev/null +++ b/example/go/simple/server/server.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + "log" + "net" + + upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +type UpiServer struct { + upiv1.UnimplementedUniversalPredictionServiceServer +} + +func (_ *UpiServer) PredictValues( + _ context.Context, + req *upiv1.PredictValuesRequest, +) (*upiv1.PredictValuesResponse, error) { + return &upiv1.PredictValuesResponse{ + Metadata: &upiv1.ResponseMetadata{ + Models: []*upiv1.ModelMetadata{ + { + Name: "Echo Request Table", + Version: "1", + }, + }, + }, + PredictionResultTable: req.GetPredictionTable(), + }, nil +} + +func (us *UpiServer) Run(address string) { + lis, err := net.Listen("tcp", address) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + upiv1.RegisterUniversalPredictionServiceServer(s, us) + reflection.Register(s) + log.Printf("listening on port %s", address) + if err := s.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} diff --git a/example/go/simple/server/server_test.go b/example/go/simple/server/server_test.go new file mode 100644 index 0000000..ac1865d --- /dev/null +++ b/example/go/simple/server/server_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "context" + "fmt" + upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "log" + "testing" + "time" +) + +func TestUpiServer_Run(t *testing.T) { + address := fmt.Sprintf(":%d", 50555) + upiServer := UpiServer{} + go upiServer.Run(address) + + conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + + defer conn.Close() + c := upiv1.NewUniversalPredictionServiceClient(conn) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.PredictValues(ctx, &upiv1.PredictValuesRequest{ + PredictionTable: &upiv1.Table{ + Name: "Test", + Columns: []*upiv1.Column{ + { + Name: "col1", + Type: upiv1.Type_TYPE_DOUBLE, + }, + }, + Rows: []*upiv1.Row{ + { + RowId: "1", + Values: []*upiv1.Value{ + {}, + }, + }, + }, + }, + }) + if err != nil { + log.Fatalf("could not call upi server: %v", err) + } + log.Printf("Response: %s", r.String()) +} From 6f5d89d385113cd3f63711550043129e9d43655e Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Wed, 5 Oct 2022 21:04:23 +0800 Subject: [PATCH 15/29] change to publish and manual --- .github/workflows/publish-upi-echo-server.yaml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 5de6816..841c0f1 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,13 +1,8 @@ name: publish-upi-echo-server on: - push: + release: + types: [published] workflow_dispatch: - workflow_call: - inputs: - container_registry: - type: string - required: false - default: ghcr.io env: DOCKER_REGISTRY: ghcr.io @@ -72,7 +67,6 @@ jobs: go mod tidy go test ./... - publish-upi-echo-server: runs-on: ubuntu-latest needs: From 7f299165b8a571d98d66c98c18cee1add4aadb61 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:06:24 +0800 Subject: [PATCH 16/29] add readme and minor refactor --- example/README.md | 8 ++++++++ example/go/simple/server/main.go | 5 ----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 example/README.md diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..b113a40 --- /dev/null +++ b/example/README.md @@ -0,0 +1,8 @@ +# Universal Prediction Interface Example + +## Go Example +. +├── go/simple +│ ├── client # Go Client +│ └── server # Go Upi Echo Server +└── README.md \ No newline at end of file diff --git a/example/go/simple/server/main.go b/example/go/simple/server/main.go index 76c9bb8..294ff4a 100644 --- a/example/go/simple/server/main.go +++ b/example/go/simple/server/main.go @@ -3,17 +3,12 @@ package main import ( "flag" "fmt" - upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" ) var ( port = flag.Int("port", 50051, "The server port") ) -type server struct { - upiv1.UnimplementedUniversalPredictionServiceServer -} - func main() { flag.Parse() upiServer := UpiServer{} From d33d578561a6b8d2a054b37c6abbbd8110a92593 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:12:21 +0800 Subject: [PATCH 17/29] patch readme --- example/README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/example/README.md b/example/README.md index b113a40..d651393 100644 --- a/example/README.md +++ b/example/README.md @@ -1,8 +1,14 @@ # Universal Prediction Interface Example ## Go Example -. -├── go/simple -│ ├── client # Go Client -│ └── server # Go Upi Echo Server -└── README.md \ No newline at end of file +### UPI Echo Server +Server will return a dummy metadata and response table with request table if any. + + . + ├── go/simple + │ ├── client + │ │ └── main.go + │ └── server + │ ├── server.go + │ └── main.go + └── README.md \ No newline at end of file From 84f4c6359a0a2e4437d44105b720c251d58dad4f Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:16:51 +0800 Subject: [PATCH 18/29] remove on publish --- .github/workflows/publish-upi-echo-server.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 841c0f1..2fed003 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,7 +1,5 @@ name: publish-upi-echo-server on: - release: - types: [published] workflow_dispatch: env: From a4b574f34662afc5b6f769831caaba0ee8533148 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:27:04 +0800 Subject: [PATCH 19/29] make publish upi echo server on ci --- .github/workflows/ci.yaml | 2 ++ .github/workflows/publish-upi-echo-server.yaml | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e053135..4848753 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -74,3 +74,5 @@ jobs: output-file-path: ./gen/python/grpc/output.json external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true + publish-upi-echo-server: + uses: ./.github/workflows/publish-upi-echo-server.yml diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index 2fed003..b61d7f8 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,6 +1,4 @@ name: publish-upi-echo-server -on: - workflow_dispatch: env: DOCKER_REGISTRY: ghcr.io From 804bfedec3e061653fcff601efbdf513b9478034 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:28:16 +0800 Subject: [PATCH 20/29] make publish upi echo server on ci - patch on condition --- .github/workflows/publish-upi-echo-server.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index b61d7f8..b22b036 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,4 +1,7 @@ name: publish-upi-echo-server +on: + workflow_call: + workflow_dispatch: env: DOCKER_REGISTRY: ghcr.io From 802cb8500ef6033ffd9dcfb7f5fb6b2f784e9fc8 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:32:36 +0800 Subject: [PATCH 21/29] make publish upi echo server on ci - fix typo --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4848753..0765547 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -75,4 +75,4 @@ jobs: external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true publish-upi-echo-server: - uses: ./.github/workflows/publish-upi-echo-server.yml + uses: ./.github/workflows/publish-upi-echo-server.yaml From ab72bf91363fe90f92b419664e58e8bb9b7d51c8 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 11:47:37 +0800 Subject: [PATCH 22/29] rename workflow --- .github/workflows/ci.yaml | 2 +- ...blish-upi-echo-server.yaml => upi-echo-server.yaml} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename .github/workflows/{publish-upi-echo-server.yaml => upi-echo-server.yaml} (95%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0765547..058d599 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -75,4 +75,4 @@ jobs: external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true publish-upi-echo-server: - uses: ./.github/workflows/publish-upi-echo-server.yaml + uses: ./.github/workflows/upi-echo-server.yaml diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/upi-echo-server.yaml similarity index 95% rename from .github/workflows/publish-upi-echo-server.yaml rename to .github/workflows/upi-echo-server.yaml index b22b036..37cf863 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/upi-echo-server.yaml @@ -30,7 +30,7 @@ jobs: echo ${VERSION} echo "::set-output name=version::${VERSION}" - build-upi-echo-server: + build: runs-on: ubuntu-latest needs: - create-version @@ -47,7 +47,7 @@ jobs: path: upi-echo-server.${{ needs.create-version.outputs.version }}.tar retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} - test-upi-echo-server: + test: runs-on: ubuntu-latest defaults: run: @@ -66,12 +66,12 @@ jobs: go mod tidy go test ./... - publish-upi-echo-server: + release: runs-on: ubuntu-latest needs: - create-version - - build-upi-echo-server - - test-upi-echo-server + - build + - test steps: - name: Log in to the Container registry uses: docker/login-action@v1 From 1c83fb25ef189d0a8bc50e1b300fba5de28adaf0 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:00:37 +0800 Subject: [PATCH 23/29] allow manual trigger of ci --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 058d599..28fcf84 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,6 +4,7 @@ on: branches: [ main ] pull_request: branches: [] + workflow_dispatch: jobs: build: runs-on: ubuntu-latest From 02ba71e7d3ad24129f680f1b9e0672bc5e1dbe35 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:44:04 +0800 Subject: [PATCH 24/29] skip publish on pr --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 28fcf84..3396b83 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -76,4 +76,5 @@ jobs: external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true publish-upi-echo-server: + if: github.event_name != 'pull_request' uses: ./.github/workflows/upi-echo-server.yaml From e9b8a599155192306f7dc3b199f382dec74fa7f4 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:47:16 +0800 Subject: [PATCH 25/29] skip publish on pr bugfix and rename files --- .github/workflows/ci.yaml | 3 +-- .../{upi-echo-server.yaml => publish-upi-echo-server.yaml} | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{upi-echo-server.yaml => publish-upi-echo-server.yaml} (98%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3396b83..5d271de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -76,5 +76,4 @@ jobs: external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true publish-upi-echo-server: - if: github.event_name != 'pull_request' - uses: ./.github/workflows/upi-echo-server.yaml + uses: ./.github/workflows/publish-upi-echo-server.yaml diff --git a/.github/workflows/upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml similarity index 98% rename from .github/workflows/upi-echo-server.yaml rename to .github/workflows/publish-upi-echo-server.yaml index 37cf863..a35aa53 100644 --- a/.github/workflows/upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -1,4 +1,4 @@ -name: publish-upi-echo-server +name: upi-echo-server on: workflow_call: workflow_dispatch: @@ -67,6 +67,7 @@ jobs: go test ./... release: + if: github.event_name != 'pull_request' runs-on: ubuntu-latest needs: - create-version From cdcfa0e39f16284776d5d422ebca45d122862563 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:49:24 +0800 Subject: [PATCH 26/29] rename ci --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5d271de..51da689 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -75,5 +75,5 @@ jobs: output-file-path: ./gen/python/grpc/output.json external-data-json-path: ./cache/benchmark-data.json fail-on-alert: true - publish-upi-echo-server: + upi-echo-server: uses: ./.github/workflows/publish-upi-echo-server.yaml From 74e7c6b06a6e105a60e0754f7b02938edc011d95 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:54:30 +0800 Subject: [PATCH 27/29] refactor test --- example/go/simple/server/server_test.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/example/go/simple/server/server_test.go b/example/go/simple/server/server_test.go index ac1865d..067befa 100644 --- a/example/go/simple/server/server_test.go +++ b/example/go/simple/server/server_test.go @@ -3,18 +3,28 @@ package main import ( "context" "fmt" - upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" "log" + "os" "testing" "time" + + upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) -func TestUpiServer_Run(t *testing.T) { - address := fmt.Sprintf(":%d", 50555) +const testPort = 50555 + +var address = fmt.Sprintf(":%d", testPort) + +func TestMain(m *testing.M) { + upiServer := UpiServer{} go upiServer.Run(address) + os.Exit(m.Run()) +} + +func TestUpiServer_Run(t *testing.T) { conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { From 46d6baf1894d7d18ea6d8da97eb82dd0a8ebf452 Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 12:59:07 +0800 Subject: [PATCH 28/29] refactor test --- .github/workflows/publish-upi-echo-server.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-upi-echo-server.yaml b/.github/workflows/publish-upi-echo-server.yaml index a35aa53..b823b03 100644 --- a/.github/workflows/publish-upi-echo-server.yaml +++ b/.github/workflows/publish-upi-echo-server.yaml @@ -64,7 +64,7 @@ jobs: - name: Test run: | go mod tidy - go test ./... + go test ./... -v release: if: github.event_name != 'pull_request' From 37ca278691ed87c90be4bd56b9c42306c8084e4f Mon Sep 17 00:00:00 2001 From: "ningjie.lee" Date: Thu, 6 Oct 2022 13:05:30 +0800 Subject: [PATCH 29/29] refactor test --- example/go/simple/server/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/go/simple/server/server_test.go b/example/go/simple/server/server_test.go index 067befa..14ce800 100644 --- a/example/go/simple/server/server_test.go +++ b/example/go/simple/server/server_test.go @@ -26,7 +26,7 @@ func TestMain(m *testing.M) { func TestUpiServer_Run(t *testing.T) { - conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) if err != nil { log.Fatalf("did not connect: %v", err) }