web: integrate with Tilt deployment

This commit is contained in:
Leo 2020-11-10 19:39:32 +01:00
parent 6cc3495ac5
commit db63c3efbc
4 changed files with 101 additions and 5 deletions

View File

@ -7,15 +7,19 @@ The following dependencies are required for local development:
- [Go](https://golang.org/dl/) >= 1.15.3
- [Docker](https://docs.docker.com/engine/install/) / moby-engine >= 19.03
- [Tilt](http://tilt.dev/) >= 0.17.2
- Any of the local Kubernetes clusters supported by Tilt
(we recommend [minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/) in the default config).
- Any of the local Kubernetes clusters supported by Tilt.
We recommend [minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/) with the kvm2 driver.
See the [Tilt docs](https://docs.tilt.dev/install.html) docs on how to set up your local cluster -
it won't take more than a few minutes to set up! Example minikube invocation, adjust limits as needed:
minikube start --cpus=8 --memory=8G --disk-size=50G --driver=kvm2
npm wants to set up an insane number of inotify watches in the web container which may exceed kernel limits.
The minikube default is too low, adjust it like this:
minikube ssh 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p'
This should work on Linux, MacOS and possibly even Windows.
After installing all dependencies, just run `tilt up --update-mode=exec`.
@ -25,6 +29,8 @@ Specify number of guardians nodes to run (default is five):
tilt up --update-mode=exec -- --num=1
## Usage
Watch pod status in your cluster:
kubectl get pod -A -w

View File

@ -95,7 +95,11 @@ docker_build(
k8s_yaml("devnet/solana-devnet.yaml")
k8s_resource("solana-devnet")
k8s_resource("solana-devnet", port_forwards=[
port_forward(8899, name="Solana RPC [:8899]"),
port_forward(8900, name="Solana WS [:8900]"),
port_forward(9000, name="Solana PubSub [:9000]"),
])
# eth devnet
@ -119,4 +123,26 @@ docker_build(
k8s_yaml("devnet/eth-devnet.yaml")
k8s_resource("eth-devnet")
k8s_resource("eth-devnet", port_forwards=[
port_forward(8545, name="Ganache RPC [:8545]")
])
# web frontend
docker_build(
ref = "web",
context = "./web",
dockerfile = "./web/Dockerfile",
ignore = ["./web/node_modules"],
live_update = [
sync("./web/src", "/home/node/app/src"),
sync("./web/public", "/home/node/app/public"),
sync("./web/contracts", "/home/node/app/contracts"),
],
)
k8s_yaml("devnet/web.yaml")
k8s_resource("web", port_forwards=[
port_forward(3000, name="Experimental Web UI [:3000]")
])

43
devnet/web.yaml Normal file
View File

@ -0,0 +1,43 @@
---
apiVersion: v1
kind: Service
metadata:
name: web
labels:
app: web
spec:
ports:
- port: 3000
name: rpc
protocol: TCP
clusterIP: None
selector:
app: web
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: web
serviceName: web
replicas: 1
template:
metadata:
labels:
app: web
spec:
terminationGracePeriodSeconds: 1
containers:
- name: web
image: web
command:
- /usr/local/bin/npm
- start
tty: true
ports:
- containerPort: 3000
name: react-devserver
protocol: TCP

21
web/Dockerfile Normal file
View File

@ -0,0 +1,21 @@
# syntax=docker/dockerfile:experimental
# Derivative of ethereum/Dockerfile, look there for an explanation on how it works.
FROM node:lts-alpine
USER 1000
RUN mkdir -p /home/node/app
RUN mkdir -p /home/node/.npm
WORKDIR /home/node/app
ADD --chown=node:node package.json .
ADD --chown=node:node package-lock.json .
RUN --mount=type=cache,uid=1000,gid=1000,target=/home/node/.npm \
--mount=type=cache,uid=1000,gid=1000,target=node_modules \
npm install && \
cp -r node_modules node_modules_cache
RUN rmdir node_modules && mv node_modules_cache node_modules
ADD --chown=node:node . .