From ba2be3220d74aaf5e209b8139d0fbd409432eaa3 Mon Sep 17 00:00:00 2001 From: mrrishi Date: Tue, 17 Sep 2024 19:53:43 +0530 Subject: [PATCH] fix:check docker daemon running? --- cmd/akamai/create.go | 8 ++++++++ cmd/aws/create.go | 8 ++++++++ cmd/civo/create.go | 8 ++++++++ cmd/digitalocean/create.go | 8 ++++++++ cmd/google/create.go | 8 ++++++++ cmd/k3d/create.go | 8 ++++++++ cmd/k3s/create.go | 8 ++++++++ cmd/vultr/create.go | 8 ++++++++ go.mod | 8 +++++--- go.sum | 15 ++++++++++----- internal/docker/checkstatus.go | 23 +++++++++++++++++++++++ 11 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 internal/docker/checkstatus.go diff --git a/cmd/akamai/create.go b/cmd/akamai/create.go index dcf6b83f..9e525765 100644 --- a/cmd/akamai/create.go +++ b/cmd/akamai/create.go @@ -15,6 +15,7 @@ import ( pkg "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -32,6 +33,13 @@ func createAkamai(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to get flags: %w", err) } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(25) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/aws/create.go b/cmd/aws/create.go index e2e51a2b..b9df8646 100644 --- a/cmd/aws/create.go +++ b/cmd/aws/create.go @@ -17,6 +17,7 @@ import ( pkg "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -34,6 +35,13 @@ func createAws(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(40) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/civo/create.go b/cmd/civo/create.go index f1f36bef..867e1ba0 100644 --- a/cmd/civo/create.go +++ b/cmd/civo/create.go @@ -15,6 +15,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -32,6 +33,13 @@ func createCivo(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(15) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/digitalocean/create.go b/cmd/digitalocean/create.go index 9ae9e2aa..235a79cc 100644 --- a/cmd/digitalocean/create.go +++ b/cmd/digitalocean/create.go @@ -15,6 +15,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -32,6 +33,13 @@ func createDigitalocean(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(20) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/google/create.go b/cmd/google/create.go index e15651df..aaef6a02 100644 --- a/cmd/google/create.go +++ b/cmd/google/create.go @@ -15,6 +15,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -33,6 +34,13 @@ func createGoogle(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(20) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index 32db2f99..71d7daba 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -43,6 +43,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst-api/pkg/wrappers" "github.com/konstructio/kubefirst/internal/catalog" + docker "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/progress" "github.com/konstructio/kubefirst/internal/segment" @@ -132,6 +133,13 @@ func runK3d(cmd *cobra.Command, args []string) error { return err } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + switch gitProviderFlag { case "github": key, err := internalssh.GetHostKey("github.com") diff --git a/cmd/k3s/create.go b/cmd/k3s/create.go index a76dd5be..72fa9578 100644 --- a/cmd/k3s/create.go +++ b/cmd/k3s/create.go @@ -17,6 +17,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -35,6 +36,13 @@ func createK3s(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(20) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/cmd/vultr/create.go b/cmd/vultr/create.go index 9cd91113..bd91c9ce 100644 --- a/cmd/vultr/create.go +++ b/cmd/vultr/create.go @@ -15,6 +15,7 @@ import ( utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/internal/catalog" "github.com/konstructio/kubefirst/internal/cluster" + "github.com/konstructio/kubefirst/internal/docker" "github.com/konstructio/kubefirst/internal/gitShim" "github.com/konstructio/kubefirst/internal/launch" "github.com/konstructio/kubefirst/internal/progress" @@ -33,6 +34,13 @@ func createVultr(cmd *cobra.Command, args []string) error { return nil } + log.Info().Msg("Check Docker status") + err = docker.Checkstatus() + if err != nil { + log.Info().Msgf("%s", err) + return err + } + progress.DisplayLogHints(15) isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps) diff --git a/go.mod b/go.mod index 93edad7b..d589c9a6 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/charmbracelet/bubbles v0.16.1 github.com/charmbracelet/bubbletea v0.24.2 github.com/charmbracelet/lipgloss v0.10.0 - github.com/charmbracelet/log v0.4.0 github.com/civo/civogo v0.3.53 github.com/denisbrodbeck/machineid v1.0.1 github.com/dustin/go-humanize v1.0.1 @@ -87,6 +86,8 @@ require ( github.com/digitalocean/godo v1.98.0 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-units v0.4.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect @@ -95,7 +96,6 @@ require ( github.com/fvbommel/sortorder v1.0.2 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-errors/errors v1.4.2 // indirect - github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/go-openapi/jsonpointer v0.20.0 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.4 // indirect @@ -143,6 +143,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect github.com/otiai10/copy v1.7.0 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect @@ -159,6 +160,7 @@ require ( github.com/segmentio/analytics-go v3.1.0+incompatible // indirect github.com/segmentio/backo-go v1.0.1 // indirect github.com/skeema/knownhosts v1.1.0 // indirect + github.com/stretchr/testify v1.9.0 // indirect github.com/thanhpk/randstr v1.0.6 // indirect github.com/vmihailenco/go-tinylfu v0.2.1 // indirect github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect @@ -216,6 +218,7 @@ require ( github.com/charmbracelet/glamour v0.6.0 github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/docker v27.2.1+incompatible github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.13.0 github.com/fsnotify/fsnotify v1.6.0 // indirect @@ -334,4 +337,3 @@ replace ( k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.24.2 k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.2 ) - diff --git a/go.sum b/go.sum index b2ac8fab..80b30f6f 100644 --- a/go.sum +++ b/go.sum @@ -255,8 +255,6 @@ github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM2 github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= -github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= -github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -343,8 +341,11 @@ github.com/docker/distribution v2.8.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4Kfc github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v20.10.17+incompatible h1:JYCuMrWaVNophQTOrMMoSwudOVEfcegoZZrleKc1xwE= github.com/docker/docker v20.10.17+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -433,8 +434,6 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= -github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= @@ -847,6 +846,7 @@ github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb/go.mod h1:TaXosZuwd github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= @@ -924,6 +924,8 @@ github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWEr github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 h1:rc3tiVYb5z54aKaDfakKn0dDjIyPpTtszkjuMzyt7ec= +github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v1.1.0/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc= github.com/opencontainers/runc v1.1.1/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= @@ -1106,8 +1108,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -1825,6 +1828,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/docker/checkstatus.go b/internal/docker/checkstatus.go new file mode 100644 index 00000000..4f411514 --- /dev/null +++ b/internal/docker/checkstatus.go @@ -0,0 +1,23 @@ +package docker + +import ( + "context" + "fmt" + + "github.com/docker/docker/client" +) + +func Checkstatus() error { + + cli, err := client.NewClientWithOpts(client.FromEnv) + if err != nil { + return fmt.Errorf("Docker is not installed or not accessible: %w", err) + } + + _, err = cli.Ping(context.Background()) + if err != nil { + return fmt.Errorf("Docker is not accessible: %v", err) + } + + return nil +}