Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified HTML landing page (NOT a dashboard!) #531

Merged
merged 12 commits into from
Sep 12, 2024
51 changes: 51 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Quick run

## Installation

Either install warnet via pip, or clone the source and install:

### via pip

You can install warnet via `pip` into a virtual environment with

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install warnet
```

### via cloned source

You can install warnet from source into a virtual environment with

```bash
git clone https://github.com/bitcoin-dev-project/warnet.git
cd warnet
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
```

## Running

To get started first check you have all the necessary requirements:

```bash
warnet setup
```

Then create your first network:

```bash
# Create a new network in the current directory
warnet init

# Or in a directory of choice
warnet new <directory>
```

Follow the guide to configure network variables.

## fork-observer

If you enabled [fork-observer](https://github.com/0xB10C/fork-observer), it will be available from the landing page at `localhost:2019`.
23 changes: 23 additions & 0 deletions resources/charts/caddy/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions resources/charts/caddy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: caddy-server
description: A Helm chart for Caddy

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: 0.1.0
1 change: 1 addition & 0 deletions resources/charts/caddy/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Caddy is serving your every need.
57 changes: 57 additions & 0 deletions resources/charts/caddy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "caddy.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "caddy.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "caddy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "caddy.labels" -}}
helm.sh/chart: {{ include "caddy.chart" . }}
{{ include "caddy.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "caddy.selectorLabels" -}}
app.kubernetes.io/name: {{ include "caddy.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "caddy.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "caddy.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions resources/charts/caddy/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "caddy.fullname" . }}
labels:
{{- include "caddy.labels" . | nindent 4 }}
data:
Caddyfile: |
{{- .Values.caddyConfig | nindent 4 }}
index: |
{{- .Values.htmlConfig | nindent 4 }}
38 changes: 38 additions & 0 deletions resources/charts/caddy/templates/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Pod
metadata:
name: {{ include "caddy.fullname" . }}
labels:
{{- include "caddy.labels" . | nindent 4 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
app: {{ include "caddy.fullname" . }}
spec:
restartPolicy: "{{ .Values.restartPolicy }}"
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 4 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: web
containerPort: {{ .Values.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 8 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 8 }}
resources:
{{- toYaml .Values.resources | nindent 8 }}
volumeMounts:
{{- toYaml .Values.volumeMounts | nindent 8 }}
volumes:
{{- toYaml .Values.volumes | nindent 4 }}
16 changes: 16 additions & 0 deletions resources/charts/caddy/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "caddy.fullname" . }}
labels:
{{- include "caddy.labels" . | nindent 4 }}
app: {{ include "caddy.fullname" . }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.port }}
targetPort: web
protocol: TCP
name: http
selector:
{{- include "caddy.selectorLabels" . | nindent 4 }}
123 changes: 123 additions & 0 deletions resources/charts/caddy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Default values for caddy.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
namespace: warnet

restartPolicy: Always

image:
repository: caddy
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "2.8.4"

imagePullSecrets: []

nameOverride: ""

fullnameOverride: ""

podLabels:
app: "warnet"
mission: "proxy"

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

livenessProbe:
httpGet:
path: /live
port: 80
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 1

readinessProbe:
httpGet:
path: /ready
port: 80
failureThreshold: 1
periodSeconds: 1
successThreshold: 1
timeoutSeconds: 1

volumes:
- name: caddy-config
configMap:
name: caddy
items:
- key: Caddyfile
path: Caddyfile
- key: index
path: index

volumeMounts:
- name: caddy-config
mountPath: /etc/caddy/Caddyfile
subPath: Caddyfile
- name: caddy-config
mountPath: /usr/share/caddy/index.html
subPath: index

port: 80

caddyConfig: |
:80 {
respond /live 200
respond /ready 200

root * /usr/share/caddy
file_server

handle_path /fork-observer/* {
reverse_proxy fork-observer:2323
}

handle_path /grafana/* {
reverse_proxy loki-grafana:80
}

}

htmlConfig: |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Welcome to the Warnet dashboard</h1>
<p>You can access the following services:</p>
<ul>
<li><a href="/grafana/">Grafana</a></li>
<li><a href="/fork-observer/">Fork Observer</a></li>
</ul>
</body>
</html>
6 changes: 1 addition & 5 deletions resources/charts/fork-observer/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
To view forkobserver you must forward the port from the cluster to your local machine

kubectl port-forward fork-observer 2323

fork-observer will then be available at web address: http://localhost:2323
Fork observer enabled.
3 changes: 3 additions & 0 deletions resources/manifests/grafana_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ grafana.ini:
auth:
disable_login_form: true
disable_signout_menu: true
server:
# this is required to use Grafana behind a reverse proxy (caddy)
root_url: "%(protocol)s://%(domain)s:%(http_port)s/grafana/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my own understanding, grafana stuff is in manifests/ for legacy reasons, yeah? was surprised its not also being deployed by helm (not a blocker for this PR tho)

auth.anonymous:
enabled: true
org_name: Main Org.
Expand Down
4 changes: 3 additions & 1 deletion resources/networks/6_node_bitcoin/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ nodes:
- tank-0006
- name: tank-0006
fork_observer:
enabled: false
enabled: true
caddy:
enabled: true
4 changes: 4 additions & 0 deletions src/warnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
]

DEFAULT_NAMESPACE = "warnet"
LOGGING_NAMESPACE = "warnet-logging"
HELM_COMMAND = "helm upgrade --install --create-namespace"

# Directories and files for non-python assets, e.g., helm charts, example scenarios, default configs
Expand All @@ -32,6 +33,9 @@
FORK_OBSERVER_CHART = str(CHARTS_DIR.joinpath("fork-observer"))
COMMANDER_CHART = str(CHARTS_DIR.joinpath("commander"))
NAMESPACES_CHART_LOCATION = CHARTS_DIR.joinpath("namespaces")
FORK_OBSERVER_CHART = str(files("resources.charts").joinpath("fork-observer"))
CADDY_CHART = str(files("resources.charts").joinpath("caddy"))

DEFAULT_NETWORK = Path("6_node_bitcoin")
DEFAULT_NAMESPACES = Path("two_namespaces_two_users")

Expand Down
Loading