Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update build pipeline #59

Merged
merged 4 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Build Project

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
Expand All @@ -9,29 +15,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.3
go-version-file: go.mod
cache-dependency-path: go.sum
cache: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
- name: Log into GHCR
if: github.event_name == 'push'
uses: magefile/mage-action@v1
uses: magefile/mage-action@v2
with:
version: latest
args: ghcr:login
env:
GHCR_PAT: ${{ secrets.GHCR_PAT }}
- name: Build image
if: github.event_name == 'pull_request'
uses: magefile/mage-action@v1
uses: magefile/mage-action@v2
with:
version: latest
args: -v docker:build
- name: Build and Push image
if: github.event_name == 'push'
Expand All @@ -47,26 +53,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.3
go-version-file: go.mod
cache-dependency-path: go.sum
cache: true
- name: Run tests
uses: magefile/mage-action@v1
uses: magefile/mage-action@v2
with:
version: latest
args: go:test
go_lint:
name: Run go lints
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.3
go-version-file: go.mod
cache-dependency-path: go.sum
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
Expand All @@ -76,7 +85,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
uses: actions/checkout@v3
- name: hadolint
uses: reviewdog/action-hadolint@v1
with:
Expand Down
18 changes: 5 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
run:
deadline: 3m
go: "1.19"
deadline: 20m

linters:
disable-all: true
enable:
- deadcode
- depguard
- dupl
- errcheck
- gochecknoinits
- exportloopref
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- maligned
- megacheck
- misspell
- nakedret
- prealloc
- scopelint
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- unused
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17.3-buster AS builder
FROM golang:1.19.0 AS builder
# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down
30 changes: 12 additions & 18 deletions cmd/gitdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,21 @@ import (
"crypto/rsa"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"time"

"github.com/cresta/gitdb/internal/gitdb"
"github.com/cresta/gitdb/internal/gitdb/goget"

"github.com/gorilla/mux"

"github.com/dgrijalva/jwt-go"

"github.com/cresta/gitdb/internal/gitdb/tracing/datadog"
"github.com/signalfx/golib/v3/httpdebug"

"github.com/cresta/gitdb/internal/gitdb/repoprovider/github"
"github.com/cresta/gitdb/internal/gitdb/tracing"
"github.com/cresta/gitdb/internal/gitdb/tracing/datadog"
"github.com/cresta/gitdb/internal/httpserver"
"github.com/cresta/gitdb/internal/log"

"github.com/cresta/gitdb/internal/gitdb/repoprovider/github"

"github.com/cresta/gitdb/internal/gitdb"
"github.com/dgrijalva/jwt-go"
"github.com/gorilla/mux"
"github.com/signalfx/golib/v3/httpdebug"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -121,7 +114,7 @@ func (m *Service) loadRepoConfig(cfg config) (RepoConfig, error) {
if cfg.RepoConfig == "" {
return RepoConfig{}, nil
}
b, err := ioutil.ReadFile(cfg.RepoConfig)
b, err := os.ReadFile(cfg.RepoConfig)
if err != nil {
return RepoConfig{}, fmt.Errorf("unable to read file %s: %w", cfg.RepoConfig, err)
}
Expand Down Expand Up @@ -256,7 +249,7 @@ func setupJWT(cfg config, m *mux.Router, h *gitdb.CheckoutHandler, logger *log.L
logger.Info(context.Background(), "skipping public JWT handler: no public key")
return nil
}
fileContent, err := ioutil.ReadFile(cfg.JWTPublicKey)
fileContent, err := os.ReadFile(cfg.JWTPublicKey)
if err != nil {
return fmt.Errorf("unable to read jwt file %s: %w", cfg.JWTPublicKey, err)
}
Expand Down Expand Up @@ -284,7 +277,7 @@ func setupJWTSigning(ctx context.Context, cfg config, log *log.Logger, m *mux.Ro
log.Info(ctx, "no private key set. Skipping JWT signing step")
return nil
}
fileContent, err := ioutil.ReadFile(cfg.JWTPrivateKey)
fileContent, err := os.ReadFile(cfg.JWTPrivateKey)
if err != nil {
return fmt.Errorf("unable to read private key file %s: %w", cfg.JWTPrivateKey, err)
}
Expand Down Expand Up @@ -332,7 +325,8 @@ func setupServer(cfg config, z *log.Logger, rootTracer tracing.Tracing, coHandle
rootMux.NotFoundHandler = httpserver.NotFoundHandler(z)
rootMux.Use(tracing.MuxTagging(rootTracer))
return &http.Server{
Handler: rootHandler,
Addr: cfg.ListenAddr,
Handler: rootHandler,
Addr: cfg.ListenAddr,
ReadHeaderTimeout: time.Second * 30,
}
}
44 changes: 36 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
module github.com/cresta/gitdb

go 1.14
go 1.19

require (
github.com/DataDog/datadog-go v4.0.0+incompatible // indirect
github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1
github.com/cresta/magehelper v0.0.30
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-git/go-git/v5 v5.1.0
github.com/google/go-cmp v0.5.2 // indirect
github.com/google/go-github/v32 v32.1.0
github.com/google/uuid v1.1.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/hashicorp/golang-lru v0.5.4
github.com/signalfx/golib/v3 v3.3.17
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.16.0
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0
)

require (
github.com/DataDog/datadog-go v4.0.0+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.0.0 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/go-cmp v0.5.2 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect
github.com/magefile/mage v1.11.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/signalfx/golib/v3 v3.3.17
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.16.0
github.com/tinylib/msgp v1.1.2 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20201013201025-64a9e34f3752 // indirect
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojt
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4 h1:fP04zlkPjAGpsduG7xN3rRkxjAqkJaIQnnkNYYw/pAk=
github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4/go.mod h1:SBHk9aNQtiw4R4bEuzHjVmZikkUKCnO1v3lPQ21HZGk=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
Expand Down Expand Up @@ -92,9 +91,7 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/errors v0.0.0-20181012004132-a4583d0a56ea h1:g2k+8WR7cHch4g0tBDhfiEvAp7fXxTNBiD1oC1Oxj3E=
github.com/juju/errors v0.0.0-20181012004132-a4583d0a56ea/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 h1:UUHMLvzt/31azWTN/ifGWef4WUqvXk0iRqdhdy/2uzI=
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b h1:Rrp0ByJXEjhREMPGTt3aWYjoIsUGCbt21ekbeJcTWv0=
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
Expand Down Expand Up @@ -253,7 +250,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
Expand Down
9 changes: 3 additions & 6 deletions internal/gitdb/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/cresta/gitdb/internal/gitdb/goget"

jwtmiddleware "github.com/auth0/go-jwt-middleware"

"github.com/cresta/gitdb/internal/gitdb/goget"
"github.com/cresta/gitdb/internal/gitdb/tracing"
"github.com/cresta/gitdb/internal/httpserver"
"github.com/cresta/gitdb/internal/log"
Expand Down Expand Up @@ -59,7 +56,7 @@ func NewHandler(logger *log.Logger, cfg Config, tracer tracing.Tracing) (*Checko
if trimmedRepoURL == "" {
return nil, fmt.Errorf("unable to find URL for repo index %d", idx)
}
cloneInto, err := ioutil.TempDir(dataDir, "gitdb_repo_"+sanitizeDir(trimmedRepoURL))
cloneInto, err := os.MkdirTemp(dataDir, "gitdb_repo_"+sanitizeDir(trimmedRepoURL))
if err != nil {
return nil, fmt.Errorf("unable to make temp dir for %s,%s: %w", dataDir, "gitdb_repo_"+sanitizeDir(trimmedRepoURL), err)
}
Expand Down Expand Up @@ -371,7 +368,7 @@ func getAuthMethod(repo Repository) (transport.AuthMethod, error) {
if pKey == "" {
return nil, nil
}
sshKey, err := ioutil.ReadFile(pKey)
sshKey, err := os.ReadFile(pKey)
if err != nil {
return nil, fmt.Errorf("unable to read file %s: %w", pKey, err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ func (f *FieldLogger) Log(keyvals ...interface{}) {
if i+1 >= len(keyvals) {
continue
}
kInt := keyvals[i]
keyInt := keyvals[i]
v := keyvals[i+1]
if kAsString, ok := kInt.(string); ok {
if kAsString == "msg" {
if keyAsString, ok := keyInt.(string); ok {
if keyAsString == "msg" {
if valAsString, ok := v.(string); ok {
msg = valAsString
}
} else {
fields = append(fields, zap.Any(kAsString, v))
fields = append(fields, zap.Any(keyAsString, v))
}
}
}
Expand Down