diff --git a/Makefile b/Makefile index 5b67492..d66ce42 100644 --- a/Makefile +++ b/Makefile @@ -53,9 +53,11 @@ build: ## build the Gostwire stripped static binary build-embedded: ## build the Gostwire stripped static binary with embedded web UI @$(GENAPIDOC) ( \ - $(GETGITVERSION) \ - cd webui \ - REACT_APP_GIT_VERSION=$$GIT_VERSION yarn build \ + $(GETGITVERSION) && \ + cd webui && \ + echo "$$GIT_VERSION" && \ + sed -i "s/^VITE_REACT_APP_GIT_VERSION=.*/VITE_REACT_APP_GIT_VERSION=$$GIT_VERSION/" .env && \ + yarn build \ ) go build -v $(GOSTATIC),webui ./cmd/gostwire @file gostwire @@ -80,7 +82,7 @@ deploy: ## deploy Gostwire service exposed on host port 5999 && echo "deploying version" $$GIT_VERSION \ && scripts/docker-build.sh deployments/gostwire/Dockerfile \ -t gostwire \ - --build-arg GIT_VERSION=$$GIT_VERSION \ + --build-arg REACT_APP_GIT_VERSION=$$GIT_VERSION \ --build-context webappsrc=./webui \ ) docker compose -p gostwire -f deployments/gostwire/docker-compose.yaml up diff --git a/README.md b/README.md index 00b1229..945a720 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ ![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success) ![file descriptors](https://img.shields.io/badge/file%20descriptors-not%20leaking-success) [![Go Report Card](https://goreportcard.com/badge/github.com/siemens/ghostwire/v2)](https://goreportcard.com/report/github.com/siemens/ghostwire/v2) -![Coverage](https://img.shields.io/badge/Coverage-76.2%25-yellow) +![Coverage](https://img.shields.io/badge/Coverage-72.6%25-yellow) **G(h)ostwire** discovers the virtual (or not) network configuration inside _Linux_ hosts – and can be deployed as a REST service or consumed as a Go diff --git a/api/v1/package_test.go b/api/v1/package_test.go index 715d176..117a0e2 100644 --- a/api/v1/package_test.go +++ b/api/v1/package_test.go @@ -96,16 +96,18 @@ func Decorate(engines []*model.ContainerEngine, labels map[string]string) { } func tabulaRasa() { - nerdctl.NerdctlIgnore("rm", "-f", podc1) - nerdctl.NerdctlIgnore("rm", "-f", podc2) - nerdctl.NerdctlIgnore("rm", "-f", bareName) - nerdctl.NerdctlIgnore("network", "rm", podNetworkName) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + nerdctl.NerdctlIgnore(ctx, "rm", "-f", podc1) + nerdctl.NerdctlIgnore(ctx, "rm", "-f", podc2) + nerdctl.NerdctlIgnore(ctx, "rm", "-f", bareName) + nerdctl.NerdctlIgnore(ctx, "network", "rm", podNetworkName) } var v1apispec *openapi3.T var disco gostwire.DiscoveryResult -var _ = BeforeSuite(func() { +var _ = BeforeSuite(func(ctx context.Context) { if os.Getuid() != 0 { return } @@ -124,12 +126,16 @@ var _ = BeforeSuite(func() { tabulaRasa() By("setting up some fake pod containers") - nerdctl.Nerdctl("network", "create", podNetworkName) - nerdctl.Nerdctl( + cmdctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + nerdctl.Nerdctl(cmdctx, "network", "create", podNetworkName) + cmdctx, cancel = context.WithTimeout(ctx, 60*time.Second) + defer cancel() + nerdctl.Nerdctl(cmdctx, "run", "-d", "--name", bareName, "busybox", "/bin/sleep", "120s") - nerdctl.Nerdctl( + nerdctl.Nerdctl(cmdctx, "run", "-d", "--name", podc1, "--network", podNetworkName, @@ -137,7 +143,7 @@ var _ = BeforeSuite(func() { "--label", kuhbernetes.PodNameLabel+"="+podName, "--label", kuhbernetes.PodContainerNameLabel+"="+podc1, "busybox", "/bin/sleep", "120s") - nerdctl.Nerdctl( + nerdctl.Nerdctl(cmdctx, "run", "-d", "--name", podc2, "--network", podNetworkName, @@ -147,7 +153,7 @@ var _ = BeforeSuite(func() { "busybox", "/bin/sleep", "120s") By("discovering") - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel = context.WithCancel(ctx) cizer := turtlefinder.New(func() context.Context { return ctx }) defer cancel() defer cizer.Close() diff --git a/cmd/gostwire/server.go b/cmd/gostwire/server.go index 772dccf..d4188ce 100644 --- a/cmd/gostwire/server.go +++ b/cmd/gostwire/server.go @@ -23,7 +23,7 @@ import ( // dynVarsRe matches the window.dynvars assignment, so we can rewrite (or // rather, insert) the current values of variables that might or might not // changed based on the particular HTTP request. -var dynVarsRe = regexp.MustCompile(`()`) +var dynVarsRe = regexp.MustCompile(`()`) var ( once sync.Once diff --git a/decorator/nerdctlnet/nerdctlnet_test.go b/decorator/nerdctlnet/nerdctlnet_test.go index 448fc19..0d3ae24 100644 --- a/decorator/nerdctlnet/nerdctlnet_test.go +++ b/decorator/nerdctlnet/nerdctlnet_test.go @@ -43,13 +43,17 @@ var _ = Describe("nerdctlnet decorator", func() { goodfds := Filedescriptors() goodgos := Goroutines() // avoid other failed goroutine tests to spill over - nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName) - nerdctl.NerdctlIgnore("network", "rm", testNetworkName) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + nerdctl.NerdctlIgnore(ctx, "rm", "-f", testWorkloadName) + nerdctl.NerdctlIgnore(ctx, "network", "rm", testNetworkName) DeferCleanup(func() { gexec.KillAndWait() - nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName) - nerdctl.NerdctlIgnore("network", "rm", testNetworkName) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + nerdctl.NerdctlIgnore(ctx, "rm", "-f", testWorkloadName) + nerdctl.NerdctlIgnore(ctx, "network", "rm", testNetworkName) Eventually(Goroutines).WithTimeout(2 * time.Second).WithPolling(250 * time.Millisecond). ShouldNot(HaveLeaked(goodgos)) @@ -65,18 +69,22 @@ var _ = Describe("nerdctlnet decorator", func() { nerdctl.SkipWithout() By(fmt.Sprintf("creating a test bridge network %q", testNetworkName)) - nerdctl.Nerdctl("network", "create", "--label=foo=bar", testNetworkName) + cmdctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + nerdctl.Nerdctl(cmdctx, "network", "create", "--label=foo=bar", testNetworkName) By("creating a test workload and connecting it to the test network") - nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName) - nerdctl.Nerdctl( + cmdctx, cancel = context.WithTimeout(ctx, 60*time.Second) + defer cancel() + nerdctl.NerdctlIgnore(cmdctx, "rm", "-f", testWorkloadName) + nerdctl.Nerdctl(cmdctx, "run", "-d", "--name", testWorkloadName, "--network", testNetworkName, "busybox", "/bin/sleep", "120s") By("running a discovery") - ctx, cancel := context.WithCancel(ctx) + ctx, cancel = context.WithCancel(ctx) cizer := turtlefinder.New(func() context.Context { return ctx }) defer cancel() defer cizer.Close() diff --git a/deployments/gostwire/Dockerfile b/deployments/gostwire/Dockerfile index dc73899..5c004af 100644 --- a/deployments/gostwire/Dockerfile +++ b/deployments/gostwire/Dockerfile @@ -132,7 +132,8 @@ RUN yarn eslint --init COPY --from=webappsrc public/ ./public/ COPY --from=webappsrc src/ ./src/ COPY --from=webappsrc .env ./ -ARG GIT_VERSION +ARG REACT_APP_GIT_VERSION +RUN sed -i "s/^VITE_REACT_APP_GIT_VERSION=.*/VITE_REACT_APP_GIT_VERSION=${REACT_APP_GIT_VERSION}/" .env RUN yarn build # -- 3. stage --------------------------------------------------------------- diff --git a/test/nerdctl/nerdctl.go b/test/nerdctl/nerdctl.go index b44d3b0..4648535 100644 --- a/test/nerdctl/nerdctl.go +++ b/test/nerdctl/nerdctl.go @@ -5,7 +5,9 @@ package nerdctl import ( + "context" "os/exec" + "time" "github.com/onsi/gomega/gexec" @@ -15,18 +17,21 @@ import ( // Nerdctl runs a nerdctl command with the specified CLI arguments, expecting // the command to succeed without any error code. -func Nerdctl(args ...string) { +func Nerdctl(ctx context.Context, args ...string) { + gi.GinkgoHelper() session, err := gexec.Start( exec.Command("nerdctl", args...), gi.GinkgoWriter, gi.GinkgoWriter) - g.ExpectWithOffset(1, err).NotTo(g.HaveOccurred()) - g.EventuallyWithOffset(1, session, "5s").Should(gexec.Exit(0)) + g.Expect(err).NotTo(g.HaveOccurred()) + g.Eventually(ctx, session).ProbeEvery(100 * time.Millisecond). + Should(gexec.Exit(0)) } // NerdctlIgnore runs a nerdctl command with the specified CLI arguments and // ignores whatever outcome of running the nerdctl command will be. -func NerdctlIgnore(args ...string) { +func NerdctlIgnore(ctx context.Context, args ...string) { + gi.GinkgoHelper() session, err := gexec.Start( exec.Command("nerdctl", args...), gi.GinkgoWriter, @@ -34,7 +39,7 @@ func NerdctlIgnore(args ...string) { if err != nil { return } - g.EventuallyWithOffset(1, session, "5s").Should(gexec.Exit()) + g.Eventually(ctx, session).Should(gexec.Exit()) } // SkipWithout skips a test if nerdctl cannot be found in PATH. diff --git a/webui/.env b/webui/.env index 356c9c7..b1fd6d1 100644 --- a/webui/.env +++ b/webui/.env @@ -1 +1 @@ -VITE_REACT_APP_GIT_VERSION=$REACT_APP_GIT_VERSION +VITE_REACT_APP_GIT_VERSION=2.3.0-3-g190b76b diff --git a/webui/src/views/about/About.mdx b/webui/src/views/about/About.mdx index 4204746..646305b 100644 --- a/webui/src/views/about/About.mdx +++ b/webui/src/views/about/About.mdx @@ -1,6 +1,6 @@ # -© Siemens 2018-2023. All rights reserved. +© Siemens 2018-2024. All rights reserved. ## In a Nutshell @@ -13,7 +13,7 @@ Please see also our integrated detailed help. ## App Information -- **web app version:** +- **web app version:** - **discovery backend engine:** diff --git a/webui/src/views/help/chapters/Ghostwire.mdx b/webui/src/views/help/chapters/Ghostwire.mdx index 2ae31c3..875e085 100644 --- a/webui/src/views/help/chapters/Ghostwire.mdx +++ b/webui/src/views/help/chapters/Ghostwire.mdx @@ -52,7 +52,7 @@ install this plugin at any time without the need to restart your browser ## Copyright The [Edgeshark project](https://github.com/siemens/edgeshark) is (c) Siemens -2023 and available under the MIT license. +2023, 2024 and available under the MIT license. ## Trademarks