This project provides a fully containerized hostname generator API that allows you to generate random server hostnames based on predefined themes. It includes a FastAPI backend, a Vue.js Web UI, MongoDB for storage, and MQTT for auto-assigning hostnames to Raspberry Pi devices.
- ✅ Random hostname generation based on different themes
- ✅ MongoDB-backed persistence for themes and names
- ✅ Web UI for managing themes and names
- ✅ Auto-assign hostnames to Raspberry Pi devices via MQTT
- ✅ Podman/Docker Compose for easy deployment
- ✅ Swagger API documentation
git clone https://github.com/your-username/hostname-generator.git
cd hostname-generator
Create a .env
file inside webui/
:
echo "VITE_API_BASE_URL=http://backend:8000" > webui/.env
podman-compose up -d --build
Once everything is running, open your browser and go to:
http://localhost:8080
To check if all containers are running properly:
podman ps
You can access the Swagger API Documentation at:
http://localhost:8000/docs
This provides an interactive way to test API calls.
curl http://localhost:8000/dc
Response:
{ "batman" }
curl http://localhost:8000/themes
Response:
["dc", "marvel", "dinosaurs"]
curl http://localhost:8000/theme/dc
Response:
["batman", "superman", "joker"]
curl -X POST "http://localhost:8000/add_theme/starwars" -H "Content-Type: application/json" -d '["yoda", "vader", "skywalker"]'
curl -X POST "http://localhost:8000/add_names/starwars" -H "Content-Type: application/json" -d '["chewbacca", "han-solo"]'
curl -X DELETE "http://localhost:8000/remove_theme/starwars"
curl -X DELETE "http://localhost:8000/remove_name/dc/joker"
curl -X PUT "http://localhost:8000/update_name/dc?old_name=superman&new_name=man-of-steel"
This project supports automatic hostname assignment using MQTT. When a Raspberry Pi boots up, it can request a hostname from a specific theme and automatically set it.
sudo apt install mosquitto mosquitto-clients
Save this as /home/pi/get_hostname.sh
:
#!/bin/bash
THEME="dc"
MQTT_BROKER="mqtt"
# Request hostname
mosquitto_pub -h $MQTT_BROKER -t "hostname/request" -m "$THEME"
# Listen for response
mosquitto_sub -h $MQTT_BROKER -t "hostname/response/$THEME" -C 1 | xargs sudo hostnamectl set-hostname
Edit /etc/rc.local
and add:
bash /home/pi/get_hostname.sh &
Reboot the Raspberry Pi, and it will automatically request a hostname from the API! 🎉
podman ps
podman-compose down
podman-compose up -d --build
podman logs backend
podman logs webui
- ✅ DNS Integration – Auto-map hostnames to IP addresses
- ✅ Webhook Support – Notify when a hostname is assigned
- ✅ More Themes – Star Trek, Harry Potter, LOTR, Cyberpunk, etc.
This project is open-source under the MIT License.
Created with ❤️ by Adam Stracener 🚀