Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 .docker/Dockerfile.distroless
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ RUN apt update && \
mkdir /var/lib/polymesh && \
chown 4001:4001 /var/lib/polymesh

FROM busybox:stable-uclibc as busybox

FROM gcr.io/distroless/cc
USER 4001:4001

# Distroless doesn't have a shell, which is needed for the health check.
COPY --from=busybox /bin/sh /bin/sh
COPY --from=install /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1
COPY --from=install --chown=4001:4001 /var/lib/polymesh /var/lib/polymesh
COPY --chown=4002:4002 --from=gobuild /opt/health-check/polymesh-health-check /usr/local/bin/check
Expand Down
4 changes: 4 additions & 0 deletions .docker/arm64/Dockerfile.distroless
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ RUN apt update && \
mkdir /var/lib/polymesh && \
chown 4001:4001 /var/lib/polymesh

FROM busybox:stable-uclibc as busybox

FROM gcr.io/distroless/cc
USER 4001:4001

# Distroless doesn't have a shell, which is needed for the health check.
COPY --from=busybox /bin/sh /bin/sh
COPY --from=install /lib/aarch64-linux-gnu/libz.so.1 /lib/aarch64-linux-gnu/libz.so.1
COPY --from=install --chown=4001:4001 /var/lib/polymesh /var/lib/polymesh
COPY --chown=4002:4002 --from=gobuild /opt/health-check/polymesh-health-check /usr/local/bin/check
Expand Down
125 changes: 62 additions & 63 deletions .docker/src/health-check/health-check.go
Original file line number Diff line number Diff line change
@@ -1,88 +1,87 @@
package main

import (
"fmt"
"os"
"github.com/AdamSLevy/jsonrpc2/v14"
"net/http"
"io/ioutil"
"fmt"
"io/ioutil"
"net/http"
"os"

"github.com/AdamSLevy/jsonrpc2/v14"
)

type systemHealth struct {
IsSyncing bool `json:"isSyncing"`
Peers float64 `json:"peers"`
ShouldHavePeers bool `json:"shouldHavePeers"`
IsSyncing bool `json:"isSyncing"`
Peers float64 `json:"peers"`
ShouldHavePeers bool `json:"shouldHavePeers"`
}


func testJSONRPC(readinessCheck bool) {
var c jsonrpc2.Client
params := []float64{}
var r systemHealth
err := c.Request(nil, "http://localhost:9933", "system_health", params, &r)
if _, ok := err.(jsonrpc2.Error); ok {
fmt.Printf("Error checking jsonrpc port. %v\n", err)
os.Exit(1)
}
if err != nil {
fmt.Printf("Error checking jsonrpc port! %v\n", err)
os.Exit(1)
}
//fmt.Printf("Node syncing: %v\n", r.IsSyncing )
//fmt.Printf("Should have peers: %v\n", r.ShouldHavePeers )
//fmt.Printf("Number of peers: %v\n", r.Peers )
if r.IsSyncing && readinessCheck {
fmt.Printf("Node is syncing" )
os.Exit(1)
}
var c jsonrpc2.Client
params := []float64{}
var r systemHealth
err := c.Request(nil, "http://localhost:9944", "system_health", params, &r)
if _, ok := err.(jsonrpc2.Error); ok {
fmt.Printf("Error checking jsonrpc port. %v\n", err)
os.Exit(1)
}
if err != nil {
fmt.Printf("Error checking jsonrpc port! %v\n", err)
os.Exit(1)
}
//fmt.Printf("Node syncing: %v\n", r.IsSyncing )
//fmt.Printf("Should have peers: %v\n", r.ShouldHavePeers )
//fmt.Printf("Number of peers: %v\n", r.Peers )
if r.IsSyncing && readinessCheck {
fmt.Printf("Node is syncing")
os.Exit(1)
}
}

func testPrometheus() {
resp, err := http.Get("http://localhost:9615/metrics")
if err != nil {
fmt.Printf( "Error checking prometheus exporter! %v\n", err )
os.Exit(1)
}
defer resp.Body.Close()
_, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
fmt.Printf( "Error reading prometheus metrics! %v\n", err2 )
os.Exit(1)
}
if resp.StatusCode > 299 {
fmt.Printf("Response status is %v", resp.StatusCode )
os.Exit(1)
}
resp, err := http.Get("http://localhost:9615/metrics")
if err != nil {
fmt.Printf("Error checking prometheus exporter! %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
_, err2 := ioutil.ReadAll(resp.Body)
if err2 != nil {
fmt.Printf("Error reading prometheus metrics! %v\n", err2)
os.Exit(1)
}
if resp.StatusCode > 299 {
fmt.Printf("Response status is %v", resp.StatusCode)
os.Exit(1)
}
}

func printHelp(progname string) {
fmt.Printf(`Use:
fmt.Printf(`Use:
%v [command]
Commands:
* help: print this help
* liveness: return 0 if localhost polymesh has both the RPC (9933) and prometheus (9615) ports open and responsive, 1 otherwise
* liveness: return 0 if localhost polymesh has both the WS/RPC (9944) and prometheus (9615) ports open and responsive, 1 otherwise
* readiness: return 0 if liveness check passes and the node is not syncing, 1 otherwise
`, progname)
}

func main() {
args := os.Args
if len(args) != 2 {
printHelp(args[0])
os.Exit(1)
}
if args[1] == "liveness" {
testJSONRPC(false)
} else if args[1] == "readiness" {
testJSONRPC(true)
} else if args[1] == "help" {
printHelp(args[0])
os.Exit(0)
} else {
printHelp(args[0])
os.Exit(1)
}
args := os.Args
if len(args) != 2 {
printHelp(args[0])
os.Exit(1)
}
if args[1] == "liveness" {
testJSONRPC(false)
} else if args[1] == "readiness" {
testJSONRPC(true)
} else if args[1] == "help" {
printHelp(args[0])
os.Exit(0)
} else {
printHelp(args[0])
os.Exit(1)
}

testPrometheus()
testPrometheus()
}

34 changes: 17 additions & 17 deletions .docker/src/rotate-keys/rotate-keys.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package main

import (
"fmt"
"os"
"github.com/AdamSLevy/jsonrpc2/v14"
"fmt"
"os"

"github.com/AdamSLevy/jsonrpc2/v14"
)

func main() {
var c jsonrpc2.Client
params := []float64{}
var r string
err := c.Request(nil, "http://localhost:9933", "author_rotateKeys", params, &r)
if _, ok := err.(jsonrpc2.Error); ok {
fmt.Printf("Error checking jsonrpc port. %v\n", err)
os.Exit(1)
}
if err != nil {
fmt.Printf("Error checking jsonrpc port! %v\n", err)
os.Exit(1)
}
fmt.Println(r)
var c jsonrpc2.Client
params := []float64{}
var r string
err := c.Request(nil, "http://localhost:9944", "author_rotateKeys", params, &r)
if _, ok := err.(jsonrpc2.Error); ok {
fmt.Printf("Error checking jsonrpc port. %v\n", err)
os.Exit(1)
}
if err != nil {
fmt.Printf("Error checking jsonrpc port! %v\n", err)
os.Exit(1)
}
fmt.Println(r)
}