ui_poc/README.md

251 lines
5.5 KiB
Markdown
Raw Normal View History

2024-09-06 02:07:07 +00:00
<h1> Dashboard UI </h1>
<h2>Table of Contents</h2>
- [Introduction](#introduction)
2024-09-06 18:58:31 +00:00
- [Download Repo](#download-repo)
2024-09-06 18:16:08 +00:00
- [Prerequisites](#prerequisites)
- [Make Commands](#make-commands)
2024-09-06 18:58:31 +00:00
- [Local](#local)
- [Micro VM](#micro-vm)
2024-09-06 02:07:07 +00:00
- [Deploy Locally](#deploy-locally)
2024-09-06 12:04:08 +00:00
- [Deploy Online](#deploy-online)
- [DNS Name](#dns-name)
- [Deploy on TFGrid with Full VM](#deploy-on-tfgrid-with-full-vm)
- [Troubleshooting](#troubleshooting)
- [Deploy on TFGrid with Micro VM](#deploy-on-tfgrid-with-micro-vm)
- [Prepare the VM](#prepare-the-vm)
2024-09-06 12:10:37 +00:00
- [Prepare Repo](#prepare-repo)
2024-09-06 12:04:08 +00:00
- [Zinit](#zinit)
- [Manage Caddy with zinit](#manage-caddy-with-zinit)
- [Manage Webserver with zinit](#manage-webserver-with-zinit)
2024-09-06 02:07:07 +00:00
- [Notes](#notes)
---
2024-09-06 00:50:11 +00:00
## Introduction
This is a proof-of-concept of a basic Dashboard UI in Python using FastApi and HTMX.
2024-09-06 18:58:31 +00:00
## Download Repo
2024-09-06 18:18:41 +00:00
```
git clone https://git.ourworld.tf/tfgrid/ui_poc
cd ui_poc
```
2024-09-06 18:16:08 +00:00
## Prerequisites
- python3
## Make Commands
You can simply clone the repo and run the make command:
2024-09-06 18:58:31 +00:00
### Local
Run locally on your machine.
2024-09-06 18:16:08 +00:00
```
make run
```
2024-09-06 18:58:31 +00:00
This runs the `./scripts/microvm.sh` script.
### Micro VM
Run on a TFGrid micro VM with IPv4 address. Make sure to point a DNS A record of your (sub)domain to the IPv4 address of the VM
```
make microvm domain="example.com"
```
This runs the `./scripts/microvm.sh` script.
2024-09-06 18:16:08 +00:00
## Deploy Locally
2024-09-06 12:10:37 +00:00
You can use the following script to deploy the UI locally.
```
# Clone the repository
git clone https://git.ourworld.tf/tfgrid/ui_poc
2024-09-06 16:58:48 +00:00
# Go to app directory
cd ui_poc/app
2024-09-06 15:46:30 +00:00
# Clean Up if necessary
2024-09-06 18:16:08 +00:00
rm -rf venv
rm -rf __pycache__
# Set Python environment
python3 -m venv venv
source venv/bin/activate
# Install requirements
python3 -m pip install -r requirements.txt
# Deploy the local website at port 8000
2024-09-06 16:58:48 +00:00
uvicorn app:app --reload
```
2024-09-06 12:04:08 +00:00
## Deploy Online
You can deploy the webserver online with an IPv4 address. In this case make sure to set the DNS properly.
We show how to deploy online on both a micro and a full VM running on the TFGrid.
### DNS Name
Set a DNS A record of your domain URL pointing to the IPv4 address.
## Deploy on TFGrid with Full VM
2024-09-06 02:07:07 +00:00
You can deploy the website on the TFGrid. Follow those steps before after following the local steps.
- Deploy Full VM Ubuntu 24.04 with IPv4 address and connect into it via SSH
2024-09-06 12:04:08 +00:00
- Prepare the environment
```
apt update && apt install -y git nano curl python3 python-is-python3 python3-venv python3-pip
```
- Install Caddy
```
apt install -y debian-keyring debian-archive-keyring
apt install -y apt-transport-https
echo "deb [trusted=yes] https://releases.caddyserver.com/deb/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/caddy.list
apt update
apt install caddy
```
- Enable and start caddy
```
systemctl enable caddy
systemctl start caddy
```
- Create caddyfile at
```
nano /etc/caddy/Caddyfile
```
- Caddyfile content
```
example.com {
reverse_proxy 127.0.0.1:8000
}
```
### Troubleshooting
- Check the status
2024-09-06 12:10:37 +00:00
```
systemctl status caddy
```
2024-09-06 12:04:08 +00:00
- Check the caddy log
2024-09-06 12:10:37 +00:00
```
journalctl -u caddy
```
2024-09-06 12:04:08 +00:00
## Deploy on TFGrid with Micro VM
You can deploy the website on the TFGrid with a micro VM.
### Prepare the VM
- Deploy Micro VM Ubuntu 24.04 with IPv4 address and connect into it via SSH
2024-09-06 02:07:07 +00:00
- Prepare the environment
2024-09-06 12:10:37 +00:00
```
apt update && apt install -y git nano curl python3 python-is-python3 python3-venv python3-pip
```
2024-09-06 02:07:07 +00:00
- Install Caddy
2024-09-06 12:10:37 +00:00
```
apt install -y debian-keyring debian-archive-keyring
apt install -y apt-transport-https
echo "deb [trusted=yes] https://releases.caddyserver.com/deb/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/caddy.list
apt update
apt install caddy
```
2024-09-06 12:04:08 +00:00
2024-09-06 12:10:37 +00:00
### Prepare Repo
2024-09-06 12:12:56 +00:00
We clone the repository.
2024-09-06 12:04:08 +00:00
2024-09-06 02:07:07 +00:00
```
2024-09-06 12:04:08 +00:00
# Clone the repository
2024-09-06 12:10:37 +00:00
cd /root
2024-09-06 12:04:08 +00:00
git clone https://git.ourworld.tf/tfgrid/ui_poc
2024-09-06 02:07:07 +00:00
```
2024-09-06 12:04:08 +00:00
### Zinit
2024-09-06 12:12:56 +00:00
We manage Caddy and Uvicorn with Zinit.
2024-09-06 12:04:08 +00:00
#### Manage Caddy with zinit
We manage Caddy with zinit.
- Open the file for editing
```bash
nano /etc/zinit/caddy.yaml
```
- Insert the following line with your own domain and save the file
```
exec: caddy reverse-proxy --from example.com --to :8000
```
- Add the new Caddy file to zinit
```bash
zinit monitor caddy
```
Zinit will start up Caddy immediately, restart it if it ever crashes, and start it up automatically after any reboots. Assuming you tested the Caddy invocation above and used the same form here, that should be all there is to it.
Here are some other Zinit commands that could be helpful to troubleshoot issues:
- See status of all services (same as "zinit list")
```
zinit
```
- Get logs for a service
```
zinit log caddy
```
- Restart a service (to test configuration changes, for example)
```
zinit stop caddy
zinit start caddy
```
- To forget a zinit service
```
zinit forget caddy
```
#### Manage Webserver with zinit
We manage the webserver (uvicorn) with zinit.
2024-09-06 16:58:48 +00:00
- Create a script in `/root/ui_poc/app`
2024-09-06 12:04:08 +00:00
```
#!/bin/bash
2024-09-06 16:58:48 +00:00
cd /root/ui_poc/app
2024-09-06 12:07:05 +00:00
rm -r venv
rm -r __pycache__
python3 -m venv venv
2024-09-06 12:04:08 +00:00
source venv/bin/activate
python3 -m pip install -r requirements.txt
uvicorn main:app --reload
```
- Make the script executable
```
chmod +x webserver.sh
```
- Open the file for editing
```bash
nano /etc/zinit/webserver.yaml
```
- Insert the following line with your own domain and save the file
```
2024-09-06 16:58:48 +00:00
exec: bash /root/ui_poc/app/webserver.sh
2024-09-06 12:04:08 +00:00
```
- Add the new Webserver file to zinit
```bash
zinit monitor webserver
```
2024-09-06 02:07:07 +00:00
## Notes
2024-09-06 01:02:05 +00:00
The .gitignore file is set with `venv` as the Python virtual environment.