[gcsproxy] Enable gcsproxy to run a subcommand

We would like to run `gcsproxy [options] botanist ...`, where we deploy
gcsproxy through conventional platform-infra ways. Due to container
networking limitations, we currently can't do this for devices or
Caviums, which is a problem that will be resolved in time. In the
meantime, we can do this in GCE for the QEMU case - and this is the
first CL of a small series that is to enable that.

Bug: 10427
Change-Id: I421af131f2561916b3f533392d658a647ba28d86
diff --git a/cmd/gcsproxy/main.go b/cmd/gcsproxy/main.go
index c2486f0..ab1738b 100644
--- a/cmd/gcsproxy/main.go
+++ b/cmd/gcsproxy/main.go
@@ -25,6 +25,7 @@
 	"golang.org/x/time/rate"
 
 	"go.fuchsia.dev/fuchsia/tools/lib/retry"
+	"go.fuchsia.dev/fuchsia/tools/lib/runner"
 )
 
 const (
@@ -61,9 +62,11 @@
 )
 
 func usage() {
-	fmt.Printf(`gcsproxy [flags]
+	fmt.Printf(`gcsproxy [flags] [subcommand]
 
 Starts a proxy server that forwards requests to GCS with authentication.
+If positional arguments are provided, they will be run as subprocess and
+the lifetime of the server will be scoped to the lifetime of that process.
 `)
 }
 
@@ -90,13 +93,13 @@
 		}
 	}()
 
-	if err := execute(ctx, credentialsFile, port, allowedAddrsFile); err != nil {
+	if err := execute(ctx, credentialsFile, port, allowedAddrsFile, flag.Args()); err != nil {
 		log.Fatal(err)
 	}
 }
 
 // Execute starts the proxy server.
-func execute(ctx context.Context, credFile, port, addrsFile string) error {
+func execute(ctx context.Context, credFile, port, addrsFile string, subCmd []string) error {
 	if port == "" {
 		return fmt.Errorf("-port is required")
 	}
@@ -149,6 +152,15 @@
 		errs <- s.ListenAndServe()
 	}()
 
+	if len(subCmd) > 0 {
+		r := runner.SubprocessRunner{
+			Env: os.Environ(),
+		}
+		go func() {
+			errs <- r.Run(ctx, subCmd, os.Stdout, os.Stderr)
+		}()
+	}
+
 	shutdown := func() error {
 		log.Printf("Shutting down GCS proxy server at localhost:%s", port)
 		return s.Shutdown(ctx)