Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.DS_Store
/build
dist/
abctl
13 changes: 12 additions & 1 deletion internal/cmd/local/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/airbytehq/abctl/internal/cmd/local/docker"
"github.com/airbytehq/abctl/internal/cmd/local/k8s"
"github.com/airbytehq/abctl/internal/cmd/local/localerr"
"github.com/airbytehq/abctl/internal/telemetry"
"github.com/pterm/pterm"
)

Expand All @@ -23,7 +24,7 @@ var dockerClient *docker.Docker
// dockerInstalled checks if docker is installed on the host machine.
// Returns a nil error if docker was successfully detected, otherwise an error will be returned. Any error returned
// is guaranteed to include the ErrDocker error in the error chain.
func dockerInstalled(ctx context.Context) (docker.Version, error) {
func dockerInstalled(ctx context.Context, telClient telemetry.Client) (docker.Version, error) {
var err error
if dockerClient == nil {
if dockerClient, err = docker.New(ctx); err != nil {
Expand All @@ -37,6 +38,16 @@ func dockerInstalled(ctx context.Context) (docker.Version, error) {
pterm.Error.Println("Unable to communicate with the Docker daemon")
return docker.Version{}, fmt.Errorf("%w: %w", localerr.ErrDocker, err)
}

telClient.Attr("docker_version", version.Version)
telClient.Attr("docker_arch", version.Arch)
telClient.Attr("docker_platform", version.Platform)

if info, err := dockerClient.Client.Info(ctx); err == nil {
telClient.Attr("docker_ncpu", fmt.Sprintf("%d", info.NCPU))
telClient.Attr("docker_memtotal", fmt.Sprintf("%d", info.MemTotal))
}

pterm.Success.Println(fmt.Sprintf("Found Docker installation: version %s", version.Version))
return version, nil

Expand Down
12 changes: 10 additions & 2 deletions internal/cmd/local/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/airbytehq/abctl/internal/cmd/local/localerr"
"github.com/airbytehq/abctl/internal/telemetry"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
)
Expand All @@ -31,10 +32,17 @@ func TestDockerInstalled(t *testing.T) {
Arch: "arch",
}, nil
},
FnInfo: func(ctx context.Context) (system.Info, error) {
return system.Info{}, nil
},
},
}

version, err := dockerInstalled(context.Background())
tel := mockTelemetryClient{
attr: func(key, val string) {},
}

version, err := dockerInstalled(context.Background(), &tel)
if err != nil {
t.Error("unexpected error:", err)
}
Expand Down Expand Up @@ -63,7 +71,7 @@ func TestDockerInstalled_Error(t *testing.T) {
},
}

_, err := dockerInstalled(context.Background())
_, err := dockerInstalled(context.Background(), &mockTelemetryClient{})
if err == nil {
t.Error("unexpected error:", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/local/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -47,6 +48,7 @@ type Client interface {

ServerVersion(ctx context.Context) (types.Version, error)
VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)
Info(ctx context.Context) (system.Info, error)
}

var _ Client = (*client.Client)(nil)
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/local/docker/dockertest/dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/volume"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
Expand All @@ -26,6 +27,7 @@ type MockClient struct {
FnImagePull func(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
FnServerVersion func(ctx context.Context) (types.Version, error)
FnVolumeInspect func(ctx context.Context, volumeID string) (volume.Volume, error)
FnInfo func(ctx context.Context) (system.Info, error)
}

func (m MockClient) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error) {
Expand Down Expand Up @@ -79,3 +81,7 @@ func (m MockClient) ServerVersion(ctx context.Context) (types.Version, error) {
func (m MockClient) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) {
return m.FnVolumeInspect(ctx, volumeID)
}

func (m MockClient) Info(ctx context.Context) (system.Info, error) {
return m.FnInfo(ctx)
}
6 changes: 1 addition & 5 deletions internal/cmd/local/local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t
spinner, _ = spinner.Start("Starting installation")
spinner.UpdateText("Checking for Docker installation")

dockerVersion, err := dockerInstalled(ctx)
_, err := dockerInstalled(ctx, telClient)
if err != nil {
pterm.Error.Println("Unable to determine if Docker is installed")
return fmt.Errorf("unable to determine docker installation status: %w", err)
}

telClient.Attr("docker_version", dockerVersion.Version)
telClient.Attr("docker_arch", dockerVersion.Arch)
telClient.Attr("docker_platform", dockerVersion.Platform)

spinner.UpdateText(fmt.Sprintf("Checking if port %d is available", i.Port))
if err := portAvailable(ctx, i.Port); err != nil {
return fmt.Errorf("port %d is not available: %w", i.Port, err)
Expand Down
6 changes: 1 addition & 5 deletions internal/cmd/local/local_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ func checkDocker(ctx context.Context, telClient telemetry.Client, spinner *pterm
spinner, _ = spinner.Start("Starting status check")
spinner.UpdateText("Checking for Docker installation")

dockerVersion, err := dockerInstalled(ctx)
_, err := dockerInstalled(ctx, telClient)
if err != nil {
pterm.Error.Println("Unable to determine if Docker is installed")
return fmt.Errorf("unable to determine docker installation status: %w", err)
}

telClient.Attr("docker_version", dockerVersion.Version)
telClient.Attr("docker_arch", dockerVersion.Arch)
telClient.Attr("docker_platform", dockerVersion.Platform)

return nil
}

Expand Down
6 changes: 1 addition & 5 deletions internal/cmd/local/local_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ func (u *UninstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient
spinner, _ = spinner.Start("Starting uninstallation")
spinner.UpdateText("Checking for Docker installation")

dockerVersion, err := dockerInstalled(ctx)
_, err := dockerInstalled(ctx, telClient)
if err != nil {
pterm.Error.Println("Unable to determine if Docker is installed")
return fmt.Errorf("unable to determine docker installation status: %w", err)
}

telClient.Attr("docker_version", dockerVersion.Version)
telClient.Attr("docker_arch", dockerVersion.Arch)
telClient.Attr("docker_platform", dockerVersion.Platform)

return telClient.Wrap(ctx, telemetry.Uninstall, func() error {
spinner.UpdateText(fmt.Sprintf("Checking for existing Kubernetes cluster '%s'", provider.ClusterName))

Expand Down