This is a Telegram bot for me and my friends. It has assorted functionality for managing our Telegram chat.
If you wonder what the hell snowpity is, see the explanation.
© MareQuest and snowpity.com are't controlled by the maintainers of this telegram bot, any similarities are a coincidence!
To build the bot from sources, there has to be Rust toolchain installed.
To build and run the bot in development mode outside of docker
run this:
cargo run
Make sure to define all the necessary configurations in .env
file when doing this. Example configurations can be inferred from deployment/modules/hetzner/cloud_init.tf
.
It's also possible to run the bot in a container using docker compose
just like it is going to be on the server. It requires some preliminary setup that is not expressible via a single docker compose
command. Therefore, we have a dev CLI x.nu
, that automates this process. We recommend adding an alias to your .bashrc
or .zshrc
or just .{paste_your_shell_here}rc
file:
alias x="$(git rev-parse --show-toplevel)/x.nu"
You can use scripts/download/nu.sh
to download the nushell
interpreter for Linux OS. Then you'll need to place the nu
binary somewhere in your $PATH
.
After that you will be able to run:
# Run the application in `docker`, or only a subset of services
x up [--fresh|-f] [--no-tg-bot] [--no-observability]
# Teardown any existing `docker compose` stack
x down
The bot is deployed using terraform. All tf projects reside under deployment/
directory.
The application is hosted on Hetzner Cloud. It is delivered to the server via a Dockerhub repository, and covered with telemetry exfiltration by self-hosted Grafana, Grafana Agent, Loki, Victoria Metrics. The bot services are orchestrated by docker-compose, which is in turn bootstrapped via cloud-init and systemd.
Hetzner Cloud is not free, so you need some money 💰 on your credit card. You may tweak the server and volume sizes in terraform to optimize for your use case. With the configuration and market price at the time of this writing the entire stack in production costs €9.25/month
, but if money is a big problem for you, then there are cheaper options.
The minimum Hetzner Cloud setup is €3.73/month
, which can be achieved with the smallest possible server and volume size.
We use this minimum configuration for development mode deployments to save money 📈 there. This mode perfectly suits end-to-end testing of the app before pushing it to production.
To deploy the bot, you need to manually create several accounts at:
You also need to retrieve the bot token from @BotFather in Telegram.
Then, create a file deployment/project/terraform.tfvars
with the secrets and credentials:
tg_bot_maintainer = "999999999"
tg_bot_blob_cache_chat = {
prod = "-9999999999999"
dev = "..."
}
tg_bot_alerts_chat = {
prod = "-9999999999999"
dev = "..."
}
tg_bot_token = {
prod = "9999999999:AAaa9-9AAaa99AAaa99AAaa99AAaa99AAaa"
dev = "..."
}
docker_username = "username"
docker_password = "password"
pg_password = "password"
pgadmin_password = "password"
hcloud_token = {
prod = "AAaa99AAaa99AAaa99AAaa99AAaa99AAaa99AAaa99AAaa99AAaa99AAaa99AAaa"
dev = "..."
}
# IP addresses allowed to SSH in to the server by Hetzner firewall
allowed_ssh_ips = ["255.255.255.255/32"]
Note that some credentials differ by the terraform workspace. If the default terraform workspace is selected, then prod
credentials and configurations will be used. If dev
workspace is selected, then development dev
credentials and configurations will be used accordingly.
After all the necessary credentials are configured, you will be able to deploy the entire stack with the Dockerhub repo and Hetzner Cloud server.
Note, however, there currently is a chicken-and-egg problem, so the deployment won't succeed from the first try because first the Dockerhub repo must be deployed, then artifacts uploaded and only after that can we deploy the Hetzner server. To do the deployment for the first time run this:
cd deployment/project
terraform init
terraform apply -target=module.dockerhub
Once this is done you don't need to repeat the steps higher again. You may run the following command to build the app and deploy the stack to Hetzner.
x deploy
To clean everything up and get rid of the bot entirely run the following command.
⚠️ Warning! This will destroy the NAS volume of the database, basically resulting in data loss!
x destroy --all
To destroy only the Hetzner Cloud server instance run this.
ℹ This is safe to do. No data will be lost, the database will gracefully shutdown saving everything to the persistent NAS volume.
x destroy
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Snowpity by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.