diff --git a/examples/Makefile b/examples/Makefile index 5e1ec1e988..d333a6d280 100755 --- a/examples/Makefile +++ b/examples/Makefile @@ -56,7 +56,7 @@ vm-destroy: ## Cleanup plz @vagrant destroy -f .PHONY: package-examples -package-examples: package-example-big-bang package-example-software-factory package-example-data-injection package-example-game package-example-gitops-data package-example-single-big-bang-package package-example-tiny-kafka package-example-postgres-operator ## Create zarf packages from all examples +package-examples: package-example-big-bang package-example-software-factory package-example-data-injection package-example-game package-example-gitops-data package-example-single-big-bang-package package-example-tiny-kafka package-example-postgres-operator package-example-composability ## Create zarf packages from all examples .PHONY: package-example-big-bang package-example-big-bang: ## Create the Big Bang Core example @@ -101,3 +101,7 @@ package-example-tiny-kafka: ## Create the Tiny Kafka example .PHONY: package-example-postgres-operator package-example-postgres-operator: ## Create the Postgres Operator example cd postgres-operator && $(ZARF_BIN) package create --confirm && mv zarf-package-* ../sync/ + +.PHONY: package-example-composability +package-example-composability: ## Create the Composable example + cd composable-packages && $(ZARF_BIN) package create --confirm && mv zarf-package-* ../sync/ diff --git a/examples/compose-example/zarf.yaml b/examples/composable-packages/zarf.yaml similarity index 100% rename from examples/compose-example/zarf.yaml rename to examples/composable-packages/zarf.yaml diff --git a/test/e2e/e2e_composability_test.go b/test/e2e/e2e_composability_test.go new file mode 100644 index 0000000000..6050990768 --- /dev/null +++ b/test/e2e/e2e_composability_test.go @@ -0,0 +1,63 @@ +package test + +import ( + "fmt" + "testing" + "time" + + teststructure "github.com/gruntwork-io/terratest/modules/test-structure" + "github.com/stretchr/testify/require" +) + +func TestE2eExampleComposability(t *testing.T) { + + e2e := NewE2ETest(t) + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer teststructure.RunTestStage(e2e.testing, "TEARDOWN", e2e.teardown) + + // Upload the Zarf artifacts + teststructure.RunTestStage(e2e.testing, "UPLOAD", func() { + e2e.syncFileToRemoteServer("../../build/zarf", fmt.Sprintf("/home/%s/build/zarf", e2e.username), "0700") + e2e.syncFileToRemoteServer("../../build/zarf-init.tar.zst", fmt.Sprintf("/home/%s/build/zarf-init.tar.zst", e2e.username), "0600") + e2e.syncFileToRemoteServer("../../build/zarf-package-compose-example.tar.zst", fmt.Sprintf("/home/%s/build/zarf-package-compose-example.tar.zst", e2e.username), "0600") + }) + + teststructure.RunTestStage(e2e.testing, "TEST", func() { + // Make sure `zarf --help` doesn't error + output, err := e2e.runSSHCommand("sudo /home/%s/build/zarf --help", e2e.username) + require.NoError(e2e.testing, err, output) + + // run `zarf init` + output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf init --confirm --components k3s'", e2e.username) + require.NoError(e2e.testing, err, output) + + // Deploy the composable package + output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf package deploy zarf-package-composable-example.tar.zst --confirm'", e2e.username) + require.NoError(e2e.testing, err, output) + + // Validate that the composed sub packages exist + require.Contains(e2e.testing, "flux-baseline", output) + require.Contains(e2e.testing, "appliance-demo-multi-games-baseline", output) + + // Establish the port-forward into the game service; give the service a few seconds to come up since this is not a command we can retry + time.Sleep(5 * time.Second) + output, err = e2e.runSSHCommand("sudo bash -c '(/home/%s/build/zarf connect doom --local-port 22333 &> /dev/nul &)'", e2e.username) + require.NoError(e2e.testing, err, output) + + // Right now we're just checking that `curl` returns 0. It can be enhanced by scraping the HTML that gets returned or something. + output, err = e2e.runSSHCommand("bash -c '[[ $(curl -sfSL --retry 15 --retry-connrefused --retry-delay 5 http://127.0.0.1:22333?doom') ]]'") + require.NoError(e2e.testing, err, output) + require.Contains(e2e.testing, "Zarf needs games too", output) + + // Validate that the flux composed component was deployed by describing the flux helm controller and validating availibility + output, err = e2e.runSSHCommand(`sudo bash -c '/usr/sbin/kubectl describe deployment helm-controller -n flux-system'`) + require.NoError(e2e.testing, err, output) + require.Contains(e2e.testing, "1 desired | 1 updated | 1 total | 1 available | 0 unavailable", output) + + // Run `zarf destroy` to make sure that works correctly + output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf destroy --confirm'", e2e.username) + require.NoError(e2e.testing, err, output) + }) + +}