diff options
| author | diogo464 <[email protected]> | 2025-05-28 20:46:55 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-05-28 20:46:55 +0100 |
| commit | 05f7444ecd2e3405b0e595042166ec5f8a3395ab (patch) | |
| tree | 2b28bca5dab0f2ec79c41893732b5d6866725f56 /README.md | |
init
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..1467530 --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | # Bonsai Web | ||
| 2 | |||
| 3 | A simple web interface for the Bonsai network latency graph generator. | ||
| 4 | |||
| 5 | ## Features | ||
| 6 | |||
| 7 | - Clean, modern UI using Pico CSS | ||
| 8 | - YAML configuration input | ||
| 9 | - Real-time file generation | ||
| 10 | - File viewing and downloading capabilities | ||
| 11 | - Containerized deployment support | ||
| 12 | |||
| 13 | ## Local Development | ||
| 14 | |||
| 15 | ### Prerequisites | ||
| 16 | |||
| 17 | - Python 3.9+ | ||
| 18 | - Flask | ||
| 19 | |||
| 20 | ### Installation | ||
| 21 | |||
| 22 | 1. Clone this repository | ||
| 23 | 2. Install dependencies: | ||
| 24 | ```bash | ||
| 25 | pip install -r requirements.txt | ||
| 26 | ``` | ||
| 27 | |||
| 28 | ### Running Locally | ||
| 29 | |||
| 30 | ```bash | ||
| 31 | python app.py | ||
| 32 | ``` | ||
| 33 | |||
| 34 | The application will be available at `http://localhost:5000` | ||
| 35 | |||
| 36 | ### Environment Configuration | ||
| 37 | |||
| 38 | The application behavior can be controlled using the `BONSAI_TEST_MODE` environment variable: | ||
| 39 | |||
| 40 | - **Test Mode** (default for local development): `BONSAI_TEST_MODE=true` | ||
| 41 | - If Bonsai fails or is not available, dummy files are generated for testing | ||
| 42 | - Useful for development and testing the web interface | ||
| 43 | |||
| 44 | - **Production Mode**: `BONSAI_TEST_MODE=false` | ||
| 45 | - If Bonsai fails, proper error messages are returned to the user | ||
| 46 | - No dummy files are generated | ||
| 47 | |||
| 48 | ```bash | ||
| 49 | # Run in production mode | ||
| 50 | BONSAI_TEST_MODE=false python app.py | ||
| 51 | |||
| 52 | # Run in test mode (default) | ||
| 53 | BONSAI_TEST_MODE=true python app.py | ||
| 54 | # or simply | ||
| 55 | python app.py | ||
| 56 | ``` | ||
| 57 | |||
| 58 | ### Development Mode | ||
| 59 | |||
| 60 | 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. | ||
| 61 | |||
| 62 | **Error Handling**: When Bonsai fails in production mode, detailed error messages are displayed to the user in red text, including: | ||
| 63 | - Execution failures with return codes and stderr output | ||
| 64 | - Timeout errors (30-second limit) | ||
| 65 | - Missing Bonsai installation errors | ||
| 66 | |||
| 67 | ## Container Deployment | ||
| 68 | |||
| 69 | ### Building the Container | ||
| 70 | |||
| 71 | #### Local Build (for testing) | ||
| 72 | ```bash | ||
| 73 | ./build.sh | ||
| 74 | ``` | ||
| 75 | |||
| 76 | #### Production Build and Push | ||
| 77 | ```bash | ||
| 78 | PUSH=1 ./build.sh | ||
| 79 | ``` | ||
| 80 | |||
| 81 | The build script will: | ||
| 82 | - Always build the container image with appropriate tags | ||
| 83 | - Only push to `git.d464.sh/diogo464/bonsai-web` when `PUSH=1` is set | ||
| 84 | - Use git tags for versioning (or 'latest' if no tag) | ||
| 85 | - Check registry authentication only when pushing | ||
| 86 | |||
| 87 | #### Manual Build Commands | ||
| 88 | |||
| 89 | ```bash | ||
| 90 | # Local build | ||
| 91 | podman build -t bonsai-web -f Containerfile . | ||
| 92 | |||
| 93 | # Production build and push | ||
| 94 | podman build -t git.d464.sh/diogo464/bonsai-web:latest -f Containerfile . | ||
| 95 | podman push git.d464.sh/diogo464/bonsai-web:latest | ||
| 96 | ``` | ||
| 97 | |||
| 98 | ### Running the Container | ||
| 99 | |||
| 100 | #### From Local Build | ||
| 101 | ```bash | ||
| 102 | podman run -p 5000:5000 bonsai-web:local | ||
| 103 | ``` | ||
| 104 | |||
| 105 | #### From Registry | ||
| 106 | ```bash | ||
| 107 | podman run -p 5000:5000 git.d464.sh/diogo464/bonsai-web:latest | ||
| 108 | ``` | ||
| 109 | |||
| 110 | ### Registry Authentication | ||
| 111 | |||
| 112 | Before pushing to the registry, authenticate with: | ||
| 113 | ```bash | ||
| 114 | podman login git.d464.sh | ||
| 115 | ``` | ||
| 116 | |||
| 117 | ### Bonsai Integration | ||
| 118 | |||
| 119 | To integrate with the actual Bonsai tool, modify the `Containerfile` in the "BONSAI SETUP SECTION" to: | ||
| 120 | |||
| 121 | 1. Clone or copy the Bonsai source code to `/usr/src/bonsai` | ||
| 122 | 2. Install Bonsai's dependencies | ||
| 123 | 3. Ensure the Bonsai tool is properly configured | ||
| 124 | |||
| 125 | Example: | ||
| 126 | ```dockerfile | ||
| 127 | # In the BONSAI SETUP SECTION of Containerfile | ||
| 128 | RUN git clone https://github.com/your-org/bonsai.git /usr/src/bonsai | ||
| 129 | WORKDIR /usr/src/bonsai | ||
| 130 | RUN pip install -r requirements.txt | ||
| 131 | WORKDIR /app | ||
| 132 | ``` | ||
| 133 | |||
| 134 | ## Usage | ||
| 135 | |||
| 136 | 1. Open the web application in your browser | ||
| 137 | 2. Enter your network configuration in YAML format in the text area | ||
| 138 | 3. Click "Generate Network Files" | ||
| 139 | 4. View or download the generated `edges.csv` and `nodes.csv` files | ||
| 140 | |||
| 141 | ### Example Configuration | ||
| 142 | |||
| 143 | ```yaml | ||
| 144 | network: | ||
| 145 | nodes: 10 | ||
| 146 | density: 0.3 | ||
| 147 | latency_range: [1, 100] | ||
| 148 | ``` | ||
| 149 | |||
| 150 | ## API | ||
| 151 | |||
| 152 | ### POST / | ||
| 153 | |||
| 154 | Generates network files from a YAML configuration. | ||
| 155 | |||
| 156 | **Request Body:** | ||
| 157 | ```json | ||
| 158 | { | ||
| 159 | "config": "network:\n nodes: 10\n density: 0.3" | ||
| 160 | } | ||
| 161 | ``` | ||
| 162 | |||
| 163 | **Response:** | ||
| 164 | ```json | ||
| 165 | { | ||
| 166 | "edges.csv": "source,target,weight\nnode1,node2,0.5\n...", | ||
| 167 | "nodes.csv": "id,label,x,y\nnode1,Node 1,0,0\n..." | ||
| 168 | } | ||
| 169 | ``` | ||
| 170 | |||
| 171 | ## Project Structure | ||
| 172 | |||
| 173 | ``` | ||
| 174 | . | ||
| 175 | ├── app.py # Flask backend | ||
| 176 | ├── index.html # Main web page | ||
| 177 | ├── script.js # Client-side JavaScript | ||
| 178 | ├── logo.png # Bonsai logo | ||
| 179 | ├── requirements.txt # Python dependencies | ||
| 180 | ├── Containerfile # Container build instructions | ||
| 181 | ├── build.sh # Container build script | ||
| 182 | ├── .gitignore # Git ignore patterns | ||
| 183 | └── README.md # This file | ||
| 184 | ``` \ No newline at end of file | ||
