Skip to content

Commit

Permalink
Merge pull request #234 from depot/perf/gzip
Browse files Browse the repository at this point in the history
perf: use gzip to compress transfer of context
  • Loading branch information
goller authored Dec 20, 2023
2 parents eaee433 + 8d4081c commit 53a7b1c
Show file tree
Hide file tree
Showing 27 changed files with 453 additions and 223 deletions.
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ managed:
- buf.build/googleapis/googleapis
- buf.build/depot/buildkit
plugins:
- plugin: buf.build/protocolbuffers/go:v1.30.0
- plugin: buf.build/protocolbuffers/go:v1.31.0
out: pkg/proto
opt: paths=source_relative
- plugin: buf.build/bufbuild/connect-go:v1.7.0
- plugin: buf.build/connectrpc/go:v1.11.1
out: pkg/proto
opt: paths=source_relative
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/depot/cli
go 1.20

require (
connectrpc.com/connect v1.13.0
github.com/adrg/xdg v0.4.0
github.com/briandowns/spinner v1.18.1
github.com/bufbuild/connect-go v1.7.0
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.7.1
Expand Down Expand Up @@ -187,7 +187,7 @@ require (
)

replace (
github.com/moby/buildkit => github.com/depot/buildkit v0.11.6-depot.14
github.com/moby/buildkit => github.com/depot/buildkit v0.11.6-depot.34
k8s.io/api => k8s.io/api v0.22.4
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4
k8s.io/client-go => k8s.io/client-go v0.22.4
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
connectrpc.com/connect v1.13.0 h1:lGs5maZZzWOOD+PFFiOt5OncKmMsk9ZdPwpy5jcmaYg=
connectrpc.com/connect v1.13.0/go.mod h1:uHAFHtYgeSZJxXrkN1IunDpKghnTXhYbVh0wW4StPW0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
Expand Down Expand Up @@ -112,8 +114,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY=
github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
github.com/bufbuild/connect-go v1.7.0 h1:MGp82v7SCza+3RhsVhV7aMikwxvI3ZfD72YiGt8FYJo=
github.com/bufbuild/connect-go v1.7.0/go.mod h1:GmMJYR6orFqD0Y6ZgX8pwQ8j9baizDrIQMm1/a6LnHk=
github.com/bugsnag/bugsnag-go v1.4.1 h1:TT3P9AX69w8mbSGE8L7IJOO2KBlPN0iQtYD0dUlrWHc=
github.com/bugsnag/panicwrap v1.2.0 h1:OzrKrRvXis8qEvOkfcxNcYbOd2O7xXS2nnKMEMABFQA=
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
Expand Down Expand Up @@ -170,8 +170,8 @@ github.com/creack/pty v1.1.12/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/depot/buildkit v0.11.6-depot.14 h1:eOMKiInDcQzG9e8GGIiO8gLQ2u8SarjEIgYGmymDZK8=
github.com/depot/buildkit v0.11.6-depot.14/go.mod h1:pOJLLsXimiQGXOqPXmTS47ikf9G3ZnmuGkmhXI0qWMw=
github.com/depot/buildkit v0.11.6-depot.34 h1:d/bYRb2nYGgHmwavx0AUUORKsxP5LH7sgelj6oQ3hwM=
github.com/depot/buildkit v0.11.6-depot.34/go.mod h1:xAR2fCjg3pATE/K5/+TYmxFCrhIdsJ0NtXgNCZKtcjA=
github.com/distribution/distribution/v3 v3.0.0-20220725133111-4bf3547399eb h1:oCCuuU3kMO3sjZH/p7LamvQNW9SWoT4yQuMGcdSxGAE=
github.com/distribution/distribution/v3 v3.0.0-20220725133111-4bf3547399eb/go.mod h1:28YO/VJk9/64+sTGNuYaBjWxrXTPrj0C0XmgTIOjxX4=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"connectrpc.com/connect"
"github.com/briandowns/spinner"
"github.com/bufbuild/connect-go"
cliv1beta1 "github.com/depot/cli/pkg/proto/depot/cli/v1beta1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"runtime"
"sync"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/depot/cli/internal/build"
"github.com/depot/cli/pkg/ci"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"os"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/depot/cli/pkg/proto/depot/cli/v1/cliv1connect"
"github.com/depot/cli/pkg/proto/depot/cli/v1beta1/cliv1beta1connect"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"strings"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
depotapi "github.com/depot/cli/pkg/api"
"github.com/depot/cli/pkg/progress"
cliv1 "github.com/depot/cli/pkg/proto/depot/cli/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cache/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"path/filepath"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/depot/cli/pkg/api"
"github.com/depot/cli/pkg/helpers"
cliv1beta1 "github.com/depot/cli/pkg/proto/depot/cli/v1beta1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/list/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"sync"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/containerd/console"
"github.com/depot/cli/pkg/api"
depotapi "github.com/depot/cli/pkg/api"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/push/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"sync"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/reference"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/depot/cli/pkg/api"
depotapi "github.com/depot/cli/pkg/api"
"github.com/depot/cli/pkg/ci"
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"os"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
depotbuild "github.com/depot/cli/pkg/build"
"github.com/depot/cli/pkg/profiler"
cliv1 "github.com/depot/cli/pkg/proto/depot/cli/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/buildlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down
13 changes: 12 additions & 1 deletion pkg/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"strings"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
"github.com/depot/cli/pkg/api"
cliv1 "github.com/depot/cli/pkg/proto/depot/cli/v1"
"github.com/depot/cli/pkg/proto/depot/cli/v1/cliv1connect"
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip"
)

type Machine struct {
Expand All @@ -29,6 +31,7 @@ type Machine struct {
Key string

client *client.Client
useGzip bool
reportHealthDone chan struct{}
}

Expand Down Expand Up @@ -83,6 +86,9 @@ func Acquire(ctx context.Context, buildID, token, platform string) (*Machine, er
m.CACert = connection.Active.CaCert.Cert
m.Cert = connection.Active.Cert.Cert
m.Key = connection.Active.Cert.Key
if connection.Active.Compressor != nil {
m.useGzip = connection.Active.GetGzip() != nil
}
return m, nil
case *cliv1.GetBuildKitConnectionResponse_Pending:
select {
Expand Down Expand Up @@ -191,6 +197,11 @@ func (m *Machine) Client(ctx context.Context) (*client.Client, error) {
opts = append(opts, client.WithCredentials("", caCert, cert, key))
}

if m.useGzip {
useGzip := grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name))
opts = append(opts, useGzip)
}

c, err := client.New(ctx, m.Addr, opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
depotapi "github.com/depot/cli/pkg/api"
cliv1 "github.com/depot/cli/pkg/proto/depot/cli/v1"
cliv1connect "github.com/depot/cli/pkg/proto/depot/cli/v1/cliv1connect"
Expand Down
2 changes: 1 addition & 1 deletion pkg/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/bufbuild/connect-go"
"connectrpc.com/connect"
cliv1 "github.com/depot/cli/pkg/proto/depot/cli/v1"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client"
Expand Down
Loading

0 comments on commit 53a7b1c

Please sign in to comment.