This repository is part of an article series
This repository contains two applications:
- A Webhook payload delivery service for local development
- A Telegram bot that logs GitHub Actions workflows
I will write the second part of the article once I have more time, but feel free to read the first one.
bot-demo.mov
- Add a
.envbycp .env.sample .env
# this can be found when creating your bot through BotFather
# https://core.telegram.org/bots/tutorial#obtain-your-bot-token
TELEGRAM_BOT_TOKEN=
# this can either be found through the browser URL, it should have a format liks "-1234567890"
# or you can use https://telegram.me/rawdatabot
TELEGRAM_CHAT_ID=
# this is for dev environment + it is explained on the article how it works
DEV_CLI_SOURCE_URL=https://your-service.com # e.g. https://smee.io/
DEV_CLI_TARGET_URL=http://web:3000/webhook
# you must have a github app created with the Webhook URL pointing to your server
# this will be the URL of the deployed webserver
# https://your-server.com/webhooks - for prod
# https://your-server.com/channel/<any-wildcard> - for dev
# more info on how to generate the key below
GITHUB_APP_PRIVATE_KEY=
# the APP_ID and APP_INSTALLATION_ID can be found directly in the Github App page
GITHUB_APP_ID=
GITHUB_APP_INSTALLATION_ID=- Go to github app page
- Click on "generate a private key" in the Private keys section
- Save the
.pemfile appropriately - Generate a base64 representation of the item using
base64 -w 0 -i my.pem > encoded-private-key.txtorpbcopy < base64 -w 0 -i my.pem - Copy the content into the
GITHUB_APP_PRIVATE_KEYenv variable
make dev- runs docker environment with CLI and Web- CLI forwards
DEV_CLI_SOURCE_URLto `DEV_CLI_TARGET_URL - Web defaults to
http://localhost:3000--webalias to docker env - Default webhook endpoint is
http://localhost:3000/webhook
- CLI forwards
make cli-run source=http://my-source target=http://localhost:3000/webhook- runs only CLI environment, don't forget thesourceandtargetparamsmake web-run- runs webserver defaulting tohttp://localhost:3000make web-run-docker- runs production version of webserver - defaults tohttp://localhost:8080kamal deployorkamal setupto deploy things
For most cases, just run
make devIf you want to debug server, just run cli separately
make cli-run source=http://my-source target=http://localhost:3000/webhookYou can find a guide on the first article
All credits for the playbooks are from https://github.com/guillaumebriday/kamal-ansible-manager
When provisioning a new droplet, just configure ansible inside infra folder and run it
Copy the inventory example file:
$ cp infra/hosts.ini.example infra/hosts.iniUpdate the <host1> with your server's IP address (you can have multiple servers):
$ vim hosts.iniInstall the requirements:
$ ansible-galaxy collection install -r infra/requirements.yml
$ ansible-galaxy role install -r infra/requirements.ymlVariables can be configured in the playbook.yml file.
Also, you can override default variables provided in geerlingguy/ansible-role-swap to adjust the swap settings.
For instance:
vars:
security_autoupdate_reboot: "true"
security_autoupdate_reboot_time: "03:00"
swap_file_size_mb: '1024'Run the playbook:
$ ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i infra/hosts.ini infra/playbook.yml