diff --git a/k8s/beacon-chain/contract-address.yaml b/k8s/beacon-chain/contract-address.yaml new file mode 100644 index 0000000000..55d98427fa --- /dev/null +++ b/k8s/beacon-chain/contract-address.yaml @@ -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 diff --git a/tools/contract-addr/BUILD.bazel b/tools/contract-addr/BUILD.bazel new file mode 100644 index 0000000000..5ac5cf8ffe --- /dev/null +++ b/tools/contract-addr/BUILD.bazel @@ -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"], +) diff --git a/tools/contract-addr/main.go b/tools/contract-addr/main.go new file mode 100644 index 0000000000..77bd340ebd --- /dev/null +++ b/tools/contract-addr/main.go @@ -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) + } +}