|
6 | 6 | "fmt" |
7 | 7 | "log" |
8 | 8 | "log/slog" |
| 9 | + "net/http" |
9 | 10 | "net/url" |
10 | 11 | "os" |
11 | 12 | "path/filepath" |
|
56 | 57 | contenderArgs []string |
57 | 58 | contenderTarget string |
58 | 59 | detached bool |
| 60 | + readyServer bool |
59 | 61 | skipSetup bool |
60 | 62 | prefundedAccounts []string |
61 | 63 | followFlag bool |
@@ -599,6 +601,7 @@ func main() { |
599 | 601 | cmd.Flags().StringArrayVar(&contenderArgs, "contender.arg", []string{}, "add/override contender CLI flags") |
600 | 602 | cmd.Flags().StringVar(&contenderTarget, "contender.target", "", "override the node that contender spams") |
601 | 603 | cmd.Flags().BoolVar(&detached, "detached", false, "Detached mode: Run the recipes in the background") |
| 604 | + cmd.Flags().BoolVar(&readyServer, "ready-server", false, "Start an HTTP server on 0.0.0.0:8123 that returns 200 OK when all services are healthy") |
602 | 605 | cmd.Flags().BoolVar(&skipSetup, "skip-setup", false, "Skip the setup commands defined in the YAML recipe") |
603 | 606 | cmd.Flags().StringArrayVar(&prefundedAccounts, "prefunded-accounts", []string{}, "Fund this account in addition to static prefunded accounts") |
604 | 607 | cmd.Flags().BoolVar(&k8sFlag, "k8s", false, "generate Kubernetes manifests (requires kompose) and helper files") |
@@ -881,6 +884,21 @@ func runIt(recipe playground.Recipe) error { |
881 | 884 |
|
882 | 885 | slog.Info("All services are healthy! Ready to accept transactions. 🚀", "session-id", svcManager.ID) |
883 | 886 |
|
| 887 | + if readyServer { |
| 888 | + mux := http.NewServeMux() |
| 889 | + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 890 | + w.WriteHeader(http.StatusOK) |
| 891 | + }) |
| 892 | + srv := &http.Server{Addr: "0.0.0.0:8123", Handler: mux} |
| 893 | + defer srv.Close() |
| 894 | + go func() { |
| 895 | + slog.Info("Ready server listening", "addr", "0.0.0.0:8123") |
| 896 | + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { |
| 897 | + slog.Error("Ready server failed", "err", err) |
| 898 | + } |
| 899 | + }() |
| 900 | + } |
| 901 | + |
884 | 902 | // get the output from the recipe |
885 | 903 | output := recipe.Output(svcManager) |
886 | 904 | if len(output) > 0 { |
|
0 commit comments