Skip to content

Commit

Permalink
test context cmd (#79)
Browse files Browse the repository at this point in the history
* Rename identity-1.audius-d -> identity.audius-d

There will only be one

* Add `audius-ctl test context` cmd

* Remove unneeded code

* Fix identity-1 -> identity hostnaming after rebase

* Separate context test logic from cobra command

* Add RPCs to test cmd

* Return correct status codes for test context cmd, update ci

---------

Co-authored-by: endline <[email protected]>
  • Loading branch information
endline and endline authored Jan 22, 2024
1 parent 80a6eab commit 1c672e8
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 173 deletions.
95 changes: 4 additions & 91 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ commands:
sudo cp deployments/tls/devnet-cert.pem /usr/local/share/ca-certificates/devnet.audius-d.crt
sudo update-ca-certificates
basic-health-check:
description: 'Perform a basic health check on an audius node'
parameters:
host:
type: string
jqkey:
type: string
steps:
- run:
name: 'Basic health check'
command: |
timeout=0
while [[ "$(curl -Lso /dev/null -w "%{http_code}" << parameters.host >>/health_check)" =~ 502|000 ]] && [ "$timeout" -lt 60 ]; do
sleep 3
((timeout=timeout+3))
echo "Waiting for server to start... $timeout"
done
cresult="$(curl -Lv << parameters.host >>/health_check | jq '<< parameters.jqkey >>')"
echo $cresult
[ "$cresult" = true ] || [ "$cresult" = false ]
jobs:
build:
machine:
Expand Down Expand Up @@ -104,56 +83,6 @@ jobs:
- bin/audius-ctl-arm
- bin/audius-ctl-x86

test-devnet-deps: # TODO add ingress. consolidate with test-audius-d-devnet.
machine:
image: ubuntu-2204:current
resource_class: large
steps:
- setup-audius-ctl
- run: docker network create --subnet=172.100.0.0/16 --gateway=172.100.0.1 deployments_devnet
- run: cd ~/audius-d && audius-ctl devnet
- run: docker ps
- run:
name: Wait for acdc-ganache to start
command: |
timeout=0
while [[ "$(curl -sf -w "%{http_code}" -o /dev/null -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8545)" =~ 502|000 ]] && [ "$timeout" -lt 60 ]; do
sleep 3
((timeout=timeout+3))
echo "Waiting for server to start... $timeout"
done
if [ "$timeout" -ge 60 ]; then
echo "Server didn't respond within 60 seconds. Exiting due to timeout."
exit 1
fi
- run:
name: Wait for mainnet-ganache to start
command: |
timeout=0
while [[ "$(curl -sf -w "%{http_code}" -o /dev/null -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://localhost:8546)" =~ 502|000 ]] && [ "$timeout" -lt 60 ]; do
sleep 3
((timeout=timeout+3))
echo "Waiting for server to start... $timeout"
done
if [ "$timeout" -ge 60 ]; then
echo "Server didn't respond within 60 seconds. Exiting due to timeout."
exit 1
fi
- run:
name: Wait for mainnet-solana to start
command: |
timeout=0
while [[ "$(curl http://localhost:8899 -o /dev/null -X POST -H "Content-Type: application/json" -w "%{http_code}" -d '{"jsonrpc":"2.0","id":1,"method":"getFirstAvailableBlock"}')" =~ 502|000 ]] && [ "$timeout" -lt 60 ]; do
sleep 3
((timeout=timeout+3))
echo "Waiting for server to start... $timeout"
done
if [ "$timeout" -ge 60 ]; then
echo "Server didn't respond within 60 seconds. Exiting due to timeout."
exit 1
fi
- run: audius-ctl devnet down

test-audius-d-devnet:
machine:
image: ubuntu-2204:current
Expand All @@ -163,33 +92,22 @@ jobs:
- run:
name: Add audius-d hosts
command: |
audius_hosts='127.0.0.1 creator-1.devnet.audius-d discovery-1.devnet.audius-d identity-1.devnet.audius-d eth-ganache.devnet.audius-d acdc-ganache.devnet.audius-d solana-test-validator.devnet.audius-d'
audius_hosts='127.0.0.1 creator-1.devnet.audius-d discovery-1.devnet.audius-d identity.devnet.audius-d eth-ganache.devnet.audius-d acdc-ganache.devnet.audius-d solana-test-validator.devnet.audius-d'
grep -q "$audius_hosts" /etc/hosts || sudo tee -a /etc/hosts \<<<$audius_hosts
- run:
name: Stand up devnet
command: |
cd ~/audius-d
IMAGE_TAG="$(sha1sum ./Dockerfile | awk '{print $1}')"
audius-ctl config create-context devnet -f configs/templates/devnet.toml
# TODO
docker network create --subnet=172.100.0.0/16 --gateway=172.100.0.1 deployments_devnet
audius-ctl devnet
audius-ctl register
audius-ctl up --await-healthy --audius-d-version $IMAGE_TAG
- run:
name: Inspect docker (for debugging)
name: Test context
command: |
docker ps -a
docker network inspect deployments_devnet
- basic-health-check:
host: 'https://creator-1.devnet.audius-d'
jqkey: '.data.healthy'
- basic-health-check:
host: 'https://discovery-1.devnet.audius-d'
jqkey: '.data.discovery_provider_healthy'
- basic-health-check:
host: 'https://identity-1.devnet.audius-d'
jqkey: '.healthy'
cd ~/audius-d
audius-ctl test context
- run:
name: Teardown
command: |
Expand Down Expand Up @@ -297,10 +215,6 @@ workflows:
context: github
requires:
- build
- test-devnet-deps:
context: github
requires:
- build
- test-config-subcommands:
context: github
requires:
Expand All @@ -309,7 +223,6 @@ workflows:
context: github
requires:
- test-audius-d-devnet
- test-devnet-deps
- test-config-subcommands
filters:
branches:
Expand Down
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# audius-d

run your own node.
Run your own node.

## Installation
### Latest release
Expand Down Expand Up @@ -45,15 +45,15 @@ Run Audius nodes and chains in a sandbox on your local machine.

Devnet uses a local nginx container on 80/443 to act as a layer 7 load balancer. Hence we need to add the hosts so we may intelligently route on localhost.
```
sh -c 'echo "127.0.0.1 creator-1.devnet.audius-d discovery-1.devnet.audius-d identity-1.devnet.audius-d eth-ganache.devnet.audius-d acdc-ganache.devnet.audius-d solana-test-validator.devnet.audius-d" >> /etc/hosts'
sudo sh -c 'echo "127.0.0.1 creator-1.devnet.audius-d discovery-1.devnet.audius-d identity.devnet.audius-d eth-ganache.devnet.audius-d acdc-ganache.devnet.audius-d solana-test-validator.devnet.audius-d" >> /etc/hosts'
```

Instruct audius-ctl what services to create and how to configure them. More on this concept below.
```
audius-ctl config create-context devnet -f configs/templates/devnet.toml
```

Optionally, install the devnet certificate to avoid https warnings when connecting to local nodes
Install the devnet certificate to avoid https warnings when connecting to local nodes
```
# MacOS
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain deployments/tls/devnet-cert.pem
Expand All @@ -68,22 +68,15 @@ Stand up audius nodes
audius-ctl up
```

Visit local health checks to verify it is all working.
Test context to verify it is all working.
```
# TODO: audius-ctl config test-context
curl -s https://creator-1.devnet.audius-d/health_check | jq .data.healthy
true
curl -s https://discovery-1.devnet.audius-d/health_check | jq .data.discovery_provider_healthy
true
curl -s https://identity-1.devnet.audius-d/health_check | jq .healthy
true
audius-ctl test context
...
https://creator-1.audius-d [ /health_check .data.healthy ] true
https://discovery-1.audius-d [ /health_check .data.discovery_provider_healthy ] true
https://identity.audius-d [ /health_check .healthy ] true
```

Note: if you choose not to install the devnet.audius-d certificate, use `curl -sk`

## Run

### Run installed binary
Expand Down
11 changes: 0 additions & 11 deletions caddy-root.crt

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/audius-ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
},
}
rootCmd.Flags().BoolVar(&displayVersion, "version", false, "Display version info")
rootCmd.AddCommand(upCmd, downCmd, devnetCmd, registerCmd, configCmd, guiCmd, sbCmd, emCmd, hashCmd)
rootCmd.AddCommand(configCmd, devnetCmd, downCmd, emCmd, guiCmd, hashCmd, registerCmd, sbCmd, testCmd, upCmd)

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
Expand Down
58 changes: 58 additions & 0 deletions cmd/audius-ctl/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"

"github.com/AudiusProject/audius-d/pkg/conf"
"github.com/AudiusProject/audius-d/pkg/logger"
"github.com/AudiusProject/audius-d/pkg/test"
"github.com/spf13/cobra"
)

var (
testCmd = &cobra.Command{
Use: "test [command]",
Short: "test audius-d connectivity",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}

testContextCmd = &cobra.Command{
Use: "context",
Short: "Test the health of the current context",
SilenceUsage: true, // do not print --help text on failed node health
RunE: func(cmd *cobra.Command, args []string) error {
ctxConfig, err := conf.ReadOrCreateContextConfig()
if err != nil {
return logger.Error("Failed to retrieve context. ", err)
}

responses, err := test.CheckNodeHealth(ctxConfig)
if err != nil {
return err
}

var encounteredError bool
for _, response := range responses {
if response.Error != nil {
fmt.Printf("%-50s Error: %v\n", response.Host, response.Error)
encounteredError = true
} else {
fmt.Printf("%-50s %t\n", response.Host, response.Result)
}
}

if encounteredError {
return fmt.Errorf("\none or more health checks failed")
}

return nil
},
}
)

func init() {
testCmd.AddCommand(testContextCmd)
}
12 changes: 6 additions & 6 deletions configs/templates/devnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ example and runnable file for running a devnet configuration of audius protocol
[Network]
DeployOn = "devnet"

[IdentityService.identity]
HttpPort = 7000
HttpsPort = 7001
Host = "https://identity.devnet.audius-d"
Version = "prerelease"

[CreatorNodes.creator-1]
HttpPort = 4000
HttpsPort = 4001
Expand All @@ -23,9 +29,3 @@ Version = "prerelease"
OperatorPrivateKey = "d09ba371c359f10f22ccda12fd26c598c7921bda3220c9942174562bc6a36fe8"
OperatorWallet = "0x73EB6d82CFB20bA669e9c178b718d770C49BB52f"
OperatorRewardsWallet = "0x73EB6d82CFB20bA669e9c178b718d770C49BB52f"

[IdentityService.identity-1]
HttpPort = 7000
HttpsPort = 7001
Host = "https://identity-1.devnet.audius-d"
Version = "prerelease"
3 changes: 0 additions & 3 deletions daemon.json

This file was deleted.

4 changes: 2 additions & 2 deletions deployments/nginx_ingress.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ server {

server {
listen 443 ssl;
server_name identity-1.devnet.audius-d;
server_name identity.devnet.audius-d;

ssl_certificate /tmp/cert.pem;
ssl_certificate_key /tmp/key.pem;

location / {
resolver 127.0.0.11 valid=30s;
set $upstream http://identity-1:7000;
set $upstream http://identity:7000;

proxy_pass $upstream;

Expand Down
2 changes: 1 addition & 1 deletion deployments/tls/devnet.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subjectAltName = @alt_names
[alt_names]
DNS.1 = creator-1.devnet.audius-d
DNS.2 = discovery-1.devnet.audius-d
DNS.3 = identity-1.devnet.audius-d
DNS.3 = identity.devnet.audius-d
DNS.4 = eth-ganache.devnet.audius-d
DNS.5 = acdc-ganache.devnet.audius-d
DNS.6 = solana-test-validator.devnet.audius-d
Expand Down
30 changes: 18 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ require (
github.com/labstack/echo/v4 v4.11.3
github.com/multiformats/go-multihash v0.2.3
github.com/speps/go-hashids/v2 v2.0.1
github.com/spf13/cobra v1.5.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
)

require github.com/caseymrm/askm v1.0.0 // indirect
require (
github.com/caseymrm/askm v1.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand All @@ -25,7 +31,7 @@ require (
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.5.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand All @@ -34,7 +40,7 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -65,14 +71,14 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.6 // indirect
Expand Down
Loading

0 comments on commit 1c672e8

Please sign in to comment.