Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(halo): ready command integrated into docker containers #2179

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/cmd/compose.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ services:
#- --metrics # Enable prometheus metrics
#- --pprof # Enable prometheus metrics
#- --pprof.addr=0.0.0.0 # Enable prometheus metrics
healthcheck:
test: "nc -z localhost 8545"
interval: 1s
retries: 30

ports:
- 8551 # Auth-RPC (used by halo)
Expand Down
1 change: 1 addition & 0 deletions halo/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func New() *cobra.Command {
buildinfo.NewVersionCmd(),
newConsKeyCmd(),
newStatusCmd(),
newReadyCmd(),
)
}

Expand Down
61 changes: 61 additions & 0 deletions halo/cmd/ready.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmd

import (
"context"
"fmt"
"net/http"
"time"

"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"

cmtcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
)

func newReadyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "ready",
Short: "Assert the readiness of the halo node",
chmllr marked this conversation as resolved.
Show resolved Hide resolved
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
err := assertReady(cmd.Context())
if err != nil {
return errors.Wrap(err, "ready failed")
chmllr marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
},
}

return cmd
}

// assertReady calls halo's /ready endpoint and returns nil if the status is ready
// or an error otherwise.
func assertReady(ctx context.Context) error {
chmllr marked this conversation as resolved.
Show resolved Hide resolved
cfg := cmtcfg.DefaultConfig()
url := fmt.Sprintf("http://0.0.0.0%v/ready", cfg.Instrumentation.PrometheusListenAddr)

chmllr marked this conversation as resolved.
Show resolved Hide resolved
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
chmllr marked this conversation as resolved.
Show resolved Hide resolved
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return errors.Wrap(err, "http request creation")
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return errors.Wrap(err, "http request")
}
defer resp.Body.Close()

if resp.StatusCode < 400 {
chmllr marked this conversation as resolved.
Show resolved Hide resolved
log.Info(ctx, "The node is ready")
return nil
}

return errors.New("the node is not ready yet")
chmllr marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions halo/cmd/testdata/TestCLIReference_halo.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Available Commands:
consensus-pubkey Print the consensus public key
help Help about any command
init Initializes required halo files and directories
ready Assert the readiness of the halo node
rollback Rollback Cosmos SDK and CometBFT state by one height
run Runs the halo consensus client
status Query remote node for status
Expand Down
2 changes: 2 additions & 0 deletions scripts/halovisor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ COPY --from=build-cosmovisor /ko-app/cosmovisor /usr/local/bin/cosmovisor
COPY --from=build-0-genesis /app /halovisor/genesis/bin/halo
COPY --from=build-1-uluwatu /app /halovisor/upgrades/1_uluwatu/bin/halo

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s CMD ["/halovisor/upgrades/1_uluwatu/bin/halo", "ready"]

# Cosmovisor is the entrypoint
ENTRYPOINT [ "cosmovisor" ]
# First 'run' is cosmovisor command, second 'run' is halo command.
Expand Down
Loading