From b670745bbd7abbefa8f600214cb9588fcd6bb707 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:05:58 +0300 Subject: [PATCH] upgrade to v2 - improve rake tasks - upgrade docker dependencies - upgrade go version - upgrade github actions --- .github/workflows/go.yml | 11 ++++------- 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, 51 insertions(+), 20 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c3fac0e..1d28eeb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,17 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 - uses: actions/setup-go@v3 + - name: Setup Go + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version-file: "go.mod" id: go - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - - name: Get dependencies - run: go mod download + uses: actions/checkout@v3 - name: Run tests run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./... 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..e398f27 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 ``` 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() {