diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml index 3790568f2..d71b49a19 100644 --- a/.github/workflows/publish-cli.yml +++ b/.github/workflows/publish-cli.yml @@ -2,8 +2,9 @@ name: public-cli on: push: branches: - - 'develop' - - 'main' + - develop + - main + - my-temp-release-check jobs: docker: runs-on: ubuntu-latest @@ -15,5 +16,32 @@ jobs: with: service_account_key: ${{ secrets.GCR_JSON_KEY }} export_default_credentials: true + - uses: haya14busa/action-cond@v1 + id: condval + with: + cond: ${{ github.ref == 'refs/heads/main' }} + if_true: "minor" + if_false: "patch" + - name: Auto Increment Semver Action + uses: MCKanpolat/auto-semver-action@1.0.5 + id: versioning + with: + releaseType: ${{ steps.condval.outputs.value }} + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Get base image name + shell: bash + run: | + echo "##[set-output name=build_timestamp;]$(echo $(date +%s))" + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: version_parameters - name: Build and Push CLI - run: make push-cli + run: make push-cli SEM_VER='${{ steps.versioning.outputs.version }}' BUILD_TIMESTAMP='${{ steps.version_parameters.outputs.build_timestamp }}' + - name: publish + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "cli/bin/*" + commit: ${{ steps.version_parameters.outputs.branch }} + tag: ${{ steps.versioning.outputs.version }} + prerelease: ${{ github.ref != 'refs/heads/main' }} + bodyFile: 'cli/bin/README.md' diff --git a/README.md b/README.md index efbcc082c..502fcde99 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,45 @@ standalone web app traffic viewer for Kubernetes ## Download -Download `mizu` for your platform as +Download `mizu` for your platform and operating system -* for MacOS - `curl -o mizu https://static.up9.com/mizu/mizu-darwin-amd64 && chmod 755 mizu` -* for Linux - `curl -o mizu https://static.up9.com/mizu/mizu-linux-amd64 && chmod 755 mizu` +### Latest stable release -## Run +* for MacOS - Intel +`curl -Lo mizu https://github.com/up9inc/mizu/releases/latest/download/mizu_darwin_amd64 && chmod 755 mizu` + +* for MacOS - Apple Silicon + `curl -Lo mizu https://github.com/up9inc/mizu/releases/latest/download/mizu_darwin_arm64 && chmod 755 mizu` + +* for Linux - Intel 64bit + `curl -Lo mizu https://github.com/up9inc/mizu/releases/latest/download/mizu_linux_amd64 && chmod 755 mizu` +SHA256 checksums are available on the [Releases](https://github.com/up9inc/mizu/releases) page. + +### Development (unstable) build +Pick one from the [Releases](https://github.com/up9inc/mizu/releases) page. + +## How to run 1. Find pod you'd like to tap to in your Kubernetes cluster -2. Run `mizu --pod podname` +2. Run `mizu PODNAME` or `mizu REGEX` 3. Open browser on `http://localhost:8899` as instructed .. 4. Watch the WebAPI traffic flowing .. +5. Type ^C to stop + +## Examples + +To tap specific pod - +``` + $ kubectl get pods | grep front-end + NAME READY STATUS RESTARTS AGE + front-end-649fc5fd6-kqbtn 2/2 Running 0 7m + $ mizu tap front-end-649fc5fd6-kqbtn + +front-end-649fc5fd6-kqbtn + Web interface is now available at http://localhost:8899 + ^C +``` + + + diff --git a/cli/Makefile b/cli/Makefile index 835ee9142..3dd9f043a 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,6 +1,8 @@ -FOLDER=$(GOOS).$(GOARCH) +SUFFIX=$(GOOS)_$(GOARCH) COMMIT_HASH=$(shell git rev-parse HEAD) GIT_BRANCH=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]') +GIT_VERSION=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]') +BUILD_TIMESTAMP=$(shell date +%s) .PHONY: help .DEFAULT_GOAL := help @@ -12,10 +14,16 @@ install: go install mizu.go build: ## build mizu CLI binary (select platform via GOOS / GOARCH env variables) - go build -ldflags="-X 'github.com/up9inc/mizu/cli/mizu.GitCommitHash=$(COMMIT_HASH)' -X 'github.com/up9inc/mizu/cli/mizu.Branch=$(GIT_BRANCH)'" -o bin/$(FOLDER)/mizu mizu.go + go build -ldflags="-X 'github.com/up9inc/mizu/cli/mizu.GitCommitHash=$(COMMIT_HASH)' \ + -X 'github.com/up9inc/mizu/cli/mizu.Branch=$(GIT_BRANCH)' \ + -X 'github.com/up9inc/mizu/cli/mizu.BuildTimestamp=$(BUILD_TIMESTAMP)' \ + -X 'github.com/up9inc/mizu/cli/mizu.SemVer=$(SEM_VER)'" \ + -o bin/mizu_$(SUFFIX) mizu.go + (cd bin && shasum -a 256 mizu_${SUFFIX} > mizu_${SUFFIX}.sha256) build-all: ## build for all supported platforms @echo "Compiling for every OS and Platform" + @mkdir -p bin && echo "SHA256 checksums available for compiled binaries \n\nRun \`shasum -a 256 -c mizu_OS_ARCH.sha256\` to verify\n\n" > bin/README.md @$(MAKE) build GOOS=darwin GOARCH=amd64 @$(MAKE) build GOOS=linux GOARCH=amd64 @# $(MAKE) GOOS=windows GOARCH=amd64 diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index e01294e1d..679e46dbe 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -249,11 +249,7 @@ func createRBACIfNecessary(ctx context.Context, kubernetesProvider *kubernetes.P return false } if !mizuRBACExists { - var versionString = mizu.Version - if mizu.GitCommitHash != "" { - versionString += "-" + mizu.GitCommitHash - } - err := kubernetesProvider.CreateMizuRBAC(ctx, mizu.ResourcesNamespace, versionString) + err := kubernetesProvider.CreateMizuRBAC(ctx, mizu.ResourcesNamespace, mizu.RBACVersion) if err != nil { fmt.Printf("warning: could not create mizu rbac resources %v\n", err) return false diff --git a/cli/cmd/version.go b/cli/cmd/version.go index 11a348a27..366b05da2 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -3,19 +3,38 @@ package cmd import ( "fmt" "github.com/up9inc/mizu/cli/mizu" + "strconv" + "time" "github.com/spf13/cobra" ) +type MizuVersionOptions struct { + DebugInfo bool +} + + +var mizuVersionOptions = &MizuVersionOptions{} + var versionCmd = &cobra.Command{ Use: "version", Short: "Print version info", RunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("%s (%s) %s\n", mizu.Version, mizu.Branch, mizu.GitCommitHash) + if mizuVersionOptions.DebugInfo { + timeStampInt, _ := strconv.ParseInt(mizu.BuildTimestamp, 10, 0) + fmt.Printf("Version: %s \nBranch: %s (%s) \n", mizu.SemVer, mizu.Branch, mizu.GitCommitHash) + fmt.Printf("Build Time: %s (%s)\n", mizu.BuildTimestamp, time.Unix(timeStampInt, 0)) + + } else { + fmt.Printf("Version: %s (%s)\n", mizu.SemVer, mizu.Branch) + } return nil }, } func init() { rootCmd.AddCommand(versionCmd) + + versionCmd.Flags().BoolVarP(&mizuVersionOptions.DebugInfo, "debug", "d", false, "Provide all information about version") + } diff --git a/cli/mizu/consts.go b/cli/mizu/consts.go index 59d33f1b0..9f72620ad 100644 --- a/cli/mizu/consts.go +++ b/cli/mizu/consts.go @@ -1,9 +1,11 @@ package mizu var ( - Version = "v0.0.1" - Branch = "develop" - GitCommitHash = "" // this var is overridden using ldflags in makefile when building + SemVer = "0.0.1" + Branch = "develop" + GitCommitHash = "" // this var is overridden using ldflags in makefile when building + BuildTimestamp = "" // this var is overridden using ldflags in makefile when building + RBACVersion = "v1" ) const (