-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide contract address via http (#2303)
* Add contract-address webserver * add comment * printf
- Loading branch information
1 parent
b374254
commit 79bc40d
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |