From 4a3de40a94a583d8cb07cfd2c7a8584ef9317336 Mon Sep 17 00:00:00 2001 From: Zach Wasserman Date: Fri, 31 Dec 2021 15:13:28 -0800 Subject: [PATCH] Add no-hosts option to `fleetctl preview` (#3544) Intended mostly for testing, this is documented only in the Fleet handbook. --- cmd/fleetctl/preview.go | 60 ++++++++++++++++++++++++----------------- handbook/product.md | 6 +++-- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/cmd/fleetctl/preview.go b/cmd/fleetctl/preview.go index f54336409b..f5771b8ada 100644 --- a/cmd/fleetctl/preview.go +++ b/cmd/fleetctl/preview.go @@ -34,6 +34,7 @@ const ( licenseKeyFlagName = "license-key" tagFlagName = "tag" previewConfigFlagName = "preview-config" + noHostsFlagName = "no-hosts" ) func previewCommand() *cli.Command { @@ -65,6 +66,11 @@ Use the stop and reset subcommands to manage the server and dependencies once st Usage: "Run a specific branch of the preview repository", Value: "production", }, + &cli.BoolFlag{ + Name: noHostsFlagName, + Usage: "Start the server without adding any hosts", + Value: false, + }, }, Action: func(c *cli.Context) error { if err := checkDocker(); err != nil { @@ -242,38 +248,44 @@ Use the stop and reset subcommands to manage the server and dependencies once st return fmt.Errorf("Error disabling anonymous analytics collection in app config: %w", err) } - fmt.Println("Fleet will now enroll your device and log you into the UI automatically.") + fmt.Println("Fleet will now log you into the UI automatically.") fmt.Println("You can also open the UI at this URL: http://localhost:1337/previewlogin.") fmt.Println("Email:", email) fmt.Println("Password:", password) - fmt.Println("Downloading Orbit and osqueryd...") + if !c.Bool(noHostsFlagName) { + fmt.Println("Enrolling local host...") - if err := downloadOrbitAndStart(previewDir, secrets.Secrets[0].Secret, address); err != nil { - return fmt.Errorf("downloading orbit and osqueryd: %w", err) - } + if err := downloadOrbitAndStart(previewDir, secrets.Secrets[0].Secret, address); err != nil { + return fmt.Errorf("downloading orbit and osqueryd: %w", err) + } - // Give it a bit of time so the current device is the one with id 1 - fmt.Println("Waiting for current host to enroll...") - if err := waitFirstHost(client); err != nil { - return fmt.Errorf("wait for current host: %w", err) - } + // Give it a bit of time so the current device is the one with id 1 + fmt.Println("Waiting for host to enroll...") + if err := waitFirstHost(client); err != nil { + return fmt.Errorf("wait for current host: %w", err) + } - if err := openBrowser("http://localhost:1337/previewlogin"); err != nil { - fmt.Println("Automatic browser open failed. Please navigate to http://localhost:1337/previewlogin.") - } + if err := openBrowser("http://localhost:1337/previewlogin"); err != nil { + fmt.Println("Automatic browser open failed. Please navigate to http://localhost:1337/previewlogin.") + } - fmt.Println("Starting simulated Linux hosts...") - cmd = exec.Command("docker-compose", "up", "-d", "--remove-orphans") - cmd.Dir = filepath.Join(previewDir, "osquery") - cmd.Env = append(os.Environ(), - "ENROLL_SECRET="+secrets.Secrets[0].Secret, - "FLEET_URL="+address, - ) - out, err = cmd.CombinedOutput() - if err != nil { - fmt.Println(string(out)) - return errors.New("Failed to run docker-compose") + fmt.Println("Starting simulated Linux hosts...") + cmd = exec.Command("docker-compose", "up", "-d", "--remove-orphans") + cmd.Dir = filepath.Join(previewDir, "osquery") + cmd.Env = append(os.Environ(), + "ENROLL_SECRET="+secrets.Secrets[0].Secret, + "FLEET_URL="+address, + ) + out, err = cmd.CombinedOutput() + if err != nil { + fmt.Println(string(out)) + return errors.New("Failed to run docker-compose") + } + } else { + if err := openBrowser("http://localhost:1337/previewlogin"); err != nil { + fmt.Println("Automatic browser open failed. Please navigate to http://localhost:1337/previewlogin.") + } } fmt.Println("Preview environment complete. Enjoy using Fleet!") diff --git a/handbook/product.md b/handbook/product.md index 5f33218238..36208dc59f 100644 --- a/handbook/product.md +++ b/handbook/product.md @@ -73,9 +73,11 @@ The images used in the docs live in `docs/images/`. Note that you must provide t Fleet uses a human-oriented quality assurance (QA) process to ensure the product meets the standards of users and organizations. -To try stuff out with Fleet locally for QA purposes, you can run `fleetctl preview`, which defaults to running the latest stable release. +To try Fleet locally for QA purposes, run `fleetctl preview`, which defaults to running the latest stable release. -To target a different version of Fleet, you can use the `--tag` argument to target any tag in [Docker Hub](https://hub.docker.com/r/fleetdm/fleet/tags?page=1&ordering=last_updated), including any git commit hash or branch name. For example, to QA the latest code on the `main` branch of fleetdm/fleet, you can run: `fleetctl preview --tag='main'` +To target a different version of Fleet, use the `--tag` flag to target any tag in [Docker Hub](https://hub.docker.com/r/fleetdm/fleet/tags?page=1&ordering=last_updated), including any git commit hash or branch name. For example, to QA the latest code on the `main` branch of fleetdm/fleet, you can run: `fleetctl preview --tag=main` + +To start preview without starting the simulated hosts, use the `--no-hosts` flag (eg. `fleetctl preview --no-hosts`). ### Why human-oriented QA?