aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 14675307036fed8696d8221cb3aec060d2827a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Bonsai Web

A simple web interface for the Bonsai network latency graph generator.

## Features

- Clean, modern UI using Pico CSS
- YAML configuration input
- Real-time file generation
- File viewing and downloading capabilities
- Containerized deployment support

## Local Development

### Prerequisites

- Python 3.9+
- Flask

### Installation

1. Clone this repository
2. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```

### Running Locally

```bash
python app.py
```

The application will be available at `http://localhost:5000`

### Environment Configuration

The application behavior can be controlled using the `BONSAI_TEST_MODE` environment variable:

- **Test Mode** (default for local development): `BONSAI_TEST_MODE=true`
  - If Bonsai fails or is not available, dummy files are generated for testing
  - Useful for development and testing the web interface
  
- **Production Mode**: `BONSAI_TEST_MODE=false`
  - If Bonsai fails, proper error messages are returned to the user
  - No dummy files are generated

```bash
# Run in production mode
BONSAI_TEST_MODE=false python app.py

# Run in test mode (default)
BONSAI_TEST_MODE=true python app.py
# or simply
python app.py
```

### Development Mode

For development, the application includes fallback dummy data generation when `BONSAI_TEST_MODE=true` and the actual Bonsai tool is not available. This allows you to test the web interface without having the full Bonsai installation.

**Error Handling**: When Bonsai fails in production mode, detailed error messages are displayed to the user in red text, including:
- Execution failures with return codes and stderr output
- Timeout errors (30-second limit)
- Missing Bonsai installation errors

## Container Deployment

### Building the Container

#### Local Build (for testing)
```bash
./build.sh
```

#### Production Build and Push
```bash
PUSH=1 ./build.sh
```

The build script will:
- Always build the container image with appropriate tags
- Only push to `git.d464.sh/diogo464/bonsai-web` when `PUSH=1` is set
- Use git tags for versioning (or 'latest' if no tag)
- Check registry authentication only when pushing

#### Manual Build Commands

```bash
# Local build
podman build -t bonsai-web -f Containerfile .

# Production build and push
podman build -t git.d464.sh/diogo464/bonsai-web:latest -f Containerfile .
podman push git.d464.sh/diogo464/bonsai-web:latest
```

### Running the Container

#### From Local Build
```bash
podman run -p 5000:5000 bonsai-web:local
```

#### From Registry
```bash
podman run -p 5000:5000 git.d464.sh/diogo464/bonsai-web:latest
```

### Registry Authentication

Before pushing to the registry, authenticate with:
```bash
podman login git.d464.sh
```

### Bonsai Integration

To integrate with the actual Bonsai tool, modify the `Containerfile` in the "BONSAI SETUP SECTION" to:

1. Clone or copy the Bonsai source code to `/usr/src/bonsai`
2. Install Bonsai's dependencies
3. Ensure the Bonsai tool is properly configured

Example:
```dockerfile
# In the BONSAI SETUP SECTION of Containerfile
RUN git clone https://github.com/your-org/bonsai.git /usr/src/bonsai
WORKDIR /usr/src/bonsai
RUN pip install -r requirements.txt
WORKDIR /app
```

## Usage

1. Open the web application in your browser
2. Enter your network configuration in YAML format in the text area
3. Click "Generate Network Files"
4. View or download the generated `edges.csv` and `nodes.csv` files

### Example Configuration

```yaml
network:
  nodes: 10
  density: 0.3
  latency_range: [1, 100]
```

## API

### POST /

Generates network files from a YAML configuration.

**Request Body:**
```json
{
  "config": "network:\n  nodes: 10\n  density: 0.3"
}
```

**Response:**
```json
{
  "edges.csv": "source,target,weight\nnode1,node2,0.5\n...",
  "nodes.csv": "id,label,x,y\nnode1,Node 1,0,0\n..."
}
```

## Project Structure

```
.
├── app.py              # Flask backend
├── index.html          # Main web page
├── script.js           # Client-side JavaScript
├── logo.png            # Bonsai logo
├── requirements.txt    # Python dependencies
├── Containerfile       # Container build instructions
├── build.sh            # Container build script
├── .gitignore          # Git ignore patterns
└── README.md          # This file
```