mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Provide contract address via http (#2303)
* Add contract-address webserver * add comment * printf
This commit is contained in:
committed by
Raul Jordan
parent
b3742544ee
commit
79bc40dcbe
74
k8s/beacon-chain/contract-address.yaml
Normal file
74
k8s/beacon-chain/contract-address.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: contract-address-http
|
||||
namespace: beacon-chain
|
||||
labels:
|
||||
app: beacon-chain
|
||||
component: contract-address-http
|
||||
version: v1
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: beacon-chain
|
||||
component: contract-address-http
|
||||
version: v1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: beacon-chain
|
||||
component: contract-address-http
|
||||
version: v1
|
||||
spec:
|
||||
priorityClassName: production-priority
|
||||
containers:
|
||||
- name: site
|
||||
image: gcr.io/prysmaticlabs/prysm/contract-addr:latest
|
||||
args:
|
||||
- --address-path=/etc/address/DEPOSIT_CONTRACT_ADDRESS
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: config-volume
|
||||
mountPath: /etc/address
|
||||
volumes:
|
||||
- name: config-volume
|
||||
configMap:
|
||||
name: beacon-config
|
||||
---
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: contract-address-http
|
||||
namespace: beacon-chain
|
||||
spec:
|
||||
selector:
|
||||
app: beacon-chain
|
||||
component: contract-address-http
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
name: http
|
||||
type: ClusterIP
|
||||
---
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: contract-address-http
|
||||
namespace: istio-system
|
||||
spec:
|
||||
hosts:
|
||||
- beta.prylabs.net
|
||||
gateways:
|
||||
- prylabs-wildcard-gateway
|
||||
http:
|
||||
- match:
|
||||
- uri:
|
||||
prefix: /contract
|
||||
route:
|
||||
- destination:
|
||||
port:
|
||||
number: 8080
|
||||
host: contract-address-http.beacon-chain.svc.cluster.local
|
||||
42
tools/contract-addr/BUILD.bazel
Normal file
42
tools/contract-addr/BUILD.bazel
Normal file
@@ -0,0 +1,42 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/tools/contract-addr",
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "contract-addr",
|
||||
embed = [":go_default_library"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "image",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/tools/contract-addr",
|
||||
visibility = ["//visibility:private"],
|
||||
static = "on",
|
||||
tags = ["manual"],
|
||||
goarch = "amd64",
|
||||
goos = "linux",
|
||||
deps = [
|
||||
],
|
||||
race = "off",
|
||||
pure = "on",
|
||||
)
|
||||
|
||||
container_push(
|
||||
name = "push_image",
|
||||
format = "Docker",
|
||||
image = ":image",
|
||||
registry = "gcr.io",
|
||||
repository = "prysmaticlabs/prysm/contract-addr",
|
||||
tag = "latest",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
43
tools/contract-addr/main.go
Normal file
43
tools/contract-addr/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* This tool exists to serve currently configured contract address in k8s.
|
||||
* It reads the contract address from a plain text file as provided by etcd.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var address = flag.String("address-path", "", "The file path to the plain text file with the contract address")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *address == "" {
|
||||
panic("Contract address filepath not set")
|
||||
}
|
||||
|
||||
fmt.Println("Starting on port 8080")
|
||||
|
||||
if err := http.ListenAndServe(":8080", &handler{}); err != nil {
|
||||
panic("Failed to run server: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type handler struct{}
|
||||
|
||||
func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
dat, err := ioutil.ReadFile(*address)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.WriteString(w, string(dat))
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to write response: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user