Skip to content

Commit e5c7df2

Browse files
authored
Merge pull request #419 from willcl-ark/package-fixups
`warcli cluster` refactors
2 parents bf9eff1 + b0e5023 commit e5c7df2

File tree

10 files changed

+349
-232
lines changed

10 files changed

+349
-232
lines changed

docs/quickrun.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,66 @@
11
# Quick run
22

3-
Warnet runs a server which can be used to manage multiple networks. On docker
4-
this runs locally, but on Kubernetes this runs as a `statefulSet` in the
5-
cluster.
3+
## Installation
64

7-
If the `$XDG_STATE_HOME` environment variable is set, the server will log to
8-
a file `$XDG_STATE_HOME/warnet/warnet.log`, otherwise it will use `$HOME/.warnet/warnet.log`.
5+
Either install warnet via pip, or clone the source and install:
96

10-
## Quick start via pip
7+
### via pip
118

12-
You can install warnet via `pip` into your virtual environment with
9+
You can install warnet via `pip` into a virtual environment with
1310

1411
```bash
1512
python3 -m venv .venv
1613
source .venv/bin/activate
1714
pip install warnet
1815
```
1916

20-
Following installation `warcli` commands will operate natively on the Kubernetes cluster currently configured with `kubectl`.
17+
### via cloned source
2118

22-
Starting the Warnet server is as easy as:
19+
You can install warnet from source into a virtual environment with
2320

2421
```bash
25-
# (optional) if using a local minikube cluster check that we have all required programs installed
26-
warcli setup
22+
git clone https://github.com/bitcoin-dev-project/warnet.git
23+
cd warnet
24+
python3 -m venv .venv
25+
source .venv/bin/activate
26+
pip install -e .
27+
```
28+
29+
## Running
30+
31+
> [!TIP]
32+
> When developing locally add the `--dev` flag to `warcli cluster deploy` to enable dev mode with hot-reloading server.
33+
34+
### Using minikube
35+
36+
To run a local cluster using minikube:
37+
38+
```bash
39+
warcli cluster setup-minikube
2740

28-
# (optional) if using a local minikube cluster, set it up
29-
warcli cluster minikube-setup
41+
warcli cluster deploy
42+
```
43+
44+
### Other cluster types
3045

46+
If not using minikube (e.g. using Docker Desktop or a managed cluster), `warcli` commands will operate natively on the current Kubernetes context, so you can simply run:
47+
48+
```bash
3149
warcli cluster deploy
3250
```
3351

34-
This also automatically configures port forwarding to the Server in the cluster.
52+
...to deploy warnet to your cluster.
53+
54+
`warcli deploy` also automatically configures port forwarding to the Server in the cluster.
55+
56+
## Stopping
3557

3658
To tear down the cluster:
3759

3860
```bash
3961
warcli cluster teardown
62+
```
4063

41-
# (optional) if using a local minikube cluster, remove the image
42-
warcli cluster minikube-clean
43-
64+
## Log location
4465

66+
If the `$XDG_STATE_HOME` environment variable is set, the server will log to a file `$XDG_STATE_HOME/warnet/warnet.log`, otherwise it will use `$HOME/.warnet/warnet.log`.

docs/warcli.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ options:
2626
|----------|--------|------------|-----------|
2727
| commands | String | | |
2828

29+
### `warcli setup`
30+
Check Warnet requirements are installed
31+
32+
2933
## Bitcoin
3034

3135
### `warcli bitcoin debug-log`
@@ -69,16 +73,20 @@ options:
6973

7074
## Cluster
7175

72-
### `warcli cluster deploy`
73-
Setup Warnet using the current kubectl-configured cluster
76+
### `warcli cluster connect-logging`
77+
Connect kubectl to cluster logging
7478

7579

76-
### `warcli cluster minikube-clean`
77-
Reinit minikube images
80+
### `warcli cluster deploy`
81+
Deploy Warnet using the current kubectl-configured cluster
7882

83+
options:
84+
| name | type | required | default |
85+
|--------|--------|------------|-----------|
86+
| dev | Bool | | False |
7987

80-
### `warcli cluster minikube-setup`
81-
Setup minikube for use with Warnet
88+
### `warcli cluster deploy-logging`
89+
Deploy logging configurations to the cluster using helm
8290

8391

8492
### `warcli cluster port-start`
@@ -89,6 +97,14 @@ Port forward (runs as a detached process)
8997
Stop the port forwarding process
9098

9199

100+
### `warcli cluster setup-minikube`
101+
Configure a local minikube cluster
102+
103+
options:
104+
| name | type | required | default |
105+
|--------|--------|------------|-----------|
106+
| clean | Bool | | False |
107+
92108
### `warcli cluster teardown`
93109
Stop the warnet server and tear down the cluster
94110

justfile

Lines changed: 16 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,30 @@
11
set shell := ["bash", "-uc"]
2+
default_cpus := "4"
3+
default_memory := "4000"
24

35
[private]
46
default:
57
just --list
68

7-
cluster:
8-
kubectl apply -f resources/manifests/namespace.yaml
9-
kubectl apply -f resources/manifests/rbac-config.yaml
10-
kubectl apply -f resources/manifests/warnet-rpc-service.yaml
11-
kubectl apply -f resources/manifests/warnet-rpc-statefulset.yaml
9+
# Configure a minikube k8s cluster
10+
minikube cpus=default_cpus memory=default_memory:
11+
WAR_RPC="./resources/images/rpc" WAR_CPU={{ cpus }} WAR_MEM={{ memory }} ./resources/scripts/setup_minikube.sh
1212

13-
# Setup and start the RPC in dev mode with minikube
14-
start:
15-
#!/usr/bin/env bash
16-
set -euxo pipefail
13+
# Deploy Warnet in dev mode
14+
deploy:
15+
WAR_MANIFESTS="./resources/manifests" WAR_DEV=1 ./resources/scripts/deploy.sh
1716

18-
# Function to check if minikube is running
19-
check_minikube() {
20-
minikube status | grep -q "Running" && echo "Minikube is already running" || minikube start --mount --mount-string="$PWD:/mnt/src"
21-
}
22-
23-
# Function to check if warnet-rpc container is already running
24-
check_warnet_rpc() {
25-
if kubectl get pods --all-namespaces | grep -q "bitcoindevproject/warnet-rpc"; then
26-
echo "warnet-rpc already running in minikube"
27-
exit 1
28-
fi
29-
}
30-
31-
# Check minikube status
32-
check_minikube
33-
34-
# Build image in local registry and load into minikube
35-
docker build -t warnet/dev -f resources/images/rpc/Dockerfile_dev resources/images/rpc --load
36-
minikube image load warnet/dev
37-
38-
# Setup k8s
39-
kubectl apply -f resources/manifests/namespace.yaml
40-
kubectl apply -f resources/manifests/rbac-config.yaml
41-
kubectl apply -f resources/manifests/warnet-rpc-service.yaml
42-
kubectl apply -f resources/manifests/warnet-rpc-statefulset-dev.yaml
43-
kubectl config set-context --current --namespace=warnet
44-
45-
# Check for warnet-rpc container
46-
check_warnet_rpc
47-
48-
until kubectl get pod rpc-0 --namespace=warnet; do
49-
echo "Waiting for server to find pod rpc-0..."
50-
sleep 4
51-
done
52-
53-
echo "⏲️ This could take a minute or so."
54-
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
55-
56-
echo Done...
57-
58-
# Stop the RPC in dev mode with minikube
59-
stop:
60-
#!/usr/bin/env bash
61-
set -euxo pipefail
62-
63-
kubectl delete namespace warnet
64-
kubectl delete namespace warnet-logging --ignore-not-found
65-
kubectl config set-context --current --namespace=default
66-
67-
minikube image rm warnet/dev
68-
69-
# Setup and start the RPC in dev mode with Docker Desktop
70-
startd:
71-
docker build -t warnet/dev -f resources/images/rpc/Dockerfile_dev resources/images/rpc --load
72-
kubectl apply -f resources/manifests/namespace.yaml
73-
kubectl apply -f resources/manifests/rbac-config.yaml
74-
kubectl apply -f resources/manifests/warnet-rpc-service.yaml
75-
sed 's?/mnt/src?'`PWD`'?g' resources/manifests/warnet-rpc-statefulset-dev.yaml | kubectl apply -f -
76-
kubectl config set-context --current --namespace=warnet
77-
78-
echo waiting for rpc to come online
79-
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
80-
81-
echo Done...
82-
83-
# Stop the RPC in dev mode with Docker Desktop
84-
stopd:
85-
# Delete all resources
86-
kubectl delete namespace warnet
87-
kubectl delete namespace warnet-logging --ignore-not-found
88-
kubectl config set-context --current --namespace=default
89-
90-
echo Done...
17+
# Stop and teardown warnet
18+
teardown:
19+
./resources/scripts/stop.sh
9120

9221
# port forward
9322
p:
9423
kubectl port-forward svc/rpc 9276:9276
9524

25+
# Quick start for minikube local dev
26+
qs: minikube deploy p
27+
9628
registry := 'bitcoindevproject/bitcoin'
9729
repo := 'bitcoin/bitcoin'
9830
arches := 'amd64,arm64'
@@ -104,10 +36,10 @@ build branch tag registry=registry repo=repo build-args=build-args action=load:
10436
warcli image build --registry={{registry}} --repo={{repo}} --branch={{branch}} --arches="{{arches}}" --tag={{tag}} --build-args="{{build-args}}" --action={{action}}
10537

10638
installlogging:
107-
resources/scripts/install_logging.sh
39+
./resources/scripts/install_logging.sh
10840

10941
connectlogging:
110-
resources/scripts/connect_logging.sh
42+
./resources/scripts/connect_logging.sh
11143

11244
# Format and lint all files
11345
lint:

resources/scripts/deploy.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
5+
if [ -z "${WAR_MANIFESTS+x}" ]; then
6+
echo "WAR_MANIFESTS is unset. Please provide a path to warnet manifests."
7+
exit 1
8+
fi
9+
10+
# Function to check if warnet-rpc container is already running
11+
check_warnet_rpc() {
12+
if kubectl get pods --all-namespaces | grep -q "bitcoindevproject/warnet-rpc"; then
13+
echo "warnet-rpc pod found"
14+
exit 1
15+
fi
16+
}
17+
18+
# Deploy base configurations
19+
kubectl apply -f "$WAR_MANIFESTS/namespace.yaml"
20+
kubectl apply -f "$WAR_MANIFESTS/rbac-config.yaml"
21+
kubectl apply -f "$WAR_MANIFESTS/warnet-rpc-service.yaml"
22+
23+
# Deploy rpc server
24+
if [ -n "${WAR_DEV+x}" ]; then # Dev mode selector
25+
# Build image in local registry
26+
docker build -t warnet/dev -f "$WAR_RPC/Dockerfile_dev" "$WAR_RPC" --load
27+
if [ "$(kubectl config current-context)" = "docker-desktop" ]; then
28+
sed "s?/mnt/src?$(pwd)?g" "$WAR_MANIFESTS/warnet-rpc-statefulset-dev.yaml" | kubectl apply -f -
29+
else # assuming minikube
30+
minikube image load warnet/dev
31+
kubectl apply -f "$WAR_MANIFESTS/warnet-rpc-statefulset-dev.yaml"
32+
fi
33+
else
34+
kubectl apply -f "$WAR_MANIFESTS/warnet-rpc-statefulset.yaml"
35+
fi
36+
37+
kubectl config set-context --current --namespace=warnet
38+
39+
# Check for warnet-rpc container
40+
check_warnet_rpc
41+
42+
until kubectl get pod rpc-0 --namespace=warnet; do
43+
echo "Waiting for server to find pod rpc-0..."
44+
sleep 4
45+
done
46+
47+
echo "⏲️ This could take a minute or so."
48+
kubectl wait --for=condition=Ready --timeout=2m pod rpc-0
49+
50+
echo Done...

resources/scripts/quick_start.sh

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ print_partial_message() {
3838
local pre_message="$1"
3939
local formatted_part="$2"
4040
local post_message="$3"
41-
local format="$4"
41+
local format="${4:-}" # Default to empty string if not provided
4242
local color="${5:-$RESET}"
4343

4444
echo -e "${color}${pre_message}${format}${formatted_part}${RESET}${color}${post_message}${RESET}"
@@ -103,7 +103,6 @@ if [ -n "$just_path" ]; then
103103
else
104104
print_partial_message " 💥 Could not find " "just" ". Please follow this link to install it..." "$BOLD"
105105
print_message "" " https://github.com/casey/just?tab=readme-ov-file#pre-built-binaries" "$BOLD"
106-
exit 127
107106
fi
108107

109108
python_path=$(command -v python3 || true)
@@ -115,11 +114,10 @@ else
115114
exit 127
116115
fi
117116

118-
venv_status=$(python3 -m venv --help || true)
119-
if [ -n "$venv_status" ]; then
120-
print_partial_message " ⭐️ Found " "venv" ": a python3 module" "$BOLD"
117+
if [ -n "$VIRTUAL_ENV" ]; then
118+
print_partial_message " ⭐️ Running in virtual environment: " "$VIRTUAL_ENV" "$BOLD"
121119
else
122-
print_partial_message " 💥 Could not find " "venv" ". Please install it using your package manager." "$BOLD"
120+
print_partial_message " 💥 Not running in a virtual environment. " "Please activate a venv before proceeding." "$BOLD"
123121
exit 127
124122
fi
125123

@@ -136,44 +134,3 @@ else
136134
print_partial_message " 💥 Could not find " "BPF" ". Please figure out how to enable Berkeley Packet Filters in your kernel." "$BOLD"
137135
exit 1
138136
fi
139-
140-
print_message "" "" ""
141-
print_message "" " Let's try to spin up a python virtual environment..." ""
142-
print_message "" "" ""
143-
144-
if [ -d ".venv" ]; then
145-
print_message "" " It looks like a virtual environment already exists!" ""
146-
else
147-
print_message "" " Creating a new virtual environment..." ""
148-
python3 -m venv .venv
149-
fi
150-
151-
source .venv/bin/activate
152-
153-
print_message "" "" ""
154-
print_partial_message " ⭐️ " "venv" ": The python virtual environment looks good" "$BOLD"
155-
print_message "" "" ""
156-
print_message "" " Let's install warnet into that virtual environment..." ""
157-
print_message "" "" ""
158-
159-
pip install --upgrade pip
160-
pip install -e .
161-
162-
print_message "" "" ""
163-
print_partial_message " ⭐️ " "warnet" ": We installed Warnet in the virtual environment" "$BOLD"
164-
print_message "" "" ""
165-
print_message "" " Now, let's get the Warnet started..." ""
166-
print_message "" "" ""
167-
168-
just start
169-
just p &
170-
sleep 1
171-
warcli network start
172-
sleep 1
173-
while warcli network connected | grep -q "False"; do
174-
sleep 2
175-
done
176-
print_message "" "🥳" ""
177-
print_message "" "Run the following command to enter into the python virtual environment..." ""
178-
print_message "" " source .venv/bin/activate" "$BOLD"
179-
print_partial_message " After that, you can run " "warcli help" " to start running Warnet commands." "$BOLD"

0 commit comments

Comments
 (0)