From 255bd741ced41140747a543514e25353c8a881bc Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 5 Dec 2024 09:45:57 +0100 Subject: [PATCH 1/5] refactor: remove moby dependency --- go.mod | 8 +- go.sum | 14 ---- ignite/pkg/archive/tar_gz.go | 111 ++++++++++++++++++++++++++++ ignite/services/chain/build.go | 12 +-- ignite/services/chain/chain_test.go | 5 +- 5 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 ignite/pkg/archive/tar_gz.go diff --git a/go.mod b/go.mod index 0f1f160082..63d5810471 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,6 @@ require ( github.com/lib/pq v1.10.9 github.com/manifoldco/promptui v0.9.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/moby/moby v26.1.0+incompatible github.com/muesli/reflow v0.3.0 github.com/nqd/flat v0.2.0 github.com/otiai10/copy v1.14.0 @@ -185,8 +184,6 @@ require ( github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft-db v1.0.1 // indirect - github.com/containerd/containerd v1.7.11 // indirect - github.com/containerd/log v0.1.0 // indirect github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect github.com/cosiner/argv v0.1.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect @@ -297,6 +294,7 @@ require ( github.com/gostaticanalysis/nilerr v0.1.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-metrics v0.5.3 // indirect @@ -356,9 +354,6 @@ require ( github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect - github.com/moby/patternmatcher v0.6.0 // indirect - github.com/moby/sys/sequential v0.5.0 // indirect - github.com/moby/sys/user v0.1.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/moricho/tparallel v0.3.2 // indirect github.com/morikuni/aec v1.0.0 // indirect @@ -466,6 +461,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect go.opentelemetry.io/otel v1.26.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect go.opentelemetry.io/otel/metric v1.26.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.26.0 // indirect diff --git a/go.sum b/go.sum index f8eed5548c..9cde1f21fb 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,6 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMb github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/Abirdcfly/dupword v0.0.14 h1:3U4ulkc8EUo+CaT105/GJ1BQwtgyj6+VaBVbAX11Ba8= github.com/Abirdcfly/dupword v0.0.14/go.mod h1:VKDAbxdY8YbKUByLGg8EETzYSuC4crm9WwI6Y3S0cLI= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/Antonboom/errname v0.1.13 h1:JHICqsewj/fNckzrfVSe+T33svwQxmjC+1ntDsHOVvM= @@ -100,8 +98,6 @@ github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lpr github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= -github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -296,8 +292,6 @@ github.com/cometbft/cometbft-db v1.0.1/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5E github.com/cometbft/cometbft/api v1.0.0-rc.1 h1:GtdXwDGlqwHYs16A4egjwylfYOMYyEacLBrs3Zvpt7g= github.com/cometbft/cometbft/api v1.0.0-rc.1/go.mod h1:NDFKiBBD8HJC6QQLAoUI99YhsiRZtg2+FJWfk6A6m6o= github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= -github.com/containerd/containerd v1.7.11 h1:lfGKw3eU35sjV0aG2eYZTiwFEY1pCzxdzicHP3SZILw= -github.com/containerd/containerd v1.7.11/go.mod h1:5UluHxHTX2rdvYuZ5OJTC5m/KJNs0Zs9wVoJm9zf5ZE= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containerd/stargz-snapshotter/estargz v0.15.1 h1:eXJjw9RbkLFgioVaTG+G/ZW/0kEe2oEKCdS/ZxIyoCU= @@ -954,14 +948,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= -github.com/moby/moby v26.1.0+incompatible h1:mjepCwMH0KpCgPvrXjqqyCeTCHgzO7p9TwZ2nQMI2qU= -github.com/moby/moby v26.1.0+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc= -github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= -github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= -github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= -github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= -github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= -github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/ignite/pkg/archive/tar_gz.go b/ignite/pkg/archive/tar_gz.go new file mode 100644 index 0000000000..94144e49bd --- /dev/null +++ b/ignite/pkg/archive/tar_gz.go @@ -0,0 +1,111 @@ +package archive + +import ( + "archive/tar" + "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" +) + +// CreateArchive creates a tar.gz archive from a list of files. +func CreateArchive(dir string, buf io.Writer) error { + // Create new Writers for gzip and tar + // These writers are chained. Writing to the tar writer will + // write to the gzip writer which in turn will write to + // the "buf" writer + gw := gzip.NewWriter(buf) + defer gw.Close() + tw := tar.NewWriter(gw) + defer tw.Close() + + // Iterate over files from directory and add them to the tar archive + filepath.WalkDir(dir, func(path string, info os.DirEntry, err error) error { + return addToArchive(tw, path) + }) + + return nil +} + +func addToArchive(tw *tar.Writer, filename string) error { + // Open the file which will be written into the archive + file, err := os.Open(filename) + if err != nil { + return err + } + defer file.Close() + + // Get FileInfo about our file providing file size, mode, etc. + info, err := file.Stat() + if err != nil { + return err + } + + // Create a tar Header from the FileInfo data + header, err := tar.FileInfoHeader(info, info.Name()) + if err != nil { + return err + } + + // Use full path as name (FileInfoHeader only takes the basename) + // If we don't do this the directory strucuture would + // not be preserved + // https://golang.org/src/archive/tar/common.go?#L626 + header.Name = filename + + // Write file header to the tar archive + err = tw.WriteHeader(header) + if err != nil { + return err + } + + _, err = io.Copy(tw, file) + if err != nil { + return err + } + + return nil +} + +// ExtractArchive extracts a tar.gz archive to the specified directory. +func ExtractArchive(outDir string, gzipStream io.Reader) error { + uncompressedStream, err := gzip.NewReader(gzipStream) + if err != nil { + return err + } + + tarReader := tar.NewReader(uncompressedStream) + + for { + header, err := tarReader.Next() + if err == io.EOF { + break + } else if err != nil { + return err + } + + targetPath := filepath.Join(outDir, header.Name) + + switch header.Typeflag { + case tar.TypeDir: + if err := os.MkdirAll(targetPath, 0755); err != nil { + return err + } + case tar.TypeReg: + outFile, err := os.Create(targetPath) + if err != nil { + return err + } + if _, err := io.Copy(outFile, tarReader); err != nil { + return err + } + outFile.Close() + + default: + return fmt.Errorf("unknown type: %s in %s", string(header.Typeflag), header.Name) + } + } + + return nil +} diff --git a/ignite/services/chain/build.go b/ignite/services/chain/build.go index 97848d9e19..3cc286e69d 100644 --- a/ignite/services/chain/build.go +++ b/ignite/services/chain/build.go @@ -3,14 +3,12 @@ package chain import ( "context" "fmt" - "io" "os" "path/filepath" "runtime" "strings" - "github.com/moby/moby/pkg/archive" - + "github.com/ignite/cli/v29/ignite/pkg/archive" "github.com/ignite/cli/v29/ignite/pkg/cache" "github.com/ignite/cli/v29/ignite/pkg/checksum" "github.com/ignite/cli/v29/ignite/pkg/cmdrunner" @@ -181,11 +179,6 @@ func (c *Chain) BuildRelease( return "", err } - tarr, err := archive.Tar(out, archive.Gzip) - if err != nil { - return "", err - } - tarName := fmt.Sprintf("%s_%s_%s.tar.gz", prefix, goos, goarch) tarPath := filepath.Join(releasePath, tarName) @@ -195,10 +188,9 @@ func (c *Chain) BuildRelease( } defer tarf.Close() - if _, err := io.Copy(tarf, tarr); err != nil { + if err := archive.CreateArchive(out, tarf); err != nil { return "", err } - tarf.Close() } checksumPath := filepath.Join(releasePath, releaseChecksumKey) diff --git a/ignite/services/chain/chain_test.go b/ignite/services/chain/chain_test.go index a62c627e48..4583522ff9 100644 --- a/ignite/services/chain/chain_test.go +++ b/ignite/services/chain/chain_test.go @@ -5,9 +5,10 @@ import ( "path/filepath" "testing" - "github.com/moby/moby/pkg/archive" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/ignite/cli/v29/ignite/pkg/archive" ) func TestSourceVersion(t *testing.T) { @@ -38,7 +39,7 @@ func tempSource(t *testing.T, tarPath string) (path string) { dir := t.TempDir() - require.NoError(t, archive.Untar(f, dir, &archive.TarOptions{NoLchown: true})) + require.NoError(t, archive.ExtractArchive(dir, f)) dirs, err := os.ReadDir(dir) require.NoError(t, err) From c0bc9fe78238a54a27d88c06f348d1c13beff3e4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 5 Dec 2024 09:57:40 +0100 Subject: [PATCH 2/5] updates --- go.mod | 2 +- ignite/pkg/cosmosfaucet/http.go | 49 +++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 63d5810471..623cc81291 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,6 @@ require ( github.com/golangci/golangci-lint v1.60.3 github.com/google/go-github/v48 v48.2.0 github.com/google/go-querystring v1.1.0 - github.com/gorilla/mux v1.8.1 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.2 github.com/iancoleman/strcase v0.3.0 @@ -287,6 +286,7 @@ require ( github.com/gordonklaus/ineffassign v0.1.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.4.2 // indirect diff --git a/ignite/pkg/cosmosfaucet/http.go b/ignite/pkg/cosmosfaucet/http.go index 8db36f3566..262161c576 100644 --- a/ignite/pkg/cosmosfaucet/http.go +++ b/ignite/pkg/cosmosfaucet/http.go @@ -3,7 +3,6 @@ package cosmosfaucet import ( "net/http" - "github.com/gorilla/mux" "github.com/rs/cors" "github.com/ignite/cli/v29/ignite/pkg/openapiconsole" @@ -12,23 +11,33 @@ import ( // ServeHTTP implements http.Handler to expose the functionality of Faucet.Transfer() via HTTP. // request/response payloads are compatible with the previous implementation at allinbits/cosmos-faucet. func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) { - router := mux.NewRouter() - - router. - Handle("/", cors.Default().Handler(http.HandlerFunc(f.faucetHandler))). - Methods(http.MethodPost, http.MethodOptions) - - router. - Handle("/info", cors.Default().Handler(http.HandlerFunc(f.faucetInfoHandler))). - Methods(http.MethodGet, http.MethodOptions) - - router. - HandleFunc("/", openapiconsole.Handler("Faucet", "openapi.yml")). - Methods(http.MethodGet) - - router. - HandleFunc("/openapi.yml", f.openAPISpecHandler). - Methods(http.MethodGet) - - router.ServeHTTP(w, r) + mux := http.NewServeMux() + + mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost || r.Method == http.MethodOptions { + f.faucetHandler(w, r) + } else if r.Method == http.MethodGet { + openapiconsole.Handler("Faucet", "openapi.yml")(w, r) + } else { + http.NotFound(w, r) + } + }))) + + mux.Handle("/info", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet || r.Method == http.MethodOptions { + f.faucetInfoHandler(w, r) + } else { + http.NotFound(w, r) + } + }))) + + mux.HandleFunc("/openapi.yml", func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet { + f.openAPISpecHandler(w, r) + } else { + http.NotFound(w, r) + } + }) + + mux.ServeHTTP(w, r) } From 0f7c46e6b8cbef062e79d7b619d812734d944322 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 6 Dec 2024 10:39:43 +0100 Subject: [PATCH 3/5] linting --- ignite/pkg/archive/tar_gz.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/archive/tar_gz.go b/ignite/pkg/archive/tar_gz.go index 94144e49bd..273bf039af 100644 --- a/ignite/pkg/archive/tar_gz.go +++ b/ignite/pkg/archive/tar_gz.go @@ -89,7 +89,7 @@ func ExtractArchive(outDir string, gzipStream io.Reader) error { switch header.Typeflag { case tar.TypeDir: - if err := os.MkdirAll(targetPath, 0755); err != nil { + if err := os.MkdirAll(targetPath, 0o755); err != nil { return err } case tar.TypeReg: From 9d1101d37e51b058e0764568f953ac36616a10a9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 6 Dec 2024 20:40:09 +0100 Subject: [PATCH 4/5] updates --- ignite/pkg/archive/tar_gz.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ignite/pkg/archive/tar_gz.go b/ignite/pkg/archive/tar_gz.go index 273bf039af..38ec3fbd90 100644 --- a/ignite/pkg/archive/tar_gz.go +++ b/ignite/pkg/archive/tar_gz.go @@ -20,12 +20,9 @@ func CreateArchive(dir string, buf io.Writer) error { tw := tar.NewWriter(gw) defer tw.Close() - // Iterate over files from directory and add them to the tar archive - filepath.WalkDir(dir, func(path string, info os.DirEntry, err error) error { + return filepath.WalkDir(dir, func(path string, info os.DirEntry, err error) error { return addToArchive(tw, path) }) - - return nil } func addToArchive(tw *tar.Writer, filename string) error { From 1cec995edf1222292acb43eaea966a9e2f17c864 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 6 Dec 2024 20:57:02 +0100 Subject: [PATCH 5/5] updates --- ignite/pkg/archive/tar_gz.go | 11 ++++++----- ignite/pkg/cosmosfaucet/http.go | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ignite/pkg/archive/tar_gz.go b/ignite/pkg/archive/tar_gz.go index 38ec3fbd90..c4500d86f5 100644 --- a/ignite/pkg/archive/tar_gz.go +++ b/ignite/pkg/archive/tar_gz.go @@ -3,10 +3,11 @@ package archive import ( "archive/tar" "compress/gzip" - "fmt" "io" "os" "path/filepath" + + "github.com/ignite/cli/v29/ignite/pkg/errors" ) // CreateArchive creates a tar.gz archive from a list of files. @@ -20,7 +21,7 @@ func CreateArchive(dir string, buf io.Writer) error { tw := tar.NewWriter(gw) defer tw.Close() - return filepath.WalkDir(dir, func(path string, info os.DirEntry, err error) error { + return filepath.WalkDir(dir, func(path string, _ os.DirEntry, _ error) error { return addToArchive(tw, path) }) } @@ -82,7 +83,7 @@ func ExtractArchive(outDir string, gzipStream io.Reader) error { return err } - targetPath := filepath.Join(outDir, header.Name) + targetPath := filepath.Join(outDir, header.Name) //nolint:gosec // We trust the tar file switch header.Typeflag { case tar.TypeDir: @@ -94,13 +95,13 @@ func ExtractArchive(outDir string, gzipStream io.Reader) error { if err != nil { return err } - if _, err := io.Copy(outFile, tarReader); err != nil { + if _, err := io.Copy(outFile, tarReader); err != nil { //nolint:gosec // We trust the tar file return err } outFile.Close() default: - return fmt.Errorf("unknown type: %s in %s", string(header.Typeflag), header.Name) + return errors.Errorf("unknown type: %s in %s", string(header.Typeflag), header.Name) } } diff --git a/ignite/pkg/cosmosfaucet/http.go b/ignite/pkg/cosmosfaucet/http.go index 262161c576..a14a313b34 100644 --- a/ignite/pkg/cosmosfaucet/http.go +++ b/ignite/pkg/cosmosfaucet/http.go @@ -14,11 +14,12 @@ func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) { mux := http.NewServeMux() mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method == http.MethodPost || r.Method == http.MethodOptions { + switch { + case r.Method == http.MethodPost || r.Method == http.MethodOptions: f.faucetHandler(w, r) - } else if r.Method == http.MethodGet { + case r.Method == http.MethodGet: openapiconsole.Handler("Faucet", "openapi.yml")(w, r) - } else { + default: http.NotFound(w, r) } })))