diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index fe345b1..1e7f8ca 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -12,57 +12,56 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ 1.14.x, 1.15.x, 1.16.x ] + go-version: [ 1.18.x, 1.19.x, 1.20.x ] steps: - - uses: actions/checkout@v2 - - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - id: go - - name: Run test scripts - run: | - make setup - make test-ci - env: - GO111MODULE: on - - name: Send coverage - env: - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: make coverage + - uses: actions/checkout@v2 + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + id: go + - name: Run test scripts + run: | + make test-ci + env: + GO111MODULE: on + - name: Send coverage + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make coverage build: name: Build runs-on: ubuntu-latest strategy: matrix: - go-version: [ 1.14.x, 1.15.x, 1.16.x ] + go-version: [ 1.18.x, 1.19.x, 1.20.x ] steps: - - uses: actions/checkout@v2 - - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - id: go - - name: Build - run: make compile - env: - GO111MODULE: on + - uses: actions/checkout@v2 + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + id: go + - name: Build + run: make compile + env: + GO111MODULE: on docs: name: Docs runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: Test Build - run: | - cd website - if [ -e yarn.lock ]; then - yarn install --frozen-lockfile - elif [ -e package-lock.json ]; then - npm ci - else - npm i - fi - npm run build + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12.x' + - name: Test Build + run: | + cd website + if [ -e yarn.lock ]; then + yarn install --frozen-lockfile + elif [ -e package-lock.json ]; then + npm ci + else + npm i + fi + npm run build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2be33c..ee036ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,64 +3,64 @@ name: Release on: push: tags: - - v\d+.\d+.\d+ + - v\d+.\d+.\d+ jobs: release: name: Docker Push runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Build Push - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - shell: bash - run: | - docker run --rm --privileged -v $(pwd):/darkroom \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v $(which docker):$(which docker) -w /darkroom \ - -e GITHUB_TOKEN \ - -e DOCKER_USERNAME \ - -e DOCKER_PASSWORD \ - ajatprabha/ci-goreleaser \ - /bin/bash -c "echo $DOCKER_PASSWORD | docker login docker.io --username $DOCKER_USERNAME --password-stdin && goreleaser release --skip-validate --rm-dist" + - uses: actions/checkout@v2 + - name: Build Push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + shell: bash + run: | + docker run --rm --privileged -v $(pwd):/darkroom \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v $(which docker):$(which docker) -w /darkroom \ + -e GITHUB_TOKEN \ + -e DOCKER_USERNAME \ + -e DOCKER_PASSWORD \ + ajatprabha/ci-goreleaser \ + /bin/bash -c "echo $DOCKER_PASSWORD | docker login docker.io --username $DOCKER_USERNAME --password-stdin && goreleaser release --skip-validate --rm-dist" release-docs: name: Publish GH Pages runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: Add key to allow access to repository - env: - SSH_AUTH_SOCK: /tmp/ssh_agent.sock - GH_PAGES_DEPLOY: ${{ secrets.CI_DEPLOY_KEY }} - run: | - mkdir -p ~/.ssh - ssh-keyscan github.com >> ~/.ssh/known_hosts - echo "$GH_PAGES_DEPLOY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - cat <> ~/.ssh/config - Host github.com - HostName github.com - IdentityFile ~/.ssh/id_rsa - EOT - - name: Release to GitHub Pages - env: - USE_SSH: true - GIT_USER: git - run: | - cd website - git config --global user.email "actions@gihub.com" - git config --global user.name "gh-actions" - if [ -e yarn.lock ]; then - yarn install --frozen-lockfile - elif [ -e package-lock.json ]; then - npm ci - else - npm i - fi - npx docusaurus deploy + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12.x' + - name: Add key to allow access to repository + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + GH_PAGES_DEPLOY: ${{ secrets.CI_DEPLOY_KEY }} + run: | + mkdir -p ~/.ssh + ssh-keyscan github.com >> ~/.ssh/known_hosts + echo "$GH_PAGES_DEPLOY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + cat <> ~/.ssh/config + Host github.com + HostName github.com + IdentityFile ~/.ssh/id_rsa + EOT + - name: Release to GitHub Pages + env: + USE_SSH: true + GIT_USER: git + run: | + cd website + git config --global user.email "actions@gihub.com" + git config --global user.name "gh-actions" + if [ -e yarn.lock ]; then + yarn install --frozen-lockfile + elif [ -e package-lock.json ]; then + npm ci + else + npm i + fi + npx docusaurus deploy diff --git a/Makefile b/Makefile index acee0f0..fe5ad19 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,6 @@ GO_RUN := GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=1 go run $(LD_FLAGS) all: test-ci -setup: - go get golang.org/x/lint/golint - run: copy-config @$(GO_RUN) main.go server @@ -37,8 +34,8 @@ compile: @mkdir -p $(BUILD_DIR) @$(GO_BUILD) -o $(APP_EXECUTABLE) main.go -lint: - @golint ./... | { grep -vwE "exported (var|function|method|type|const) \S+ should have comment" || true; } +lint: golint + @$(GOLINT) ./... | { grep -vwE "exported (var|function|method|type|const) \S+ should have comment" || true; } format: go fmt ./... @@ -63,18 +60,25 @@ docker-docs: test-ci: copy-config compile lint format vet test -# find or download goveralls +### Helper functions + +golint: + $(call install-if-needed,GOLINT,golang.org/x/lint/golint,v0.0.0-20210508222113-6edffad5e616) + goveralls: -ifeq (, $(shell which goveralls)) - @{ \ + $(call install-if-needed,GOVERALLS,github.com/mattn/goveralls,v0.0.12) + +is-available = $(if $(shell command -v $(1) 2> /dev/null),yes,no) + +define install-if-needed + @if [ $(call is-available,$(notdir $(2))) = "no" ] ; then \ + echo "Installing $(2)..." ;\ set -e ;\ - GOVERALLS_TMP_DIR=$$(mktemp -d) ;\ - cd $$GOVERALLS_TMP_DIR ;\ + TMP_DIR=$$(mktemp -d) ;\ + cd $$TMP_DIR ;\ go mod init tmp ;\ - go get github.com/mattn/goveralls ;\ - rm -rf $$GOVERALLS_TMP_DIR ;\ - } -GOVERALLS=$(GOBIN)/goveralls -else -GOVERALLS=$(shell which goveralls) -endif + go install $(2)@$(3) ;\ + rm -rf $$TMP_DIR ;\ + fi + @$(eval $1 := $(if $(shell command -v $(notdir $(2))),$(shell command -v $(notdir $(2))),$(GOBIN)/$(notdir $(2)))) +endef diff --git a/build/Dockerfile b/build/Dockerfile index bfb695d..285fe7d 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.16-alpine AS builder +FROM golang:1.20-alpine AS builder ENV GO111MODULE=on WORKDIR /app COPY . . diff --git a/go.mod b/go.mod index 82a76f0..71c4fe4 100644 --- a/go.mod +++ b/go.mod @@ -1,30 +1,74 @@ module github.com/gojek/darkroom -go 1.16 +go 1.18 require ( cloud.google.com/go/storage v1.0.0 - github.com/DataDog/datadog-go v2.2.0+incompatible // indirect github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/anthonynsimon/bild v0.13.0 github.com/aws/aws-sdk-go v1.34.0 github.com/cactus/go-statsd-client/statsd v0.0.0-20190501063751-9a7692639588 github.com/chai2010/webp v1.1.0 github.com/gojektech/heimdall v5.0.2+incompatible - github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect github.com/gorilla/mux v1.8.0 - github.com/pelletier/go-toml v1.4.0 // indirect github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.1 - github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962 // indirect - github.com/smartystreets/assertions v1.0.0 // indirect github.com/spf13/cobra v1.1.3 - github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/viper v1.7.0 github.com/stretchr/testify v1.7.0 - go.opencensus.io v0.22.2 // indirect go.uber.org/zap v1.17.0 - golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 // indirect google.golang.org/api v0.13.0 sigs.k8s.io/controller-runtime v0.6.1 ) + +require ( + cloud.google.com/go v0.46.3 // indirect + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/DataDog/datadog-go v2.2.0+incompatible // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect + github.com/golang/protobuf v1.4.3 // indirect + github.com/googleapis/gax-go/v2 v2.0.5 // indirect + github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/jmespath/go-jmespath v0.3.0 // indirect + github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 // indirect + github.com/magiconair/properties v1.8.1 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect + github.com/pelletier/go-toml v1.4.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.26.0 // indirect + github.com/prometheus/procfs v0.6.0 // indirect + github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962 // indirect + github.com/smartystreets/assertions v1.0.0 // indirect + github.com/spf13/afero v1.2.2 // indirect + github.com/spf13/cast v1.3.0 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/objx v0.2.0 // indirect + github.com/subosito/gotenv v1.2.0 // indirect + go.opencensus.io v0.22.2 // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect + golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 // indirect + golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect + golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect + golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect + golang.org/x/text v0.3.3 // indirect + golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 // indirect + google.golang.org/appengine v1.6.1 // indirect + google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect + google.golang.org/grpc v1.26.0 // indirect + google.golang.org/protobuf v1.26.0-rc.1 // indirect + gopkg.in/ini.v1 v1.51.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + honnef.co/go/tools v0.0.1-2019.2.3 // indirect +) diff --git a/go.sum b/go.sum index fb1c557..d4090d3 100644 --- a/go.sum +++ b/go.sum @@ -65,7 +65,6 @@ github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/cactus/go-statsd-client/statsd v0.0.0-20190501063751-9a7692639588 h1:6yVhh6P5OsW6HutPt7z2ggDgZczgUtSl2kGRe+DslPU= github.com/cactus/go-statsd-client/statsd v0.0.0-20190501063751-9a7692639588/go.mod h1:3/sdo8I67TaOslRGJ6FqQC/ynu+wg7H6IE4WYtr51hk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= diff --git a/pkg/config/config.go b/pkg/config/config.go index 2b41a55..577ac64 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -99,7 +99,7 @@ func DefaultParams() []string { return strings.Split(getConfig().defaultParams, ";") } -// MetricSystem returns the metrics system to be used for MetricService in dependencies from the environment +// MetricsSystem returns the metrics system to be used for MetricService in dependencies from the environment func MetricsSystem() string { return getConfig().metricsSystem } diff --git a/pkg/regex/regex.go b/pkg/regex/regex.go index eaf9a32..472ec12 100644 --- a/pkg/regex/regex.go +++ b/pkg/regex/regex.go @@ -13,6 +13,6 @@ var ( WebFolderMatcher = regexp.MustCompile("^(?i)webfolder$") // PrometheusMatcher regex matches against string prometheus in any case PrometheusMatcher = regexp.MustCompile("^(?i)prometheus$") - // StatsDMatcher regex matches against string statsd in any case + // StatsdMatcher regex matches against string statsd in any case StatsdMatcher = regexp.MustCompile("^(?i)statsd$") ) diff --git a/pkg/storage/gcs/hystrix.go b/pkg/storage/gcs/hystrix.go index 88d92ba..c8d5636 100644 --- a/pkg/storage/gcs/hystrix.go +++ b/pkg/storage/gcs/hystrix.go @@ -14,8 +14,8 @@ import ( const userAgent = "gcloud-golang-storage/20151204" -func newHeimdallHTTPClient(ctx context.Context, hc heimdall.Client, credentialsJson []byte) (*http.Client, error) { - t, err := newTransport(ctx, hc, credentialsJson) +func newHeimdallHTTPClient(ctx context.Context, hc heimdall.Client, credentialsJSON []byte) (*http.Client, error) { + t, err := newTransport(ctx, hc, credentialsJSON) if err != nil { return nil, err } @@ -24,10 +24,10 @@ func newHeimdallHTTPClient(ctx context.Context, hc heimdall.Client, credentialsJ }, nil } -func newTransport(ctx context.Context, hc heimdall.Client, credentialsJson []byte) (http.RoundTripper, error) { +func newTransport(ctx context.Context, hc heimdall.Client, credentialsJSON []byte) (http.RoundTripper, error) { o := option.WithoutAuthentication() - if len(credentialsJson) > 0 { - o = option.WithCredentialsJSON(credentialsJson) + if len(credentialsJSON) > 0 { + o = option.WithCredentialsJSON(credentialsJSON) } return gcloud.NewTransport(ctx, &hystrixTransport{client: hc}, diff --git a/pkg/storage/gcs/storage_test.go b/pkg/storage/gcs/storage_test.go index 0fb588c..a648bb6 100644 --- a/pkg/storage/gcs/storage_test.go +++ b/pkg/storage/gcs/storage_test.go @@ -182,17 +182,17 @@ func (s *StorageTestSuite) TestBenchForStorage_GetPartially() { name string ctx context.Context path string - range_ *string + rangeStr *string newReaderReturn func() (Reader, error) newRangeReaderReturn func() (Reader, error) attrsReturn func() (*storage.ObjectAttrs, error) res storageTypes.IResponse }{ { - name: "Success", - ctx: context.TODO(), - path: validPath, - range_: &validRange, + name: "Success", + ctx: context.TODO(), + path: validPath, + rangeStr: &validRange, newRangeReaderReturn: func() (Reader, error) { return ioutil.NopCloser(strings.NewReader("someData")), nil }, @@ -227,10 +227,10 @@ func (s *StorageTestSuite) TestBenchForStorage_GetPartially() { res: storageTypes.NewResponse([]byte("someData"), http.StatusOK, nil), }, { - name: "WithEmptyRangeValue", - ctx: context.TODO(), - path: validPath, - range_: &emptyRange, + name: "WithEmptyRangeValue", + ctx: context.TODO(), + path: validPath, + rangeStr: &emptyRange, newReaderReturn: func() (Reader, error) { return ioutil.NopCloser(strings.NewReader("someData")), nil }, @@ -246,20 +246,20 @@ func (s *StorageTestSuite) TestBenchForStorage_GetPartially() { res: storageTypes.NewResponse(nil, http.StatusNotFound, storage.ErrObjectNotExist), }, { - name: "OnInvalidRange", - ctx: context.TODO(), - path: validPath, - range_: &invalidRange, + name: "OnInvalidRange", + ctx: context.TODO(), + path: validPath, + rangeStr: &invalidRange, newReaderReturn: func() (Reader, error) { return ioutil.NopCloser(strings.NewReader("someData")), nil }, res: storageTypes.NewResponse(nil, http.StatusUnprocessableEntity, ErrInvalidRange), }, { - name: "OnRangeReaderError", - ctx: context.TODO(), - path: validPath, - range_: &outOfBoundRange, + name: "OnRangeReaderError", + ctx: context.TODO(), + path: validPath, + rangeStr: &outOfBoundRange, newRangeReaderReturn: func() (Reader, error) { return nil, &googleapi.Error{Code: 400, Message: "Bad Request"} }, @@ -269,30 +269,30 @@ func (s *StorageTestSuite) TestBenchForStorage_GetPartially() { ), }, { - name: "NotFoundWithValidRangeAndInvalidPath", - ctx: context.TODO(), - path: invalidPath, - range_: &validRange, + name: "NotFoundWithValidRangeAndInvalidPath", + ctx: context.TODO(), + path: invalidPath, + rangeStr: &validRange, newRangeReaderReturn: func() (Reader, error) { return nil, storage.ErrObjectNotExist }, res: storageTypes.NewResponse([]byte(nil), http.StatusNotFound, storage.ErrObjectNotExist), }, { - name: "OnBadReaderError", - ctx: context.TODO(), - path: unreadablePath, - range_: &validRange, + name: "OnBadReaderError", + ctx: context.TODO(), + path: unreadablePath, + rangeStr: &validRange, newRangeReaderReturn: func() (Reader, error) { return &badReader{}, nil }, res: storageTypes.NewResponse(nil, http.StatusUnprocessableEntity, io.ErrUnexpectedEOF), }, { - name: "WhenObjectAttributesAreUnreadable", - ctx: context.TODO(), - path: invalidPath, - range_: &validRange, + name: "WhenObjectAttributesAreUnreadable", + ctx: context.TODO(), + path: invalidPath, + rangeStr: &validRange, newRangeReaderReturn: func() (Reader, error) { return ioutil.NopCloser(strings.NewReader("someData")), nil }, @@ -310,12 +310,12 @@ func (s *StorageTestSuite) TestBenchForStorage_GetPartially() { s.bucketHandle.On("Object", t.path).Return(mo) var opts *storageTypes.GetPartiallyRequestOptions - if t.range_ != nil { - if o, l, err := s.storage.parseRange(*t.range_); err == nil { + if t.rangeStr != nil { + if o, l, err := s.storage.parseRange(*t.rangeStr); err == nil { mo.On("NewRangeReader", t.ctx, o, l). Return(t.newRangeReaderReturn()) } - opts = &storageTypes.GetPartiallyRequestOptions{Range: *t.range_} + opts = &storageTypes.GetPartiallyRequestOptions{Range: *t.rangeStr} } if t.newReaderReturn != nil { mo.On("NewReader", t.ctx).Return(t.newReaderReturn())