From b362d646c07c2b24877a9e2629722067e7ea83ea Mon Sep 17 00:00:00 2001 From: fabiankramm Date: Mon, 17 Sep 2018 17:11:28 +0200 Subject: [PATCH 1/2] Improve error handling in up command --- cmd/up.go | 94 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/cmd/up.go b/cmd/up.go index 2cec7d8e98..df8ff4d858 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -301,12 +301,11 @@ func (cmd *UpCmd) buildImages(buildFlagChanged bool) bool { if randErr != nil { log.Fatalf("Image building failed: %s", randErr.Error()) } - registryConf, registryErr := registry.GetRegistryConfig(imageConf) - - if registryErr != nil { - log.Fatal(registryErr) + registryConf, err := registry.GetRegistryConfig(imageConf) + if err != nil { + log.Fatal(err) } - var buildErr error + var imageBuilder builder.Interface buildInfo := "Building image '%s' with engine '%s'" @@ -332,7 +331,10 @@ func (cmd *UpCmd) buildImages(buildFlagChanged bool) bool { if registryConf.Insecure != nil { allowInsecurePush = *registryConf.Insecure } - imageBuilder, buildErr = kaniko.NewBuilder(registryURL, *imageConf.Name, imageTag, buildNamespace, cmd.kubectl, allowInsecurePush) + imageBuilder, err = kaniko.NewBuilder(registryURL, *imageConf.Name, imageTag, buildNamespace, cmd.kubectl, allowInsecurePush) + if err != nil { + log.Fatalf("Error creating kaniko builder: %v", err) + } } else { engineName = "docker" preferMinikube := true @@ -340,62 +342,66 @@ func (cmd *UpCmd) buildImages(buildFlagChanged bool) bool { if imageConf.Build.Engine.Docker.PreferMinikube != nil { preferMinikube = *imageConf.Build.Engine.Docker.PreferMinikube } - imageBuilder, buildErr = docker.NewBuilder(registryURL, *imageConf.Name, imageTag, preferMinikube) + + imageBuilder, err = docker.NewBuilder(registryURL, *imageConf.Name, imageTag, preferMinikube) + if err != nil { + log.Fatalf("Error creating docker client: %v", err) + } } + log.Infof(buildInfo, imageName, engineName) - if buildErr == nil { - username := "" - password := "" - registryURL := "" + username := "" + password := "" - if registryConf.URL != nil { - registryURL = *registryConf.URL + if registryConf.URL != nil { + registryURL = *registryConf.URL + } + if registryConf.Auth != nil { + if registryConf.Auth.Username != nil { + username = *registryConf.Auth.Username } - if registryConf.Auth != nil { - if registryConf.Auth.Username != nil { - username = *registryConf.Auth.Username - } - if registryConf.Auth.Password != nil { - password = *registryConf.Auth.Password - } + if registryConf.Auth.Password != nil { + password = *registryConf.Auth.Password } - log.StartWait("Authenticating (" + registryURL + ")") - _, buildErr = imageBuilder.Authenticate(username, password, len(username) == 0) - log.StopWait() - - if buildErr == nil { - log.Done("Authentication successful (" + registryURL + ")") - buildOptions := &types.ImageBuildOptions{} - - if imageConf.Build.Options != nil { - if imageConf.Build.Options.BuildArgs != nil { - buildOptions.BuildArgs = *imageConf.Build.Options.BuildArgs - } - } - buildErr = imageBuilder.BuildImage(contextPath, dockerfilePath, buildOptions) + } - if buildErr == nil { - buildErr = imageBuilder.PushImage() + log.StartWait("Authenticating (" + registryURL + ")") + _, err = imageBuilder.Authenticate(username, password, len(username) == 0) + log.StopWait() - if buildErr == nil { - log.Info("Image pushed to registry (" + registryURL + ")") - } - } + if err != nil { + log.Fatalf("Error during image registry authentication: %v", err) + } + + log.Done("Authentication successful (" + registryURL + ")") + + buildOptions := &types.ImageBuildOptions{} + if imageConf.Build.Options != nil { + if imageConf.Build.Options.BuildArgs != nil { + buildOptions.BuildArgs = *imageConf.Build.Options.BuildArgs } } - if buildErr != nil { - log.Fatalf("Image building failed: %s", buildErr.Error()) + err = imageBuilder.BuildImage(contextPath, dockerfilePath, buildOptions) + if err != nil { + log.Fatalf("Error during image build: %v", err) } - imageConf.Tag = &imageTag - err := configutil.SaveConfig() + err = imageBuilder.PushImage() + if err != nil { + log.Fatalf("Error during image push: %v", err) + } + log.Info("Image pushed to registry (" + registryURL + ")") + imageConf.Tag = &imageTag + + err = configutil.SaveConfig() if err != nil { log.Fatalf("Config saving error: %s", err.Error()) } + log.Done("Done building and pushing image '" + imageName + "'") } else { log.Infof("Skip building image '%s'", imageName) From b6ff7ffc5d20bbd8b9cb699b0ba70f158e5fc653 Mon Sep 17 00:00:00 2001 From: fabiankramm Date: Mon, 17 Sep 2018 17:20:41 +0200 Subject: [PATCH 2/2] Resolve linux issue with docker daemon --- Gopkg.lock | 16 ++++++++-------- Gopkg.toml | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c16535ff0e..59a310f9b8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -45,12 +45,12 @@ version = "v0.4.11" [[projects]] - branch = "master" - digest = "1:3721a10686511b80c052323423f0de17a8c06d417dbdd3b392b1578432a33aae" + digest = "1:33f920ba428942560c22c0e145127dc09a52c52d64eac284daea6b0926fab0d1" name = "github.com/Nvveen/Gotty" packages = ["."] pruneopts = "UT" - revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" + revision = "a8b993ba6abdb0e0c12b0125c603323a71c7790c" + source = "https://github.com/ijc25/Gotty.git" [[projects]] digest = "1:d1665c44bd5db19aaee18d1b6233c99b0b9a986e8bccb24ef54747547a48027f" @@ -103,7 +103,7 @@ version = "v3.5.1" [[projects]] - digest = "1:9453458ba06a7b4b5a6cb522b479f449b4d9387bcf33f9a7e3fdb834569d7a40" + digest = "1:2aaf2cc045d0219bba79655e4df795b973168c310574669cb75786684f7287d3" name = "github.com/bmatcuk/doublestar" packages = ["."] pruneopts = "UT" @@ -186,7 +186,7 @@ revision = "83389a148052d74ac602f5f1d62f86ff2f3c4aa5" [[projects]] - digest = "1:ffc2c4996d342178394513e9866703fa8cc3154f1ae0e855c9716036abccf3ff" + digest = "1:5554aa6778ee3128d438eff483b2fdacf85f4c157abaafbead51af87d38264cb" name = "github.com/docker/docker" packages = [ "api", @@ -750,7 +750,7 @@ version = "v0.1.1" [[projects]] - digest = "1:c1072f27d5b8be1032af14ed7776f475bc58d35723a753c4b92c953d92e3eb33" + digest = "1:6d4d9067e639d96a804ee9a30fa89c7233c5c5edbfe736072ff00d48c97bccc4" name = "github.com/otiai10/copy" packages = ["."] pruneopts = "UT" @@ -1574,7 +1574,7 @@ version = "kubernetes-1.10.0" [[projects]] - digest = "1:7ae7497bb0f95b9f0d3d5876cb4140645773697c4f7ec12621da7ddc369d784f" + digest = "1:dabd439d62fbe939504ccb2ec6783d91412cdfc83e204731c16623a8d750d529" name = "k8s.io/helm" packages = [ "cmd/helm/installer", @@ -1618,7 +1618,7 @@ revision = "e3762e86a74c878ffed47484592986685639c2cd" [[projects]] - digest = "1:a93d65b059d465cd84ba089b8daf6fbacf3beeb0e78fa1a4cf0585398795b37c" + digest = "1:96dd0316331274d35050f78288957e6d04bd5594457ea1f7c24f463d19b7d793" name = "k8s.io/kubernetes" packages = [ "pkg/api/events", diff --git a/Gopkg.toml b/Gopkg.toml index 138a954d57..fd7c8c4ec5 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -114,6 +114,11 @@ [[override]] name = "github.com/sirupsen/logrus" version = "v1.0.6" + +[[override]] + name = "github.com/Nvveen/Gotty" + source = "https://github.com/ijc25/Gotty.git" + revision = "a8b993ba6abdb0e0c12b0125c603323a71c7790c" [prune] go-tests = true