From 7ca6429f524739b8bc0f1135fe2a18922a2705f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Tue, 19 Apr 2022 20:46:06 +0300 Subject: [PATCH 01/25] change github action slack notification step --- .github/workflows/go.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1175caf..836d31c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -28,16 +28,19 @@ jobs: run: go test -count=1 -coverprofile=coverage.out ./... - name: Build app - run: go build -v . + id: build_go_app + run: | + go build -v . + echo ::set-output name=exit_code::$? - - name: Slack Notify Success - if: success() - uses: cemkiy/action-slacker@master - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + - name: Notify Slack on success + if: steps.build_go_app.outputs.exit_code == 0 + id: slack_notification + uses: ravsamhq/notify-slack-action@v1 with: - channel: '#github' - username: 'github' - icon_url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' - color: '#00FFAA' - title: ${{ github.repository }} -> ${{ github.sha }} + status: ${{ job.status }} + notification_title: 'Build succeeded' + message_format: 'Statoo build succeeded. <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>' + footer: 'repo: <{repo_url}|{repo}>' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} From d61ad09dababa603cc4526390e2066a0d9d5c918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 25 Apr 2022 12:27:14 +0300 Subject: [PATCH 02/25] fix Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 68db697..d1a9932 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.16-alpine AS builder WORKDIR /go/src/github.com/vigo/statoo COPY . . -RUN apk add --no-cache git=2.34.1-r0 \ +RUN apk add --no-cache git=2.34.2-r0 \ ca-certificates=20211220-r0 \ && CGO_ENABLED=0 \ GOOS=linux \ From c9c41b28c7c4a548e6357ee4943556ccdacfd1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Tue, 3 May 2022 09:17:57 +0300 Subject: [PATCH 03/25] set golangci's go version --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 2a6de72..97a943e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ run: concurrency: 4 timeout: 1m + go: '1.16' linters-settings: revive: From 2a62387bae7a0d70fa0d5b5da389b25b204431cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 29 Apr 2022 16:50:58 +0300 Subject: [PATCH 04/25] add response header lookup feature - use `-request-header` instead of `-header` - use `-response-header` for response header lookup (closes #10) - fix multiple platform docker build (closes #9) --- .../workflows/{docker.yml => docker-lint.yml} | 0 .github/workflows/dockerhub.yml | 32 ++++ README.md | 102 +++++----- Rakefile | 38 +--- app/app.go | 176 ++++++------------ app/app_test.go | 35 +--- app/bash_completion.go | 10 + app/flags/flags.go | 60 ++++++ app/flags/flags_test.go | 68 +++++++ app/usage.go | 34 ++++ main.go | 2 +- 11 files changed, 328 insertions(+), 229 deletions(-) rename .github/workflows/{docker.yml => docker-lint.yml} (100%) create mode 100644 .github/workflows/dockerhub.yml create mode 100644 app/bash_completion.go create mode 100644 app/flags/flags.go create mode 100644 app/flags/flags_test.go create mode 100644 app/usage.go diff --git a/.github/workflows/docker.yml b/.github/workflows/docker-lint.yml similarity index 100% rename from .github/workflows/docker.yml rename to .github/workflows/docker-lint.yml diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml new file mode 100644 index 0000000..17e7f2d --- /dev/null +++ b/.github/workflows/dockerhub.yml @@ -0,0 +1,32 @@ +name: Build and push to Dockerhub + +on: + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: vigo/statoo:latest diff --git a/README.md b/README.md index 4c088e2..3f71a14 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ [![Build Status](https://travis-ci.org/vigo/statoo.svg?branch=main)](https://travis-ci.org/vigo/statoo) ![Go Build Status](https://github.com/vigo/statoo/actions/workflows/go.yml/badge.svg) ![GolangCI-Lint Status](https://github.com/vigo/statoo/actions/workflows/golang-lint.yml/badge.svg) -![Docker Status](https://github.com/vigo/statoo/actions/workflows/docker.yml/badge.svg) +![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker.yml/badge.svg) ![Test Coverage](https://img.shields.io/badge/coverage-87.9%25-orange.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) - +![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) # Statoo @@ -46,15 +46,16 @@ usage: ./statoo [-flags] URL flags: - -version display version information (X.X.X) - -verbose verbose output (default: false) - -header request header, multiple allowed - -t, -timeout default timeout in seconds (default: 10, min: 1, max: 100) - -h, -help display help - -j, -json provides json output - -f, -find find text in response body if -json is set - -a, -auth basic auth "username:password" - -s, -skip skip certificate check and hostname in that certificate (default: false) + -version display version information (%s) + -verbose verbose output (default: false) + -request-header request header, multiple allowed, "Key: Value", case sensitive + -response-header response header for lookup -json is set, multiple allowed, "Key: Value" + -t, -timeout default timeout in seconds (default: %d, min: %d, max: %d) + -h, -help display help + -j, -json provides json output + -f, -find find text in response body if -json is set, case sensitive + -a, -auth basic auth "username:password" + -s, -skip skip certificate check and hostname in that certificate (default: false) examples: @@ -62,10 +63,14 @@ usage: ./statoo [-flags] URL $ ./statoo -timeout 30 "https://ugur.ozyilmazel.com" $ ./statoo -verbose "https://ugur.ozyilmazel.com" $ ./statoo -json https://vigo.io + $ ./statoo -json -find "python" https://vigo.io + $ ./statoo -json -find "Python" https://vigo.io $ ./statoo -json -find "Golang" https://vigo.io - $ ./statoo -header "Authorization: Bearer TOKEN" https://vigo.io - $ ./statoo -header "Authorization: Bearer TOKEN" -header "X-Api-Key: APIKEY" https://vigo.io + $ ./statoo -request-header "Authorization: Bearer TOKEN" https://vigo.io + $ ./statoo -request-header "Authorization: Bearer TOKEN" -header "X-Api-Key: APIKEY" https://vigo.io $ ./statoo -auth "user:secret" https://vigo.io + $ ./statoo -json -response-header "Server: GitHub.com" https://vigo.io + $ ./statoo -json -response-header "Server: GitHub.com" -response-header "Foo: bar" https://vigo.io ``` Let’s try: @@ -144,66 +149,69 @@ You can add basic authentication via `-auth` flag statoo -auth "username:password" https://your.basic.auth.url ``` -Now you can pass multiple `-header` flags: +Now you can pass multiple `-request-header` flags: ```bash -statoo -header "Key1: Value1" -header "Key2: Value2" "https://ugur.ozyilmazel.com" +statoo -request-header "Key1: Value1" -request-header "Key2: Value2" "https://ugur.ozyilmazel.com" ``` -It’s better to pipe `-json` output to `jq` or `python -m json.tool` for pretty print :) - -That’s it! +**New** -Bash completions is available via; +You can query/search for response headers. You can pass multiple values, all +**case sensitive**!. Let’s lookup for `Server` and `Foo` response header values. +`Server` value should be `GitHub.com` and `Foo` value should be `bar`: ```bash -eval "$(statoo bash-completion)" +statoo -json -response-header "Server: GitHub.com" -response-header "Foo: bar" https://vigo.io ``` ---- +Response: -## Rake Tasks - -```bash -rake -T +```json +{ + "url": "https://vigo.io", + "status": 200, + "checked_at": "2022-07-09T17:51:14.792987Z", + "elapsed": 305.502833, + "skipcc": false, + "response_headers": { + "Foo=bar": false, + "Server=GitHub.com": true + } +} ``` -```bash -rake default # show avaliable tasks (default task) -rake docker:build # Build (locally) -rake docker:build_and_push # Build and push to docker hub (latest) -rake docker:lint # Lint -rake docker:rmi # Delete image (locally) -rake docker:run # Run (locally) -rake release[revision] # Release new version major,minor,patch, default: patch -rake test:run[verbose] # run tests, generate coverage -rake test:show_coverage # show coverage after running tests -rake test:update_coverage # update coverage value in README -``` +`Server` response header matches exactly! ---- +It’s better to pipe `-json` output to `jq` or `python -m json.tool` for pretty +print :) -## Docker (local) +That’s it! -build: +Bash completions is available via; ```bash -docker build -t statoo:latest . +eval "$(statoo bash-completion)" ``` -run: +--- -```bash -docker run statoo:latest -h -``` +## Rake Tasks ```bash -docker run statoo:latest -json -find "Meetup organization" https://vigo.io +$ rake -T + +rake default # show avaliable tasks (default task) +rake docker:lint # lint Dockerfile +rake release[revision] # release new version major,minor,patch, default: patch +rake test:run[verbose] # run tests, generate coverage +rake test:show_coverage # show coverage after running tests +rake test:update_coverage # update coverage value in README ``` --- -## Docker (docker hub) +## Docker https://hub.docker.com/r/vigo/statoo/ diff --git a/Rakefile b/Rakefile index 10210ff..e241fb6 100644 --- a/Rakefile +++ b/Rakefile @@ -59,13 +59,13 @@ end # ----------------------------------------------------------------------------- -# run tests +# run tasks # ----------------------------------------------------------------------------- namespace :test do desc 'run tests, generate coverage' task :run, [:verbose] do |_, args| args.with_defaults(verbose: '') - system "go test -count=1 #{args.verbose} -coverprofile=coverage.out ./..." + system "go test -failfast -count=1 #{args.verbose} -coverprofile=coverage.out ./..." end desc "show coverage after running tests" @@ -90,7 +90,7 @@ end # release new version # ----------------------------------------------------------------------------- -desc "Release new version #{AVAILABLE_REVISIONS.join(',')}, default: patch" +desc "release new version #{AVAILABLE_REVISIONS.join(',')}, default: patch" task :release, [:revision] => [:repo_clean] do |_, args| args.with_defaults(revision: 'patch') Rake::Task['bump'].invoke(args.revision) @@ -101,39 +101,9 @@ end # docker # ----------------------------------------------------------------------------- namespace :docker do - desc "Lint" + desc "lint Dockerfile" task :lint do system "hadolint Dockerfile" end - - desc "Build (locally)" - task :build do - system "docker build -t statoo:latest ." - end - - desc "Build and push to docker hub (latest)" - task :build_and_push do - current_git_tag = "v#{Rake::Task['current_version'].execute.first.call}" - - system %{ - docker build -t vigo/statoo:latest . && - echo "-> vigo/statoo:latest" && - docker build -t vigo/statoo:#{current_git_tag} . && - echo "-> vigo/statoo:#{current_git_tag}" && - docker push vigo/statoo:latest && - docker push vigo/statoo:#{current_git_tag} && - echo "-> pushed both..." - } - end - - desc "Delete image (locally)" - task :rmi do - system "docker rmi statoo:latest" - end - - desc "Run (locally)" - task :run do - system "docker run statoo:latest -h" - end end # ----------------------------------------------------------------------------- diff --git a/app/app.go b/app/app.go index b61f586..8b2a707 100644 --- a/app/app.go +++ b/app/app.go @@ -5,7 +5,7 @@ Usage cmd := NewCLIApplication() if err := cmd.Run(); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } */ @@ -20,13 +20,13 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" "strings" "time" + "github.com/vigo/statoo/app/flags" "github.com/vigo/statoo/app/version" ) @@ -36,98 +36,20 @@ const ( defTimeoutMax = 100 ) -var ( - errEmptyHeader = errors.New("header should not be empty") - errInvalidHeader = errors.New("invalid header value") - errInvalidTimeout = errors.New("invalid timeout") -) - -// HeadersFlag holds header information for http request. -type HeadersFlag []string - -func (f *HeadersFlag) String() string { - return fmt.Sprintf("%s", *f) -} - -// Set appends valid header values to HeadersFlag. -func (f *HeadersFlag) Set(value string) error { - value = strings.TrimSpace(value) - if value == "" { - return errEmptyHeader - } - if strings.Count(value, ":") != 1 { - return fmt.Errorf("%w: %s", errInvalidHeader, value) - } - if len(strings.FieldsFunc(value, func(c rune) bool { return c == ':' })) != 2 { - return fmt.Errorf("%w: %s", errInvalidHeader, value) - } - *f = append(*f, value) - return nil -} +var errInvalidTimeout = errors.New("invalid timeout value") +// variable declarations. var ( - // ArgURL holds URL input from command-line. - ArgURL string - - // OptVersionInformation holds boolean for displaying version information. + ArgURL string OptVersionInformation *bool - - // OptTimeout holds default timeout for network transport operations. - OptTimeout *int - - // OptVerboseOutput holds boolean for displaying detailed output. - OptVerboseOutput *bool - - // OptJSONOutput holds boolean for json response instead of text. - OptJSONOutput *bool - - // OptHeaders holds custom request header key:value. - OptHeaders HeadersFlag - // OptFind holds lookup string in the body of the response. - OptFind *string - - // OptBasicAuth holds basic auth key:value credentials. - OptBasicAuth *string - - // OptInsecureSkipVerify holds certificate check option. + OptTimeout *int + OptVerboseOutput *bool + OptJSONOutput *bool + OptRequestHeaders flags.RequestHeadersFlag + OptResponseHeaders flags.ResponseHeadersFlag + OptFind *string + OptBasicAuth *string OptInsecureSkipVerify *bool - - usage = ` -usage: %[1]s [-flags] URL - - flags: - - -version display version information (%s) - -verbose verbose output (default: false) - -header request header, multiple allowed, "Key: Value" - -t, -timeout default timeout in seconds (default: %d, min: %d, max: %d) - -h, -help display help - -j, -json provides json output - -f, -find find text in response body if -json is set - -a, -auth basic auth "username:password" - -s, -skip skip certificate check and hostname in that certificate (default: false) - - examples: - - $ %[1]s "https://ugur.ozyilmazel.com" - $ %[1]s -timeout 30 "https://ugur.ozyilmazel.com" - $ %[1]s -verbose "https://ugur.ozyilmazel.com" - $ %[1]s -json https://vigo.io - $ %[1]s -json -find "python" https://vigo.io - $ %[1]s -header "Authorization: Bearer TOKEN" https://vigo.io - $ %[1]s -header "Authorization: Bearer TOKEN" -header "X-Api-Key: APIKEY" https://vigo.io - $ %[1]s -json -find "Golang" https://vigo.io - $ %[1]s -auth "user:secret" https://vigo.io - -` - bashCompletion = `__statoo_comp() -{ - local cur next - cur="${COMP_WORDS[COMP_CWORD]}" - opts="-a -auth -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version" - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) -} -complete -F __statoo_comp statoo` ) // CLIApplication represents app structure. @@ -137,14 +59,15 @@ type CLIApplication struct { // JSONResponse represents data structure of json response. type JSONResponse struct { - URL string `json:"url"` - Status int `json:"status"` - CheckedAt time.Time `json:"checked_at"` - Elapsed float64 `json:"elapsed,omitempty"` - Length int `json:"length,omitempty"` - Find *string `json:"find,omitempty"` - Found *bool `json:"found,omitempty"` - SkipCertificateCheck *bool `json:"skipcc,omitempty"` + URL string `json:"url"` + Status int `json:"status"` + CheckedAt time.Time `json:"checked_at"` + Elapsed float64 `json:"elapsed,omitempty"` + Length int `json:"length,omitempty"` + Find *string `json:"find,omitempty"` + Found *bool `json:"found,omitempty"` + SkipCertificateCheck *bool `json:"skipcc,omitempty"` + ResponseHeaders *map[string]bool `json:"response_headers,omitempty"` } func trimSpaces(s []string) { @@ -155,6 +78,7 @@ func trimSpaces(s []string) { func flagUsage(code int) func() { return func() { + // flag.PrintDefaults() fmt.Fprintf( os.Stdout, usage, @@ -174,7 +98,11 @@ func flagUsage(code int) func() { func NewCLIApplication() *CLIApplication { flag.Usage = flagUsage(0) - OptVersionInformation = flag.Bool("version", false, fmt.Sprintf("display version information (%s)", version.Version)) + OptVersionInformation = flag.Bool( + "version", + false, + fmt.Sprintf("display version information (%s)", version.Version), + ) OptVerboseOutput = flag.Bool("verbose", false, "verbose output") helpJSON := "provides json output" @@ -189,7 +117,11 @@ func NewCLIApplication() *CLIApplication { OptFind = flag.String("find", "", helpFind) flag.StringVar(OptFind, "f", "", helpFind+" (short)") - flag.Var(&OptHeaders, "header", "") + helpRequestHeaders := "add http headers to your request. can be multiple" + flag.Var(&OptRequestHeaders, "request-header", helpRequestHeaders) + + helpResponseHeaders := "query response headers, \"Server:GitHub.com\". can be multiple" + flag.Var(&OptResponseHeaders, "response-header", helpResponseHeaders) helpBasicAuth := "basic auth \"username:password\"" OptBasicAuth = flag.String("auth", "", helpBasicAuth) @@ -255,15 +187,15 @@ func (c *CLIApplication) GetResult() error { } ctx := context.Background() - req, err := http.NewRequestWithContext(ctx, "GET", ArgURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ArgURL, nil) if err != nil { return fmt.Errorf("request error: %w", err) } req.Header.Set("Accept-Encoding", "gzip") - if len(OptHeaders) > 0 { - for _, headerValue := range OptHeaders { + if len(OptRequestHeaders) > 0 { + for _, headerValue := range OptRequestHeaders { vals := strings.Split(headerValue, ":") trimSpaces(vals) req.Header.Set(vals[0], vals[1]) @@ -273,7 +205,6 @@ func (c *CLIApplication) GetResult() error { if *OptBasicAuth != "" { words := strings.Split(*OptBasicAuth, ":") trimSpaces(words) - fmt.Println("words", words) req.SetBasicAuth(words[0], words[1]) } @@ -284,13 +215,12 @@ func (c *CLIApplication) GetResult() error { } elapsed := time.Since(start) - if resp.Body != nil { - defer func() { - if errClose := resp.Body.Close(); err != nil { - fmt.Fprintln(os.Stderr, errClose.Error()) - } - }() - } + // The http Client and Transport guarantee that Body is always + // non-nil, even on responses without a body or responses with + // a zero-length body. + defer func() { + _ = resp.Body.Close() + }() if *OptJSONOutput { js := &JSONResponse{ @@ -303,6 +233,26 @@ func (c *CLIApplication) GetResult() error { SkipCertificateCheck: OptInsecureSkipVerify, } + if len(OptResponseHeaders) > 0 { + foundResponseHeaders := make(map[string]bool) + for _, headerValue := range OptResponseHeaders { + vals := strings.Split(headerValue, ":") + trimSpaces(vals) + mapKey := vals[0] + "=" + vals[1] + + hvals, ok := resp.Header[vals[0]] + if ok { + hval := hvals[0] + if hval == vals[1] { + foundResponseHeaders[mapKey] = true + } + } else { + foundResponseHeaders[mapKey] = false + } + } + js.ResponseHeaders = &foundResponseHeaders + } + if *OptFind != "" { var bodyReader io.ReadCloser @@ -314,7 +264,7 @@ func (c *CLIApplication) GetResult() error { } defer func() { if err := bodyReader.Close(); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) + fmt.Fprintln(os.Stderr, "gzip body reader close error: %w", err) } }() default: @@ -342,8 +292,6 @@ func (c *CLIApplication) GetResult() error { return nil } - _, _ = io.Copy(ioutil.Discard, resp.Body) - if *OptVerboseOutput { fmt.Fprintf(c.Out, "%s -> ", ArgURL) } diff --git a/app/app_test.go b/app/app_test.go index 0c37622..a380c45 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -4,7 +4,6 @@ import ( "bytes" "compress/gzip" "encoding/json" - "flag" "fmt" "io" "io/ioutil" @@ -18,36 +17,6 @@ import ( "github.com/vigo/statoo/app/version" ) -func TestCustomHeadersFlag(t *testing.T) { - var flags flag.FlagSet - var h app.HeadersFlag - - flags.Init("test", flag.ContinueOnError) - flags.Var(&h, "header", "usage") - - if err := flags.Parse([]string{"-header="}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foobar"}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foo.bar"}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foo.bar", "-header=foobar"}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foo;bar"}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foo:bar:baz"}); err == nil { - t.Error(err) - } - if err := flags.Parse([]string{"-header=foo:bar"}); err != nil { - t.Error(err) - } -} - type gzipResponseWriter struct { io.Writer http.ResponseWriter @@ -228,7 +197,7 @@ func TestResponse(t *testing.T) { app.ArgURL = "https://vigo.io" cmd.Out = new(bytes.Buffer) - want := "invalid timeout: 200" + want := "invalid timeout value: 200" if got := cmd.Run(); got.Error() != want { t.Errorf("want: %v, got: %v", want, got) } @@ -240,7 +209,7 @@ func TestResponse(t *testing.T) { app.ArgURL = "https://vigo.io" cmd.Out = new(bytes.Buffer) - want := "invalid timeout: 0" + want := "invalid timeout value: 0" if got := cmd.Run(); got.Error() != want { t.Errorf("want: %v, got: %v", want, got) } diff --git a/app/bash_completion.go b/app/bash_completion.go new file mode 100644 index 0000000..d09d7f7 --- /dev/null +++ b/app/bash_completion.go @@ -0,0 +1,10 @@ +package app + +var bashCompletion = `__statoo_comp() +{ + local cur next + cur="${COMP_WORDS[COMP_CWORD]}" + opts="-a -auth -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version" + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) +} +complete -F __statoo_comp statoo` diff --git a/app/flags/flags.go b/app/flags/flags.go new file mode 100644 index 0000000..d4c34f7 --- /dev/null +++ b/app/flags/flags.go @@ -0,0 +1,60 @@ +package flags + +import ( + "errors" + "fmt" + "strings" +) + +var ( + errEmptyRequestHeader = errors.New("empty request header value") + errInvalidRequestHeader = errors.New("invalid request header value") + errEmptyResponseHeader = errors.New("empty response header value") + errInvalidResponseHeader = errors.New("invalid response header value") +) + +// RequestHeadersFlag holds header information for http request. +type RequestHeadersFlag []string + +func (f *RequestHeadersFlag) String() string { + return fmt.Sprintf("%s", *f) +} + +// Set appends valid header values to RequestHeadersFlag. +func (f *RequestHeadersFlag) Set(value string) error { + value = strings.TrimSpace(value) + if value == "" { + return errEmptyRequestHeader + } + if strings.Count(value, ":") != 1 { + return fmt.Errorf("%w: %s", errInvalidRequestHeader, value) + } + if len(strings.FieldsFunc(value, func(c rune) bool { return c == ':' })) != 2 { + return fmt.Errorf("%w: %s", errInvalidRequestHeader, value) + } + *f = append(*f, value) + return nil +} + +// ResponseHeadersFlag ... +type ResponseHeadersFlag []string + +func (f *ResponseHeadersFlag) String() string { + return fmt.Sprintf("%s", *f) +} + +// Set appends valid response headers for lookup. +func (f *ResponseHeadersFlag) Set(value string) error { + value = strings.TrimSpace(value) + if value == "" { + return errEmptyResponseHeader + } + if strings.Count(value, ":") != 1 { + return fmt.Errorf("%w: %s", errInvalidResponseHeader, value) + } + if len(strings.FieldsFunc(value, func(c rune) bool { return c == ':' })) != 2 { + return fmt.Errorf("%w: %s", errInvalidResponseHeader, value) + } + *f = append(*f, value) + return nil +} diff --git a/app/flags/flags_test.go b/app/flags/flags_test.go new file mode 100644 index 0000000..b2359f7 --- /dev/null +++ b/app/flags/flags_test.go @@ -0,0 +1,68 @@ +package flags_test + +import ( + "flag" + "testing" + + "github.com/vigo/statoo/app/flags" +) + +func TestCustomRequestHeadersFlag(t *testing.T) { + var tflags flag.FlagSet + var h flags.RequestHeadersFlag + + tflags.Init("test", flag.ContinueOnError) + tflags.Var(&h, "request-header", "usage") + + if err := tflags.Parse([]string{"-request-header="}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foobar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foo.bar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foo.bar", "-header=foobar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foo;bar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foo:bar:baz"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-request-header=foo:bar"}); err != nil { + t.Error(err) + } +} + +func TestCustomResponseHeadersFlag(t *testing.T) { + var tflags flag.FlagSet + var h flags.ResponseHeadersFlag + + tflags.Init("test", flag.ContinueOnError) + tflags.Var(&h, "response-header", "usage") + + if err := tflags.Parse([]string{"-response-header="}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foobar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foo.bar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foo.bar", "-header=foobar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foo;bar"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foo:bar:baz"}); err == nil { + t.Error(err) + } + if err := tflags.Parse([]string{"-response-header=foo:bar"}); err != nil { + t.Error(err) + } +} diff --git a/app/usage.go b/app/usage.go new file mode 100644 index 0000000..db9ecba --- /dev/null +++ b/app/usage.go @@ -0,0 +1,34 @@ +package app + +var usage = ` +usage: %[1]s [-flags] URL + + flags: + + -version display version information (%s) + -verbose verbose output (default: false) + -request-header request header, multiple allowed, "Key: Value", case sensitive + -response-header response header for lookup -json is set, multiple allowed, "Key: Value" + -t, -timeout default timeout in seconds (default: %d, min: %d, max: %d) + -h, -help display help + -j, -json provides json output + -f, -find find text in response body if -json is set, case sensitive + -a, -auth basic auth "username:password" + -s, -skip skip certificate check and hostname in that certificate (default: false) + + examples: + + $ %[1]s "https://ugur.ozyilmazel.com" + $ %[1]s -timeout 30 "https://ugur.ozyilmazel.com" + $ %[1]s -verbose "https://ugur.ozyilmazel.com" + $ %[1]s -json https://vigo.io + $ %[1]s -json -find "python" https://vigo.io + $ %[1]s -json -find "Python" https://vigo.io + $ %[1]s -json -find "Golang" https://vigo.io + $ %[1]s -request-header "Authorization: Bearer TOKEN" https://vigo.io + $ %[1]s -request-header "Authorization: Bearer TOKEN" -header "X-Api-Key: APIKEY" https://vigo.io + $ %[1]s -auth "user:secret" https://vigo.io + $ %[1]s -json -response-header "Server: GitHub.com" https://vigo.io + $ %[1]s -json -response-header "Server: GitHub.com" -response-header "Foo: bar" https://vigo.io + +` diff --git a/main.go b/main.go index 5e8426f..152d19c 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( func main() { cmd := app.NewCLIApplication() if err := cmd.Run(); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } } From 8198a52bbae84f89b1cd8456e373cb35a2e38a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Sat, 9 Jul 2022 22:40:08 +0300 Subject: [PATCH 05/25] =?UTF-8?q?Bump=20version:=201.3.1=20=E2=86=92=202.0?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- README.md | 2 +- app/version/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f26d944..a601bbc 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.3.1 +current_version = 2.0.0 commit = True tag = True diff --git a/README.md b/README.md index 3f71a14..e8321cf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/badge/version-1.3.1-orange.svg) +![Version](https://img.shields.io/badge/version-2.0.0-orange.svg) ![Go](https://img.shields.io/github/go-mod/go-version/vigo/statoo) [![Documentation](https://godoc.org/github.com/vigo/statoo?status.svg)](https://pkg.go.dev/github.com/vigo/statoo) [![Go Report Card](https://goreportcard.com/badge/github.com/vigo/statoo)](https://goreportcard.com/report/github.com/vigo/statoo) diff --git a/app/version/version.go b/app/version/version.go index ff35f22..35b6751 100644 --- a/app/version/version.go +++ b/app/version/version.go @@ -1,4 +1,4 @@ package version // Version is the current version of statoo. -const Version string = "1.3.1" +const Version string = "2.0.0" From 443dac0ff7694e1596c32a9e5ab1fe3de8953c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Sat, 9 Jul 2022 22:47:44 +0300 Subject: [PATCH 06/25] fix docker lint badge url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8321cf..fb21d43 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build Status](https://travis-ci.org/vigo/statoo.svg?branch=main)](https://travis-ci.org/vigo/statoo) ![Go Build Status](https://github.com/vigo/statoo/actions/workflows/go.yml/badge.svg) ![GolangCI-Lint Status](https://github.com/vigo/statoo/actions/workflows/golang-lint.yml/badge.svg) -![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker.yml/badge.svg) +![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker-lint.yml/badge.svg) ![Test Coverage](https://img.shields.io/badge/coverage-87.9%25-orange.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) From 113913abd6a5c20cfb9b17b809eef0c1961adeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Sun, 10 Jul 2022 14:33:37 +0300 Subject: [PATCH 07/25] improve tests --- README.md | 2 +- app/app_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb21d43..9b8042a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![Go Build Status](https://github.com/vigo/statoo/actions/workflows/go.yml/badge.svg) ![GolangCI-Lint Status](https://github.com/vigo/statoo/actions/workflows/golang-lint.yml/badge.svg) ![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker-lint.yml/badge.svg) -![Test Coverage](https://img.shields.io/badge/coverage-87.9%25-orange.svg) +![Test Coverage](https://img.shields.io/badge/coverage-90.9%25-orange.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) ![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) diff --git a/app/app_test.go b/app/app_test.go index a380c45..272aa2c 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/vigo/statoo/app" + "github.com/vigo/statoo/app/flags" "github.com/vigo/statoo/app/version" ) @@ -43,6 +44,8 @@ func gzipWrapper(handler http.Handler) http.Handler { func TestResponse(t *testing.T) { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Header().Set("Server", "FakeServer") _, _ = w.Write([]byte("hello world\n")) }) @@ -125,6 +128,50 @@ func TestResponse(t *testing.T) { *app.OptJSONOutput = false }) + t.Run("find headers", func(t *testing.T) { + buff := new(bytes.Buffer) + cmd.Out = buff + + ts := httptest.NewServer(handler) + app.ArgURL = ts.URL + *app.OptJSONOutput = true + responseHeaders := flags.ResponseHeadersFlag{ + "Content-Type: text/plain; charset=utf-8", + "Server: FakeServer", + } + app.OptResponseHeaders = responseHeaders + + if err := cmd.Run(); err != nil { + t.Error(err) + } + + body, _ := ioutil.ReadAll(buff) + + jr := new(app.JSONResponse) + _ = json.Unmarshal(body, jr) + + if jr.ResponseHeaders == nil { + t.Error("must have response headers") + } + rh := *jr.ResponseHeaders + val, ok := rh["Content-Type=text/plain; charset=utf-8"] + if !ok { + t.Error("Content-Type=text/plain; charset=utf-8 not found") + } + + if !val { + t.Error("value must be true") + } + + val, ok = rh["Server=FakeServer"] + if !ok { + t.Error("Server not found") + } + if !val { + t.Error("value must be true") + } + }) + t.Run("find text", func(t *testing.T) { buff := new(bytes.Buffer) cmd.Out = buff From 6d4c6308a4f9433f6b07dd9fa1d9cc859f37515e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Thu, 28 Jul 2022 22:18:57 +0300 Subject: [PATCH 08/25] add FUNDING --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..4cbb05c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: vigo +patreon: vigoo From 5c294682b5176c8a5a1e63863317c44147a1272e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 7 Oct 2022 22:54:47 +0300 Subject: [PATCH 09/25] update go version --- .golangci.yml | 6 ++++-- app/app_test.go | 11 +++++------ app/flags/flags.go | 2 +- go.mod | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 97a943e..a1d8c0c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ run: concurrency: 4 timeout: 1m - go: '1.16' + go: '1.19' linters-settings: revive: @@ -72,12 +72,14 @@ linters: - noctx - prealloc - gosimple + - ineffassign + - unparam + - unused presets: - comment - error - format - metalinter - - unused issues: exclude-use-default: false \ No newline at end of file diff --git a/app/app_test.go b/app/app_test.go index 272aa2c..31bb217 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -93,7 +92,7 @@ func TestResponse(t *testing.T) { t.Error(err) } - body, _ := ioutil.ReadAll(buff) + body, _ := io.ReadAll(buff) jr := new(app.JSONResponse) _ = json.Unmarshal(body, jr) @@ -117,7 +116,7 @@ func TestResponse(t *testing.T) { t.Error(err) } - body, _ := ioutil.ReadAll(buff) + body, _ := io.ReadAll(buff) jr := new(app.JSONResponse) _ = json.Unmarshal(body, jr) @@ -145,7 +144,7 @@ func TestResponse(t *testing.T) { t.Error(err) } - body, _ := ioutil.ReadAll(buff) + body, _ := io.ReadAll(buff) jr := new(app.JSONResponse) _ = json.Unmarshal(body, jr) @@ -185,7 +184,7 @@ func TestResponse(t *testing.T) { t.Error(err) } - body, _ := ioutil.ReadAll(buff) + body, _ := io.ReadAll(buff) jr := new(app.JSONResponse) _ = json.Unmarshal(body, jr) @@ -221,7 +220,7 @@ func TestResponse(t *testing.T) { t.Error(err) } - body, _ := ioutil.ReadAll(buff) + body, _ := io.ReadAll(buff) jr := new(app.JSONResponse) _ = json.Unmarshal(body, jr) diff --git a/app/flags/flags.go b/app/flags/flags.go index d4c34f7..110f020 100644 --- a/app/flags/flags.go +++ b/app/flags/flags.go @@ -36,7 +36,7 @@ func (f *RequestHeadersFlag) Set(value string) error { return nil } -// ResponseHeadersFlag ... +// ResponseHeadersFlag represents http response headers. type ResponseHeadersFlag []string func (f *ResponseHeadersFlag) String() string { diff --git a/go.mod b/go.mod index 8ff291f..4c8e3cd 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/vigo/statoo -go 1.16 +go 1.19 From 74af15735016d89a519643e18718fda62815e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 7 Oct 2022 23:07:33 +0300 Subject: [PATCH 10/25] add codecov --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 836d31c..30bc7fb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,6 +27,9 @@ jobs: - name: Run tests run: go test -count=1 -coverprofile=coverage.out ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + - name: Build app id: build_go_app run: | From 2713abc67e830fe83998bb998fd5360fc6bbba97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 7 Oct 2022 23:13:04 +0300 Subject: [PATCH 11/25] fix codecov --- .github/workflows/go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 30bc7fb..c3fac0e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.16 - uses: actions/setup-go@v1 + - name: Set up Go 1.19 + uses: actions/setup-go@v3 with: - go-version: 1.16 + go-version: 1.19 id: go - name: Check out code into the Go module directory @@ -25,7 +25,7 @@ jobs: run: go mod download - name: Run tests - run: go test -count=1 -coverprofile=coverage.out ./... + run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./... - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 From c2d155a8ce92dfbdc2cdbb95e5b7dd38cdf259b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 7 Oct 2022 23:16:11 +0300 Subject: [PATCH 12/25] add codecov badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b8042a..ea1a982 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![Go Build Status](https://github.com/vigo/statoo/actions/workflows/go.yml/badge.svg) ![GolangCI-Lint Status](https://github.com/vigo/statoo/actions/workflows/golang-lint.yml/badge.svg) ![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker-lint.yml/badge.svg) -![Test Coverage](https://img.shields.io/badge/coverage-90.9%25-orange.svg) +[![codecov](https://codecov.io/gh/vigo/statoo/branch/main/graph/badge.svg?token=BTVK8VKVZM)](https://codecov.io/gh/vigo/statoo) ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) ![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) From c8c619ca5801d0313fbdaf8e685feb9f0161ce0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Fri, 7 Oct 2022 23:16:49 +0300 Subject: [PATCH 13/25] =?UTF-8?q?Bump=20version:=202.0.0=20=E2=86=92=202.0?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- README.md | 2 +- app/version/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index a601bbc..714a731 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.0 +current_version = 2.0.1 commit = True tag = True diff --git a/README.md b/README.md index ea1a982..ee5481c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/badge/version-2.0.0-orange.svg) +![Version](https://img.shields.io/badge/version-2.0.1-orange.svg) ![Go](https://img.shields.io/github/go-mod/go-version/vigo/statoo) [![Documentation](https://godoc.org/github.com/vigo/statoo?status.svg)](https://pkg.go.dev/github.com/vigo/statoo) [![Go Report Card](https://goreportcard.com/badge/github.com/vigo/statoo)](https://goreportcard.com/report/github.com/vigo/statoo) diff --git a/app/version/version.go b/app/version/version.go index 35b6751..218d3e3 100644 --- a/app/version/version.go +++ b/app/version/version.go @@ -1,4 +1,4 @@ package version // Version is the current version of statoo. -const Version string = "2.0.0" +const Version string = "2.0.1" From e294d9f9075a24a94775a7f073c80a12d05c9f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Wed, 23 Nov 2022 12:54:48 +0300 Subject: [PATCH 14/25] add commit hash information + update dockerfile --- Dockerfile | 8 ++++---- README.md | 11 +++++++++-- app/app.go | 34 ++++++++++++++++++++++++---------- app/bash_completion.go | 2 +- app/usage.go | 1 + app/version/version.go | 3 +++ 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1a9932..53a1b66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM golang:1.16-alpine AS builder +FROM golang:1.19-alpine AS builder WORKDIR /go/src/github.com/vigo/statoo COPY . . -RUN apk add --no-cache git=2.34.2-r0 \ - ca-certificates=20211220-r0 \ +RUN apk add --no-cache git=2.36.3-r0 \ + ca-certificates=20220614-r0 \ && CGO_ENABLED=0 \ GOOS=linux \ - go build -a -installsuffix cgo -o statoo . + go build -ldflags="-X 'github.com/vigo/statoo/app/version.CommitHash=$(git rev-parse HEAD)'" -a -installsuffix cgo -o statoo . FROM alpine:3.15 RUN apk --no-cache add diff --git a/README.md b/README.md index ee5481c..72fe823 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ usage: ./statoo [-flags] URL -f, -find find text in response body if -json is set, case sensitive -a, -auth basic auth "username:password" -s, -skip skip certificate check and hostname in that certificate (default: false) + -commithash displays current build/commit hash (%s) examples: @@ -155,8 +156,6 @@ Now you can pass multiple `-request-header` flags: statoo -request-header "Key1: Value1" -request-header "Key2: Value2" "https://ugur.ozyilmazel.com" ``` -**New** - You can query/search for response headers. You can pass multiple values, all **case sensitive**!. Let’s lookup for `Server` and `Foo` response header values. `Server` value should be `GitHub.com` and `Foo` value should be `bar`: @@ -194,6 +193,14 @@ Bash completions is available via; eval "$(statoo bash-completion)" ``` +**New** + +You can check current build/commit hash via; + +```bash +statoo -commithash +``` + --- ## Rake Tasks diff --git a/app/app.go b/app/app.go index 8b2a707..79953ea 100644 --- a/app/app.go +++ b/app/app.go @@ -40,16 +40,17 @@ var errInvalidTimeout = errors.New("invalid timeout value") // variable declarations. var ( - ArgURL string - OptVersionInformation *bool - OptTimeout *int - OptVerboseOutput *bool - OptJSONOutput *bool - OptRequestHeaders flags.RequestHeadersFlag - OptResponseHeaders flags.ResponseHeadersFlag - OptFind *string - OptBasicAuth *string - OptInsecureSkipVerify *bool + ArgURL string + OptVersionInformation *bool + OptCommitHashInformation *bool + OptTimeout *int + OptVerboseOutput *bool + OptJSONOutput *bool + OptRequestHeaders flags.RequestHeadersFlag + OptResponseHeaders flags.ResponseHeadersFlag + OptFind *string + OptBasicAuth *string + OptInsecureSkipVerify *bool ) // CLIApplication represents app structure. @@ -87,6 +88,7 @@ func flagUsage(code int) func() { defTimeout, defTimeoutMin, defTimeoutMax, + version.CommitHash, ) if code > 0 { os.Exit(code) @@ -103,6 +105,13 @@ func NewCLIApplication() *CLIApplication { false, fmt.Sprintf("display version information (%s)", version.Version), ) + + OptCommitHashInformation = flag.Bool( + "commithash", + false, + fmt.Sprintf("display build information (%s)", version.CommitHash), + ) + OptVerboseOutput = flag.Bool("verbose", false, "verbose output") helpJSON := "provides json output" @@ -147,6 +156,11 @@ func (c *CLIApplication) Run() error { return nil } + if *OptCommitHashInformation { + fmt.Fprintln(c.Out, version.CommitHash) + return nil + } + if ArgURL == "bash-completion" { fmt.Fprintln(c.Out, bashCompletion) return nil diff --git a/app/bash_completion.go b/app/bash_completion.go index d09d7f7..2beafc2 100644 --- a/app/bash_completion.go +++ b/app/bash_completion.go @@ -4,7 +4,7 @@ var bashCompletion = `__statoo_comp() { local cur next cur="${COMP_WORDS[COMP_CWORD]}" - opts="-a -auth -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version" + opts="-a -auth -commithash -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version" COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) } complete -F __statoo_comp statoo` diff --git a/app/usage.go b/app/usage.go index db9ecba..01adb24 100644 --- a/app/usage.go +++ b/app/usage.go @@ -15,6 +15,7 @@ usage: %[1]s [-flags] URL -f, -find find text in response body if -json is set, case sensitive -a, -auth basic auth "username:password" -s, -skip skip certificate check and hostname in that certificate (default: false) + -commithash displays current build/commit hash (%s) examples: diff --git a/app/version/version.go b/app/version/version.go index 218d3e3..84cfb38 100644 --- a/app/version/version.go +++ b/app/version/version.go @@ -2,3 +2,6 @@ package version // Version is the current version of statoo. const Version string = "2.0.1" + +// CommitHash represents current build/commit hash. +var CommitHash string From 7f1cc311eb1435a02c7110b52a628bbc91ffbeba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Wed, 23 Nov 2022 12:56:41 +0300 Subject: [PATCH 15/25] =?UTF-8?q?Bump=20version:=202.0.1=20=E2=86=92=202.0?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- README.md | 2 +- app/version/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 714a731..3d77bd1 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.1 +current_version = 2.0.2 commit = True tag = True diff --git a/README.md b/README.md index 72fe823..0caf374 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/badge/version-2.0.1-orange.svg) +![Version](https://img.shields.io/badge/version-2.0.2-orange.svg) ![Go](https://img.shields.io/github/go-mod/go-version/vigo/statoo) [![Documentation](https://godoc.org/github.com/vigo/statoo?status.svg)](https://pkg.go.dev/github.com/vigo/statoo) [![Go Report Card](https://goreportcard.com/badge/github.com/vigo/statoo)](https://goreportcard.com/report/github.com/vigo/statoo) diff --git a/app/version/version.go b/app/version/version.go index 84cfb38..76119b0 100644 --- a/app/version/version.go +++ b/app/version/version.go @@ -1,7 +1,7 @@ package version // Version is the current version of statoo. -const Version string = "2.0.1" +const Version string = "2.0.2" // CommitHash represents current build/commit hash. var CommitHash string From bfdc26e5d30b934f83b451ee75d9c5a734c4cf45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 7 Aug 2023 18:41:13 +0300 Subject: [PATCH 16/25] add powered by rake badge (#11) * add powered by rake badge * add CODEOWNERS --- .github/CODEOWNERS | 1 + README.md | 2 ++ app/app.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..69524d9 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @vigo diff --git a/README.md b/README.md index 0caf374..9bbc37c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) ![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) +![Powered by Rake](https://img.shields.io/badge/powered_by-rake-blue?logo=ruby) + # Statoo diff --git a/app/app.go b/app/app.go index 79953ea..7e0a378 100644 --- a/app/app.go +++ b/app/app.go @@ -79,7 +79,6 @@ func trimSpaces(s []string) { func flagUsage(code int) func() { return func() { - // flag.PrintDefaults() fmt.Fprintf( os.Stdout, usage, @@ -306,6 +305,8 @@ func (c *CLIApplication) GetResult() error { return nil } + _, _ = io.Copy(io.Discard, resp.Body) + if *OptVerboseOutput { fmt.Fprintf(c.Out, "%s -> ", ArgURL) } From 8ce99c430f5e9d3b3822f99cffa142679385c404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Sun, 27 Aug 2023 22:49:56 +0300 Subject: [PATCH 17/25] upgrade to v2 (#12) - upgrade go version - improve rake tasks - upgrade docker dependencies - upgrade github actions --- .github/workflows/go.yml | 76 +++++++++++++++++++--------------------- Dockerfile | 6 ++-- README.md | 12 ++++++- Rakefile | 24 +++++++++++++ app/app.go | 4 +-- app/app_test.go | 6 ++-- app/flags/flags_test.go | 2 +- go.mod | 4 +-- main.go | 2 +- 9 files changed, 84 insertions(+), 52 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c3fac0e..c1f86c5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,49 +1,47 @@ name: build and test + on: + pull_request: push: branches: - - main - - ST-* - pull_request: + - main + tags-ignore: + - '**' jobs: build: name: Build runs-on: ubuntu-latest steps: - - - name: Set up Go 1.19 - uses: actions/setup-go@v3 - with: - go-version: 1.19 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - - name: Get dependencies - run: go mod download - - - name: Run tests - run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - - - name: Build app - id: build_go_app - run: | - go build -v . - echo ::set-output name=exit_code::$? - - - name: Notify Slack on success - if: steps.build_go_app.outputs.exit_code == 0 - id: slack_notification - uses: ravsamhq/notify-slack-action@v1 - with: - status: ${{ job.status }} - notification_title: 'Build succeeded' - message_format: 'Statoo build succeeded. <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>' - footer: 'repo: <{repo_url}|{repo}>' - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: "go.mod" + id: go + + - name: Run tests + run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + + - name: Build app + id: build_go_app + run: | + go build -v . + echo ::set-output name=exit_code::$? + + - name: Notify Slack on success + if: steps.build_go_app.outputs.exit_code == 0 + id: slack_notification + uses: ravsamhq/notify-slack-action@v1 + with: + status: ${{ job.status }} + notification_title: 'Build succeeded' + message_format: 'Statoo build succeeded. <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>' + footer: 'repo: <{repo_url}|{repo}>' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/Dockerfile b/Dockerfile index 53a1b66..22b642b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM golang:1.19-alpine AS builder +FROM golang:1.21-alpine AS builder WORKDIR /go/src/github.com/vigo/statoo COPY . . -RUN apk add --no-cache git=2.36.3-r0 \ - ca-certificates=20220614-r0 \ +RUN apk add --no-cache git=2.40.1-r0 \ + ca-certificates=20230506-r0 \ && CGO_ENABLED=0 \ GOOS=linux \ go build -ldflags="-X 'github.com/vigo/statoo/app/version.CommitHash=$(git rev-parse HEAD)'" -a -installsuffix cgo -o statoo . diff --git a/README.md b/README.md index 9bbc37c..ec2c1d1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ you can make the same kind of request and get a kind-of same response since You can install from the source; ```bash -go install github.com/vigo/statoo@latest +go install github.com/vigo/statoo/v2@latest ``` or, you can install from `brew`: @@ -211,7 +211,9 @@ statoo -commithash $ rake -T rake default # show avaliable tasks (default task) +rake docker:build # Build image (locally) rake docker:lint # lint Dockerfile +rake docker:run[param] # Run image (locally) rake release[revision] # release new version major,minor,patch, default: patch rake test:run[verbose] # run tests, generate coverage rake test:show_coverage # show coverage after running tests @@ -230,6 +232,14 @@ docker run vigo/statoo -h docker run vigo/statoo -json -find "Meetup organization" https://vigo.io ``` +to run docker locally via rake task: + +```bash +rake docker:build +rake docker:run["-h"] +rake docker:run["https://ugur.ozyilmazel.com"] +``` + --- ## Contributor(s) diff --git a/Rakefile b/Rakefile index e241fb6..4526d8d 100644 --- a/Rakefile +++ b/Rakefile @@ -100,10 +100,34 @@ end # docker # ----------------------------------------------------------------------------- +DOCKER_IMAGE_TAG = 'statoo:latest' namespace :docker do desc "lint Dockerfile" task :lint do system "hadolint Dockerfile" end + + desc "Run image (locally)" + task :run, [:param] do |_, args| + cmd_args = [args.param] + args.extras + system %{ + docker run #{DOCKER_IMAGE_TAG} #{cmd_args.join(' ')} + } + exit $?.exitstatus + end + + desc "Build image (locally)" + task :build do + git_commit_hash = `git rev-parse HEAD`.chomp + goos =`go env GOOS`.chomp + goarch =`go env GOARCH`.chomp + build_commit_hash = "#{git_commit_hash}-#{goos}-#{goarch}" + + system %{ + docker build --build-arg="BUILD_INFORMATION=#{build_commit_hash}" \ + -t #{DOCKER_IMAGE_TAG} . + } + exit $?.exitstatus + end end # ----------------------------------------------------------------------------- diff --git a/app/app.go b/app/app.go index 7e0a378..e8aa2cc 100644 --- a/app/app.go +++ b/app/app.go @@ -26,8 +26,8 @@ import ( "strings" "time" - "github.com/vigo/statoo/app/flags" - "github.com/vigo/statoo/app/version" + "github.com/vigo/statoo/v2/app/flags" + "github.com/vigo/statoo/v2/app/version" ) const ( diff --git a/app/app_test.go b/app/app_test.go index 31bb217..46a1372 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -12,9 +12,9 @@ import ( "strings" "testing" - "github.com/vigo/statoo/app" - "github.com/vigo/statoo/app/flags" - "github.com/vigo/statoo/app/version" + "github.com/vigo/statoo/v2/app" + "github.com/vigo/statoo/v2/app/flags" + "github.com/vigo/statoo/v2/app/version" ) type gzipResponseWriter struct { diff --git a/app/flags/flags_test.go b/app/flags/flags_test.go index b2359f7..b1bf4c3 100644 --- a/app/flags/flags_test.go +++ b/app/flags/flags_test.go @@ -4,7 +4,7 @@ import ( "flag" "testing" - "github.com/vigo/statoo/app/flags" + "github.com/vigo/statoo/v2/app/flags" ) func TestCustomRequestHeadersFlag(t *testing.T) { diff --git a/go.mod b/go.mod index 4c8e3cd..4017b97 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/vigo/statoo +module github.com/vigo/statoo/v2 -go 1.19 +go 1.21 diff --git a/main.go b/main.go index 152d19c..ac97fc1 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/vigo/statoo/app" + "github.com/vigo/statoo/v2/app" ) func main() { From 22c483e7529f6c1da71273cae619eab184bb262c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Sun, 27 Aug 2023 22:56:55 +0300 Subject: [PATCH 18/25] =?UTF-8?q?Bump=20version:=202.0.2=20=E2=86=92=202.0?= =?UTF-8?q?.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- README.md | 2 +- app/version/version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 3d77bd1..658421f 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.2 +current_version = 2.0.3 commit = True tag = True diff --git a/README.md b/README.md index ec2c1d1..548d853 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/badge/version-2.0.2-orange.svg) +![Version](https://img.shields.io/badge/version-2.0.3-orange.svg) ![Go](https://img.shields.io/github/go-mod/go-version/vigo/statoo) [![Documentation](https://godoc.org/github.com/vigo/statoo?status.svg)](https://pkg.go.dev/github.com/vigo/statoo) [![Go Report Card](https://goreportcard.com/badge/github.com/vigo/statoo)](https://goreportcard.com/report/github.com/vigo/statoo) diff --git a/app/version/version.go b/app/version/version.go index 76119b0..f48c73a 100644 --- a/app/version/version.go +++ b/app/version/version.go @@ -1,7 +1,7 @@ package version // Version is the current version of statoo. -const Version string = "2.0.2" +const Version string = "2.0.3" // CommitHash represents current build/commit hash. var CommitHash string From fc465648918746a1b0642258ab8fe25dff491752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Wed, 25 Oct 2023 22:52:27 +0300 Subject: [PATCH 19/25] remove travis-ci badge :( --- .github/workflows/go.yml | 6 +++++- .github/workflows/golang-lint.yml | 13 ++++++++++--- README.md | 1 - 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c1f86c5..f502e16 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,7 +2,11 @@ name: build and test on: pull_request: + paths: + - '**.go' push: + paths: + - '**.go' branches: - main tags-ignore: @@ -14,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v4 diff --git a/.github/workflows/golang-lint.yml b/.github/workflows/golang-lint.yml index 891702b..fb72d6c 100644 --- a/.github/workflows/golang-lint.yml +++ b/.github/workflows/golang-lint.yml @@ -1,18 +1,25 @@ name: golangci-lint on: push: + paths: + - '**.go' branches: - main - - ST-* pull_request: + paths: + - '**.go' jobs: golangci: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: "go.mod" - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: latest + args: --timeout=5m diff --git a/README.md b/README.md index 548d853..b4c9781 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ![Go](https://img.shields.io/github/go-mod/go-version/vigo/statoo) [![Documentation](https://godoc.org/github.com/vigo/statoo?status.svg)](https://pkg.go.dev/github.com/vigo/statoo) [![Go Report Card](https://goreportcard.com/badge/github.com/vigo/statoo)](https://goreportcard.com/report/github.com/vigo/statoo) -[![Build Status](https://travis-ci.org/vigo/statoo.svg?branch=main)](https://travis-ci.org/vigo/statoo) ![Go Build Status](https://github.com/vigo/statoo/actions/workflows/go.yml/badge.svg) ![GolangCI-Lint Status](https://github.com/vigo/statoo/actions/workflows/golang-lint.yml/badge.svg) ![Docker Lint Status](https://github.com/vigo/statoo/actions/workflows/docker-lint.yml/badge.svg) From 270a4b578d0706ba4733f8d2f65d5d3304ae1900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Wed, 25 Oct 2023 23:05:18 +0300 Subject: [PATCH 20/25] fix naming --- .github/workflows/docker-lint.yml | 2 +- .github/workflows/go.yml | 2 +- .github/workflows/golang-lint.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-lint.yml b/.github/workflows/docker-lint.yml index 0c837f1..b435419 100644 --- a/.github/workflows/docker-lint.yml +++ b/.github/workflows/docker-lint.yml @@ -1,4 +1,4 @@ -name: dockerfile +name: Lint Dockerfile on: push diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f502e16..c0df099 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: build and test +name: Build and test app on: pull_request: diff --git a/.github/workflows/golang-lint.yml b/.github/workflows/golang-lint.yml index fb72d6c..3f3a52b 100644 --- a/.github/workflows/golang-lint.yml +++ b/.github/workflows/golang-lint.yml @@ -1,4 +1,4 @@ -name: golangci-lint +name: Run golangci-lint on: push: paths: From 048989d862681e26af6d92b57c53f27c72151790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Tue, 30 Apr 2024 10:10:10 +0300 Subject: [PATCH 21/25] add repobeat stats --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b4c9781..32b1d53 100644 --- a/README.md +++ b/README.md @@ -268,4 +268,8 @@ contributors are expected to adhere to the [code of conduct][coc]. This project is licensed under MIT +--- + +![Alt](https://repobeats.axiom.co/api/embed/7bd0cfb64834682c6cbac20e6168fc105bd27eeb.svg "Repobeats analytics image") + [coc]: https://github.com/vigo/statoo/blob/main/CODE_OF_CONDUCT.md \ No newline at end of file From 4030500beedacb97a296d853425be78e91b21e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 9 Sep 2024 11:02:53 +0300 Subject: [PATCH 22/25] add ghcr (#13) --- .github/workflows/githubcr.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/githubcr.yml diff --git a/.github/workflows/githubcr.yml b/.github/workflows/githubcr.yml new file mode 100644 index 0000000..573e182 --- /dev/null +++ b/.github/workflows/githubcr.yml @@ -0,0 +1,32 @@ +name: Build and push to GitHub Container Registry + +on: + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push to GitHub Container Registry + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/${{ github.repository }}/statoo:latest From d3d1c1e1276b867a117ec8c37c2525636e7d31d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 9 Sep 2024 11:08:30 +0300 Subject: [PATCH 23/25] add ghcr (#14) - add ghcr - fix Dockerfile --- .github/workflows/dockerhub.yml | 10 +++++----- Dockerfile | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 17e7f2d..28892ec 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -9,22 +9,22 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index 22b642b..5d15198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM golang:1.21-alpine AS builder WORKDIR /go/src/github.com/vigo/statoo COPY . . -RUN apk add --no-cache git=2.40.1-r0 \ - ca-certificates=20230506-r0 \ +RUN apk add --no-cache git=2.45.2-r0 \ + ca-certificates=20240705-r0 \ && CGO_ENABLED=0 \ GOOS=linux \ go build -ldflags="-X 'github.com/vigo/statoo/app/version.CommitHash=$(git rev-parse HEAD)'" -a -installsuffix cgo -o statoo . From e40649e6dd75e7c65ce488e238cce202bbec337c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 9 Sep 2024 11:13:35 +0300 Subject: [PATCH 24/25] add ghcr badge --- .github/workflows/githubcr.yml | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/githubcr.yml b/.github/workflows/githubcr.yml index 573e182..aae5199 100644 --- a/.github/workflows/githubcr.yml +++ b/.github/workflows/githubcr.yml @@ -1,4 +1,4 @@ -name: Build and push to GitHub Container Registry +name: Build and push to GitHub CR on: workflow_dispatch: diff --git a/README.md b/README.md index 32b1d53..5dee7cf 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) ![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) +[![GitHub Container Registry](https://github.com/vigo/statoo/actions/workflows/githubcr.yml/badge.svg)](https://github.com/vigo/statoo/actions/workflows/githubcr.yml) ![Powered by Rake](https://img.shields.io/badge/powered_by-rake-blue?logo=ruby) From 47716bb9d676d864cb868813846a757b929bdead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20=C3=96zy=C4=B1lmazel?= Date: Mon, 9 Sep 2024 11:15:15 +0300 Subject: [PATCH 25/25] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5dee7cf..95b5f87 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ![Docker Pulls](https://img.shields.io/docker/pulls/vigo/statoo) ![Docker Size](https://img.shields.io/docker/image-size/vigo/statoo) ![Docker Build Status](https://github.com/vigo/statoo/actions/workflows/dockerhub.yml/badge.svg) -[![GitHub Container Registry](https://github.com/vigo/statoo/actions/workflows/githubcr.yml/badge.svg)](https://github.com/vigo/statoo/actions/workflows/githubcr.yml) +[![Build and push to GitHub CR](https://github.com/vigo/statoo/actions/workflows/githubcr.yml/badge.svg)](https://github.com/vigo/statoo/actions/workflows/githubcr.yml) ![Powered by Rake](https://img.shields.io/badge/powered_by-rake-blue?logo=ruby)