diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c5e3724 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,85 @@ +# MIT License +# +# Copyright (c) 2022 EASE lab +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +name: Release + +on: + workflow_dispatch: + + # For all pushed tags + push: + tags: + - '*' + +env: + GOOS: linux + GO111MODULE: on + + +jobs: + build_release: + name: build_release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + + ## Test artifacts + + + + + - name: Build release + run: make build-release + # - name: Get the version + # id: get_version + # run: | + # echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//} + + - name: Get the version + id: version + run: echo "::set-output name=version::$(./bin/client --version)" + + + ## Create the release + - name: release + uses: actions/create-release@v1 + id: create_release + with: + draft: true + prerelease: true + release_name: ${{ steps.version.outputs.version }} + tag_name: ${{ github.ref }} + # body_path: CHANGELOG.md + env: + GITHUB_TOKEN: ${{ github.token }} + + ## Finally upload the artifacts + - name: upload linux artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./bin/client + asset_name: client-linux-amd64 + asset_content_type: application diff --git a/Makefile b/Makefile index e097c54..b00987a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,16 @@ - ## Protocol buffer + + +BIN_DIR=./bin +BIN=client +LINUX_OS=linux + + +.PHONY: build test installclean release bin-dir + + +# VERSION ?=LOCAL + proto-all: proto-all-python proto-all-go proto-all-python: @@ -16,3 +27,41 @@ proto-all-go: --go-grpc_out=. \ --go-grpc_opt=paths=source_relative \ ./proto/*/*.proto + + +build: wkdir + sed -i "s|LOCAL|$$(git rev-parse --short HEAD)|" ./cmd/version.go; + go build -o $(BIN_DIR)/$(BIN) cmd/*; +# git checkout -- ./cmd/version.go; + + + +build-release: wkdir + sed -i "s|LOCAL|$$(git rev-parse --short HEAD)|" ./cmd/version.go; \ + go build -o $(BIN_DIR)/$(BIN) cmd/*; \ + + +# if [ -z "$(shell git status --porcelain)" ]; then \ +# sed -i "s|LOCAL|$$(git rev-parse --short HEAD)|" ./cmd/version.go; \ +# go build -o $(BIN_DIR)/$(BIN) cmd/*; \ +# git checkout -- ./cmd/version.go; \ +# else \ +# echo Working directory not clean, commit changes; \ +# fi + +## Client for all proto buffer + +# client: test-client/main.go +# sed -i "s|LOCAL|$(VERSION)|" $<; +# go mod tidy +# go build -o $@ $< + +wkdir: + mkdir -p $(BIN_DIR) + +clean: + if [ -d $(BIN_DIR) ]; then rm -rf $(BIN_DIR); fi + +release: build-release + VERSION=$$($(BIN_DIR)/$(BIN) --version); \ + git tag $$VERSION; \ No newline at end of file diff --git a/README.md b/README.md index 4b42156..012b976 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # vSwarm-proto -vSwarm-proto is a utility for [vSwarm](https://github.com/ease-lab/vSwarm/) containing all the proto files and client applications necessary to run benchmarks using [relay](https://github.com/ease-lab/vSwarm/tree/main/tools/relay). \ No newline at end of file +vSwarm-proto is a utility for [vSwarm](https://github.com/ease-lab/vSwarm/) containing all the proto files and client applications necessary to run benchmarks using [relay](https://github.com/ease-lab/vSwarm/tree/main/tools/relay). + +## CLI command +The `cmd` subfolder contains a command line interface for invoking any kind of function that implement one of the protocols in this repository. + +## Releasing new versions +In order to release a new version do the following: +1. Increment the version number in `cmd/version.go`. +2. Build the release with `make release` +3. Push the new version with `git push ` + diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..4b6368d --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,124 @@ +/* MIT License + * + * Copyright (c) 2022 David Schall and EASE lab + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +// Package main implements a client for Greeter service. +package main + +import ( + "flag" + "fmt" + "log" + "os" + + // pb "google.golang.org/grpc/examples/helloworld/helloworld" + grpcClients "github.com/ease-lab/vSwarm-proto/grpcclient" +) + +const ( + defaultInput = "world" +) + +var ( + print_version = flag.Bool("version", false, "Version of client") + functionName = flag.String("function-name", "helloworld", "Specify the name of the function being invoked.") + url = flag.String("url", "0.0.0.0", "The url to connect to") + port = flag.String("port", "50051", "the port to connect to") + input = flag.String("input", defaultInput, "Input to the function") + functionMethod = flag.String("function-method", "default", "Which method of benchmark to invoke") + n = flag.Int("n", 10, "Number of invokations") + logfile = flag.String("logging", "", "Log to file instead of standart out") +) + +func main() { + flag.Parse() + + if *print_version { + fmt.Println(version) + os.Exit(0) + } + + // open file and create if non-existent + if *logfile != "" { + file, err := os.OpenFile(*logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Fatal(err) + } + defer file.Close() + log.SetOutput(file) + } + + log.Println("-- Invokation test --") + + // Set up a connection to the function server. + serviceName := grpcClients.FindServiceName(*functionName) + client := grpcClients.FindGrpcClient(serviceName) + client.Init(*url, *port) + defer client.Close() + + // conn, err := grpc.Dial(*addr, grpc.WithInsecure()) + // if err != nil { + // log.Fatalf("FAIL: did not connect: %v", err) + // } + // defer conn.Close() + // c := pb.NewGreeterClient(conn) + + // // // Contact the server and print out its response. + // ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + // defer cancel() + + // Create packet to send to the function + // var pkt grpcClients.Input + // pkt.SetGenerator(grpcClients.Unique) + // pkt.SetValue(*input) + generator := client.GetGenerator() + generator.SetGenerator(grpcClients.Unique) + generator.SetValue(*input) + generator.SetMethod(*functionMethod) + pkt := generator.Next() + + reply := client.Request(pkt) + // log.Debug(reply) + + // r, err := c.SayHello(ctx, &pb.HelloRequest{Name: *name}) + // if err != nil { + // log.Fatalf("FAIL: could not greet: %v", err) + // } + log.Printf("Greeting: %s", reply) + + // Print 5 times the progress + mod := 1 + if *n > 2*5 { + mod = *n / 5 + } + for i := 0; i < *n; i++ { + + // c.SayHello(ctx, &pb.HelloRequest{Name: *name}) + client.Request(pkt) + if i%mod == 0 { + log.Printf("Invoked for %d times\n", i) + } + } + log.Printf("Finished invoking: %s", reply) + log.Printf("SUCCESS: Calling functions for %d times", *n) +} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..22052e2 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,3 @@ +package main + +const version = "v0.1.3-LOCAL"