From fa7dc831819ebf5df8b223a487eba51d744a18f7 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 18:47:24 -0600 Subject: [PATCH 1/6] (chore): Appease GolangLintCI in steps Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- pkg/runtime/runtime_manifest.go | 14 +++++++++++--- pkg/runtime/runtime_manifest_test.go | 3 ++- pkg/storage/plugins/mongodb/mongodb.go | 4 +++- pkg/storage/plugins/mongodb/mongodb_test.go | 8 ++++++-- pkg/test/helper.go | 3 ++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pkg/runtime/runtime_manifest.go b/pkg/runtime/runtime_manifest.go index a630023dc..ed1accd4d 100644 --- a/pkg/runtime/runtime_manifest.go +++ b/pkg/runtime/runtime_manifest.go @@ -495,7 +495,10 @@ func (m *RuntimeManifest) Initialize(ctx context.Context) error { // that's a cnab change somewhere probably // the problem is in injectParameters in cnab-go if string(bytes) == "null" { - m.config.FileSystem.Remove(param.Destination.Path) + err := m.config.FileSystem.Remove(param.Destination.Path) + if err != nil { + return fmt.Errorf("unable to remove destination path: %w", err) + } continue } decoded, err := base64.StdEncoding.DecodeString(string(bytes)) @@ -542,7 +545,10 @@ func (m *RuntimeManifest) unpackStateBag(ctx context.Context) error { // the problem is in injectParameters in cnab-go if string(bytes) == "null" { m.debugf(log, "Bundle state file has null content") - m.config.FileSystem.Remove(statePath) + err = m.config.FileSystem.Remove(statePath) + if err != nil { + log.Error(err) + } return nil } // Unpack the state file and copy its contents to where the bundle expects them @@ -598,7 +604,9 @@ func (m *RuntimeManifest) unpackStateBag(ctx context.Context) error { continue } - unpackStateFile(tr, header) + if err = unpackStateFile(tr, header); err != nil { + return err + } } return nil diff --git a/pkg/runtime/runtime_manifest_test.go b/pkg/runtime/runtime_manifest_test.go index ca65ad9fb..c8d8c938d 100644 --- a/pkg/runtime/runtime_manifest_test.go +++ b/pkg/runtime/runtime_manifest_test.go @@ -119,7 +119,8 @@ state: } else { require.Contains(t, err.Error(), test.expErr.Error()) } - pCtx.FileSystem.Remove("/porter/state.tgz") + err = pCtx.FileSystem.Remove("/porter/state.tgz") + require.NoError(t, err) }) } } diff --git a/pkg/storage/plugins/mongodb/mongodb.go b/pkg/storage/plugins/mongodb/mongodb.go index 5f0700fbe..8e2433f53 100644 --- a/pkg/storage/plugins/mongodb/mongodb.go +++ b/pkg/storage/plugins/mongodb/mongodb.go @@ -88,7 +88,9 @@ func (s *Store) Close() error { cxt, cancel := context.WithTimeout(context.Background(), s.timeout) defer cancel() - s.client.Disconnect(cxt) + if err := s.client.Disconnect(cxt); err != nil { + return err + } s.client = nil } return nil diff --git a/pkg/storage/plugins/mongodb/mongodb_test.go b/pkg/storage/plugins/mongodb/mongodb_test.go index 38d57fb54..e9f583e93 100644 --- a/pkg/storage/plugins/mongodb/mongodb_test.go +++ b/pkg/storage/plugins/mongodb/mongodb_test.go @@ -14,14 +14,18 @@ func TestParseDatabase(t *testing.T) { tc := portercontext.NewTestContext(t) t.Run("db specified", func(t *testing.T) { mongo := NewStore(tc.Context, PluginConfig{URL: "mongodb://localhost:27017/test/"}) - mongo.Connect(ctx) + if err := mongo.Connect(ctx); err != nil { + t.Fatal(err) + } defer mongo.Close() assert.Equal(t, "test", mongo.database) }) t.Run("default db", func(t *testing.T) { mongo := NewStore(tc.Context, PluginConfig{URL: "mongodb://localhost:27017"}) - mongo.Connect(ctx) + if err := mongo.Connect(ctx); err != nil { + t.Fatal(err) + } defer mongo.Close() assert.Equal(t, "porter", mongo.database) }) diff --git a/pkg/test/helper.go b/pkg/test/helper.go index 947f4c301..10fa96e5e 100644 --- a/pkg/test/helper.go +++ b/pkg/test/helper.go @@ -70,7 +70,8 @@ func TestMainWithMockedCommandHandlers(m *testing.M) { // the new test output. func CompareGoldenFile(t *testing.T, goldenFile string, got string) { if os.Getenv("PORTER_UPDATE_TEST_FILES") == "true" { - os.MkdirAll(filepath.Dir(goldenFile), pkg.FileModeDirectory) + err := os.MkdirAll(filepath.Dir(goldenFile), pkg.FileModeDirectory) + require.NoError(t, err) t.Logf("Updated test file %s to match latest test output", goldenFile) require.NoError(t, os.WriteFile(goldenFile, []byte(got), pkg.FileModeWritable), "could not update golden file %s", goldenFile) } else { From 50b91014dfda41032541d7ccd829ce3ac5978b28 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 18:50:47 -0600 Subject: [PATCH 2/6] pCtx to testconfig Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- pkg/runtime/runtime_manifest_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/runtime/runtime_manifest_test.go b/pkg/runtime/runtime_manifest_test.go index 052a65080..87c4204b2 100644 --- a/pkg/runtime/runtime_manifest_test.go +++ b/pkg/runtime/runtime_manifest_test.go @@ -120,7 +120,7 @@ state: } else { require.Contains(t, err.Error(), test.expErr.Error()) } - err = pCtx.FileSystem.Remove("/porter/state.tgz") + err = testConfig.FileSystem.Remove("/porter/state.tgz") require.NoError(t, err) }) } From 283613ecbabde7e0e260aefbc1a697140f7a780c Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 18:57:15 -0600 Subject: [PATCH 3/6] fix test failure Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- pkg/runtime/runtime_manifest_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/runtime/runtime_manifest_test.go b/pkg/runtime/runtime_manifest_test.go index 87c4204b2..8de9c49f4 100644 --- a/pkg/runtime/runtime_manifest_test.go +++ b/pkg/runtime/runtime_manifest_test.go @@ -120,8 +120,10 @@ state: } else { require.Contains(t, err.Error(), test.expErr.Error()) } - err = testConfig.FileSystem.Remove("/porter/state.tgz") - require.NoError(t, err) + if test.stateContent != "null" { + err = testConfig.FileSystem.Remove("/porter/state.tgz") + require.NoError(t, err) + } }) } } From 23d870b54a7cbd2678eb57f364813f72423ec7ef Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 19:39:02 -0600 Subject: [PATCH 4/6] next seven Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- pkg/exec/builder/errors.go | 2 +- pkg/exec/version_test.go | 6 +- pkg/pkgmgmt/client/install.go | 10 +- pkg/pkgmgmt/client/runner.go | 4 +- pkg/pkgmgmt/feed/generate_test.go | 214 ++++++++++++++++++----- pkg/plugins/pluggable/connection.go | 2 +- pkg/portercontext/context_test.go | 5 +- workshop/porter-tf-aci/azure/app/main.go | 5 +- 8 files changed, 195 insertions(+), 53 deletions(-) diff --git a/pkg/exec/builder/errors.go b/pkg/exec/builder/errors.go index 68aff8154..eade0c235 100644 --- a/pkg/exec/builder/errors.go +++ b/pkg/exec/builder/errors.go @@ -74,7 +74,7 @@ func (h IgnoreErrorHandler) HandleError(ctx context.Context, err ExitError, stdo for _, allowMatch := range h.Output.Regex { expression, regexErr := regexp.Compile(allowMatch) if regexErr != nil { - span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error())) + err := span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error())) return err } diff --git a/pkg/exec/version_test.go b/pkg/exec/version_test.go index 4456be08c..b4136ec25 100644 --- a/pkg/exec/version_test.go +++ b/pkg/exec/version_test.go @@ -19,7 +19,8 @@ func TestPrintVersion(t *testing.T) { opts := version.Options{} err := opts.Validate() require.NoError(t, err) - m.PrintVersion(opts) + err = m.PrintVersion(opts) + require.NoError(t, err) gotOutput := m.TestConfig.TestContext.GetOutput() wantOutput := "exec v1.2.3 (abc123) by Porter Authors" @@ -38,7 +39,8 @@ func TestPrintJsonVersion(t *testing.T) { opts.RawFormat = string(printer.FormatJson) err := opts.Validate() require.NoError(t, err) - m.PrintVersion(opts) + err = m.PrintVersion(opts) + require.NoError(t, err) gotOutput := m.TestConfig.TestContext.GetOutput() wantOutput := `{ diff --git a/pkg/pkgmgmt/client/install.go b/pkg/pkgmgmt/client/install.go index 94304c0b4..8d6e28b6d 100644 --- a/pkg/pkgmgmt/client/install.go +++ b/pkg/pkgmgmt/client/install.go @@ -200,14 +200,18 @@ func (fs *FileSystem) downloadFile(ctx context.Context, url url.URL, destPath st return log.Error(fmt.Errorf("unable to check if directory exists %s: %w", parentDir, err)) } - cleanup := func() {} + cleanup := func() error { return nil } if !parentDirExists { err = fs.FileSystem.MkdirAll(parentDir, pkg.FileModeDirectory) if err != nil { return log.Error(fmt.Errorf("unable to create parent directory %s: %w", parentDir, err)) } - cleanup = func() { - fs.FileSystem.RemoveAll(parentDir) // If we can't download the file, don't leave traces of it + cleanup = func() error { + // If we can't download the file, don't leave traces of it + if err = fs.FileSystem.RemoveAll(parentDir); err != nil { + return err + } + return nil } } diff --git a/pkg/pkgmgmt/client/runner.go b/pkg/pkgmgmt/client/runner.go index eded5939a..e56f372d7 100644 --- a/pkg/pkgmgmt/client/runner.go +++ b/pkg/pkgmgmt/client/runner.go @@ -84,7 +84,9 @@ func (r *Runner) Run(ctx context.Context, commandOpts pkgmgmt.CommandOptions) er } go func() { defer stdin.Close() - io.WriteString(stdin, commandOpts.Input) + if _, err := io.WriteString(stdin, commandOpts.Input); err != nil { + span.Error(err) + } }() } diff --git a/pkg/pkgmgmt/feed/generate_test.go b/pkg/pkgmgmt/feed/generate_test.go index f5208e202..d78abe781 100644 --- a/pkg/pkgmgmt/feed/generate_test.go +++ b/pkg/pkgmgmt/feed/generate_test.go @@ -15,65 +15,183 @@ import ( ) func TestGenerate(t *testing.T) { + var err error ctx := context.Background() tc := portercontext.NewTestContext(t) tc.AddTestFile("testdata/atom-template.xml", "template.xml") - tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64") - tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64") - tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64") - tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe") - tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe") + if err != nil { + require.NoError(t, err) + } // Force the up3 timestamps to stay the same for each test run up3, _ := time.Parse("2006-Jan-02", "2013-Feb-03") - tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3) + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64") - tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up4, _ := time.Parse("2006-Jan-02", "2013-Feb-04") - tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4) - tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4) - tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4) + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64") - tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up2, _ := time.Parse("2006-Jan-02", "2013-Feb-02") - tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2) - tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2) - tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2) + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/canary/exec-darwin-amd64") - tc.FileSystem.Create("bin/canary/exec-linux-amd64") - tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/canary/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up10, _ := time.Parse("2006-Jan-02", "2013-Feb-10") - tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10) - tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10) - tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10) + err = tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10) + if err != nil { + require.NoError(t, err) + } // Create extraneous release directories that should be ignored - tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64") - tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64") - tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/latest/helm-darwin-amd64") - tc.FileSystem.Create("bin/latest/helm-linux-amd64") - tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/latest/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/latest/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64") - tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64") - tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } opts := GenerateOptions{ AtomFile: "atom.xml", @@ -81,7 +199,7 @@ func TestGenerate(t *testing.T) { TemplateFile: "template.xml", } f := NewMixinFeed(tc.Context) - err := f.Generate(ctx, opts) + err = f.Generate(ctx, opts) require.NoError(t, err) err = f.Save(opts) require.NoError(t, err) @@ -142,9 +260,19 @@ func TestGenerate_RegexMatch(t *testing.T) { porterCtx.AddTestFile("testdata/atom-template.xml", "template.xml") if tc.mixinName != "" { - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName)) - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName)) - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName)) + var err error + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } } opts := GenerateOptions{ diff --git a/pkg/plugins/pluggable/connection.go b/pkg/plugins/pluggable/connection.go index 1aff49d40..95b061906 100644 --- a/pkg/plugins/pluggable/connection.go +++ b/pkg/plugins/pluggable/connection.go @@ -161,7 +161,7 @@ func (c *PluginConnection) Start(ctx context.Context, pluginCfg io.Reader) error pluginErr = ": plugin stderr was " + pluginErr } err = fmt.Errorf("could not connect to the %s plugin%s: %w", c.key, pluginErr, err) - span.Error(err) // Emit the error before trying to close the connection + err = span.Error(err) // Emit the error before trying to close the connection c.Close(ctx) return err } diff --git a/pkg/portercontext/context_test.go b/pkg/portercontext/context_test.go index f7b4e8516..4603349a6 100644 --- a/pkg/portercontext/context_test.go +++ b/pkg/portercontext/context_test.go @@ -44,7 +44,10 @@ func TestContext_LogToFile(t *testing.T) { _, log := c.StartRootSpan(context.Background(), t.Name()) log.Info("a thing happened") log.Warn("a weird thing happened") - log.Error(errors.New("a bad thing happened")) + //throwing away error here because it is a test + // we do not return it + _ = log.Error(errors.New("a bad thing happened")) + log.EndSpan() c.Close() diff --git a/workshop/porter-tf-aci/azure/app/main.go b/workshop/porter-tf-aci/azure/app/main.go index 6155ae490..fcb9aa052 100644 --- a/workshop/porter-tf-aci/azure/app/main.go +++ b/workshop/porter-tf-aci/azure/app/main.go @@ -13,7 +13,10 @@ func handle(w http.ResponseWriter, r *http.Request) { http.Error(w, "couldn't find MYSQL FQDN", http.StatusInternalServerError) } - w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN))) + _, err := w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN))) + if err != nil { + log.Fatal(err) + } } func main() { From 6237b1f36b7d54de24137ae1a050274b286704b4 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 20:02:15 -0600 Subject: [PATCH 5/6] last batch Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- mage/docs/docs.go | 9 +++++--- pkg/build/dockerfile-generator_test.go | 12 +++++++---- pkg/cache/cache_test.go | 11 +++++----- pkg/cnab/config-adapter/stamp.go | 2 +- pkg/config/config.go | 5 +++-- pkg/config/helpers.go | 26 ++++++++++++++++------ pkg/config/loader.go | 30 ++++++++++++++++++++------ pkg/editor/editor.go | 8 +++++-- 8 files changed, 73 insertions(+), 30 deletions(-) diff --git a/mage/docs/docs.go b/mage/docs/docs.go index 8fd5d4c8a..b8858d5e6 100644 --- a/mage/docs/docs.go +++ b/mage/docs/docs.go @@ -41,7 +41,8 @@ func Docs() { } func removePreviewContainer() { - docker.RemoveContainer(PreviewContainer) + err := docker.RemoveContainer(PreviewContainer) + mgx.Must(err) } // Preview the website locally using a Docker container. @@ -59,12 +60,13 @@ func DocsPreview() { } setDockerUser := fmt.Sprintf("--user=%s:%s", currentUser.Uid, currentUser.Gid) pwd, _ := os.Getwd() - must.Run("docker", "run", "-d", "-v", pwd+":/src", + err = must.Run("docker", "run", "-d", "-v", pwd+":/src", "-v", operatorDocs+":/src/docs/content/operator", setDockerUser, "-p", "1313:1313", "--name", PreviewContainer, "-w", "/src/docs", "klakegg/hugo:0.78.1-ext-alpine", "server", "-D", "-F", "--noHTTPCache", "--watch", "--bind=0.0.0.0") + mgx.Must(err) for { output, _ := must.OutputS("docker", "logs", "porter-docs") @@ -74,7 +76,8 @@ func DocsPreview() { time.Sleep(time.Second) } - must.Run("open", "http://localhost:1313/docs/") + err = must.Run("open", "http://localhost:1313/docs/") + mgx.Must(err) } // Build a branch preview of the website. diff --git a/pkg/build/dockerfile-generator_test.go b/pkg/build/dockerfile-generator_test.go index 54cdbcf26..b6c4c8734 100644 --- a/pkg/build/dockerfile-generator_test.go +++ b/pkg/build/dockerfile-generator_test.go @@ -63,7 +63,8 @@ func TestPorter_buildCustomDockerfile(t *testing.T) { COPY mybin /cnab/app/ ` - c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + err = c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + require.NoError(t, err) mp := mixin.NewTestMixinProvider() g := NewDockerfileGenerator(c.Config, m, tmpl, mp) @@ -94,7 +95,8 @@ COPY mybin /cnab/app/ COPY mybin /cnab/app/ ` - c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + err = c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + require.NoError(t, err) mp := mixin.NewTestMixinProvider() g := NewDockerfileGenerator(c.Config, m, tmpl, mp) @@ -123,7 +125,8 @@ COPY mybin /cnab/app/ COPY mybin /cnab/app/ ` - c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + err = c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + require.NoError(t, err) mp := mixin.NewTestMixinProvider() g := NewDockerfileGenerator(c.Config, m, tmpl, mp) @@ -225,7 +228,8 @@ func TestPorter_appendBuildInstructionsIfMixinTokenIsNotPresent(t *testing.T) { ARG BUNDLE_DIR COPY mybin /cnab/app/ ` - c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + err = c.TestContext.AddTestFileContents([]byte(customFrom), "Dockerfile.template") + require.NoError(t, err) mp := mixin.NewTestMixinProvider() g := NewDockerfileGenerator(c.Config, m, tmpl, mp) diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index d84e1f5d0..56bf189b9 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -254,7 +254,7 @@ func TestStoreManifest(t *testing.T) { func TestCache_StoreBundle_Overwrite(t *testing.T) { t.Parallel() - + var err error cfg := config.NewTestConfig(t) home, _ := cfg.Config.GetHomeDir() cacheDir := filepath.Join(home, "cache") @@ -266,12 +266,13 @@ func TestCache_StoreBundle_Overwrite(t *testing.T) { cb := CachedBundle{BundleReference: cnab.BundleReference{Reference: kahn1dot01}} cb.SetCacheDir(cacheDir) cfg.FileSystem.Create(cb.BuildManifestPath()) - cfg.FileSystem.Create(cb.BuildRelocationFilePath()) + _, err = cfg.FileSystem.Create(cb.BuildRelocationFilePath()) + require.NoError(t, err) junkPath := filepath.Join(cb.cacheDir, "junk.txt") - cfg.FileSystem.Create(junkPath) - + _, err = cfg.FileSystem.Create(junkPath) + require.NoError(t, err) // Refresh the cache - cb, err := c.StoreBundle(cb.BundleReference) + cb, err = c.StoreBundle(cb.BundleReference) require.NoError(t, err, "StoreBundle failed") exists, _ := cfg.FileSystem.Exists(cb.BuildBundlePath()) diff --git a/pkg/cnab/config-adapter/stamp.go b/pkg/cnab/config-adapter/stamp.go index 956256f46..8f73cb9f8 100644 --- a/pkg/cnab/config-adapter/stamp.go +++ b/pkg/cnab/config-adapter/stamp.go @@ -135,7 +135,7 @@ func (c *ManifestConverter) GenerateStamp(ctx context.Context) (Stamp, error) { if err != nil { // The digest is only used to decide if we need to rebuild, it is not an error condition to not // have a digest. - log.Error(fmt.Errorf("WARNING: Could not digest the porter manifest file: %w", err)) + log.Warn(fmt.Sprint("WARNING: Could not digest the porter manifest file: %w", err)) stamp.ManifestDigest = "unknown" } else { stamp.ManifestDigest = digest diff --git a/pkg/config/config.go b/pkg/config/config.go index 9502659d0..b0914adeb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -254,8 +254,9 @@ func (c *Config) GetPorterPath(ctx context.Context) (string, error) { // We try to resolve back to the original location hardPath, err := evalSymlinks(porterPath) if err != nil { // if we have trouble resolving symlinks, skip trying to help people who used symlinks - log.Error(fmt.Errorf("WARNING could not resolve %s for symbolic links: %w", porterPath, err)) - } else if hardPath != porterPath { + return "", log.Error(fmt.Errorf("WARNING could not resolve %s for symbolic links: %w", porterPath, err)) + } + if hardPath != porterPath { log.Debugf("Resolved porter binary from %s to %s", porterPath, hardPath) porterPath = hardPath } diff --git a/pkg/config/helpers.go b/pkg/config/helpers.go index dafb1e664..988e0d50b 100644 --- a/pkg/config/helpers.go +++ b/pkg/config/helpers.go @@ -2,6 +2,7 @@ package config import ( "context" + "log" "os" "path/filepath" "strconv" @@ -42,14 +43,27 @@ func (c *TestConfig) SetupUnitTest() { c.SetHomeDir(home) // Fake out the porter home directory - c.FileSystem.Create(filepath.Join(home, "porter")) - c.FileSystem.Create(filepath.Join(home, "runtimes", "porter-runtime")) + var err error + if _, err = c.FileSystem.Create(filepath.Join(home, "porter")); err != nil { + log.Fatal(err) + } + if _, err = c.FileSystem.Create(filepath.Join(home, "runtimes", "porter-runtime")); err != nil { + log.Fatal(err) + } mixinsDir := filepath.Join(home, "mixins") - c.FileSystem.Create(filepath.Join(mixinsDir, "exec/exec")) - c.FileSystem.Create(filepath.Join(mixinsDir, "exec/runtimes/exec-runtime")) - c.FileSystem.Create(filepath.Join(mixinsDir, "testmixin/testmixin")) - c.FileSystem.Create(filepath.Join(mixinsDir, "testmixin/runtimes/testmixin-runtime")) + if _, err = c.FileSystem.Create(filepath.Join(mixinsDir, "exec/exec")); err != nil { + log.Fatal(err) + } + if _, err = c.FileSystem.Create(filepath.Join(mixinsDir, "exec/runtimes/exec-runtime")); err != nil { + log.Fatal(err) + } + if _, err = c.FileSystem.Create(filepath.Join(mixinsDir, "testmixin/testmixin")); err != nil { + log.Fatal(err) + } + if _, err = c.FileSystem.Create(filepath.Join(mixinsDir, "testmixin/runtimes/testmixin-runtime")); err != nil { + log.Fatal(err) + } } // SetupIntegrationTest initializes the filesystem with the supporting files in diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 190bdc141..de9212a22 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -3,6 +3,7 @@ package config import ( "bytes" "context" + "errors" "fmt" "sort" "strings" @@ -36,13 +37,28 @@ func BindViperToEnvironmentVariables(v *viper.Viper) { // Bind open telemetry environment variables // See https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp/otlptrace - v.BindEnv("telemetry.endpoint", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") - v.BindEnv("telemetry.protocol", "OTEL_EXPORTER_OTLP_PROTOCOL", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL") - v.BindEnv("telemetry.insecure", "OTEL_EXPORTER_OTLP_INSECURE", "OTEL_EXPORTER_OTLP_TRACES_INSECURE") - v.BindEnv("telemetry.certificate", "OTEL_EXPORTER_OTLP_CERTIFICATE", "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE") - v.BindEnv("telemetry.headers", "OTEL_EXPORTER_OTLP_HEADERS", "OTEL_EXPORTER_OTLP_TRACES_HEADERS") - v.BindEnv("telemetry.compression", "OTEL_EXPORTER_OTLP_COMPRESSION", "OTEL_EXPORTER_OTLP_TRACES_COMPRESSION") - v.BindEnv("telemetry.timeout", "OTEL_EXPORTER_OTLP_TIMEOUT", "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT") + var err error + if err = v.BindEnv("telemetry.endpoint", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.protocol", "OTEL_EXPORTER_OTLP_PROTOCOL", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.insecure", "OTEL_EXPORTER_OTLP_INSECURE", "OTEL_EXPORTER_OTLP_TRACES_INSECURE"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.certificate", "OTEL_EXPORTER_OTLP_CERTIFICATE", "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.headers", "OTEL_EXPORTER_OTLP_HEADERS", "OTEL_EXPORTER_OTLP_TRACES_HEADERS"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.compression", "OTEL_EXPORTER_OTLP_COMPRESSION", "OTEL_EXPORTER_OTLP_TRACES_COMPRESSION"); err != nil { + errors.Unwrap(err) + } + if err = v.BindEnv("telemetry.timeout", "OTEL_EXPORTER_OTLP_TIMEOUT", "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT"); err != nil { + errors.Unwrap(err) + } } // LoadFromFilesystem loads data with the following precedence: diff --git a/pkg/editor/editor.go b/pkg/editor/editor.go index b18d5c6a0..d6488348a 100644 --- a/pkg/editor/editor.go +++ b/pkg/editor/editor.go @@ -61,8 +61,12 @@ func (e *Editor) Run(ctx context.Context) ([]byte, error) { if err != nil { return nil, err } - defer e.FileSystem.Remove(tempFile.Name()) - + defer func() error { + if err = e.FileSystem.Remove(tempFile.Name()); err != nil { + return err + } + return nil + }() _, err = tempFile.Write(e.contents) if err != nil { return nil, err From 30dd4c8372aa9a9a342c08cea646a743e241d5f2 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 15 May 2024 20:15:11 -0600 Subject: [PATCH 6/6] netlify doesnt use docker? Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- mage/docs/docs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mage/docs/docs.go b/mage/docs/docs.go index b8858d5e6..5d16af9d6 100644 --- a/mage/docs/docs.go +++ b/mage/docs/docs.go @@ -29,8 +29,7 @@ const ( // Build the website in preparation for deploying to the production website on Netlify. // Uses symlinks so it won't work on Windows. Don't run locally, use DocsPreview instead. func Docs() { - // Remove the preview container because otherwise it holds a file open and we can't delete the volume mount created at docs/content/operator - mg.SerialDeps(removePreviewContainer, linkOperatorDocs) + mg.SerialDeps(linkOperatorDocs) cmd := must.Command("hugo", "--source", "docs/") baseURL := os.Getenv("BASEURL")