Gancho takes webhook payload and perform actions
Usage:
On github set webhook for the desired events.
Events supported
- create: execute a
deployment/{user}/{repo}/deploy.sh - ping: returns "pong"
TODO
- Challenge the secret passed by the webhook
- Use a config file to declare events and target scripts
- Rate limiting
- Allow using a task queue producer instead of the Background thread
Installation
# Service directories
mkdir p /opt/gancho
# Service User
sudo useradd -r -s /usr/sbin/nologin -d /opt/gancho -M gancho
# This gives permission to manipulate /var/www, adjust for your needs
sudo chown -R gancho:www-data /opt/gancho
sudo chown -R root:www-data /var/www
sudo chmod -R 775 /var/www
sudo usermod -aG www-data gancho
# Environment
cd /opt/gancho
uv venv
uv pip install gancho
Test it
$ /opt/gancho/.venv/bin/gancho
INFO: Started server process [4321]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:5000 (Press CTRL+C to quit)]
On a separate terminal
curl -X POST localhost:5000 -H "x-github-event:ping"
Service Daemon
Soket directory
sudo mkdir -p /run/gancho
sudo chown gancho:www-data /run/gancho
sudo chmod 770 /run/gancho
/etc/systemd/system/gancho.socket
[Unit]
Description=Socket do gancho
[Socket]
ListenStream=/run/gancho/gancho.sock
SocketMode=0660
SocketUser=gancho
SocketGroup=www-data
[Install]
WantedBy=sockets.target
/etc/systemd/system/gancho.service
[Unit]
Description=gancho daemon
Requires=gancho.socket
After=network.target
[Service]
User=gancho
Group=www-data
WorkingDirectory=/opt/gancho
ExecStart=/opt/gancho/.venv/bin/gancho --uds /run/gancho/gancho.sock
Restart=always
RestartSec=5
StandardInput=socket
StandardOutput=journal
StandardError=journal
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
Start the service
sudo systemctl daemon-reload
sudo systemctl enable --now gancho.socket
sudo systemctl status gancho.service # will start only when socket is used
$ systemctl status gancho
○ gancho.service - gancho daemon
Loaded: loaded (/etc/systemd/system/gancho.service; disabled; preset: enabled)
Active: inactive (dead)
TriggeredBy: ● gancho.socket
Logs
journalctl -u gancho.service -f
Nginx host
Replace example.com with your host
/etc/nginx/sites-available/gancho
server {
listen 80;
server_name webhook.example.com;
location / {
proxy_pass http://unix:/run/gancho/gancho.sock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
ln -s /etc/nginx/sites-available/gancho /etc/nginx/sites-enabled/gancho
nginx -t
sudo systemctl restart nginx
Notes:
- Ensure your default nginx site is cleaned up and not catching all domains
- If using https, ensure certificate is enabled to the new domain, example:
certbot --nginx -d webhook.example.com
Deployments
For a repo my-username/my-repo the following will be the deploy script.
/opt/gancho/deployment/my-username/my-repo/deploy.sh
#!/usr/bin/bash
echo "deploying"
chmod +x /opt/gancho/deployment/my-username/my-repo/deploy.sh
Release files for gancho 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gancho-0.1.5.tar.gz | 41.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gancho-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.4 kB
Release files / gancho-0.1.5.tar.gz
| Download URL | gancho-0.1.5.tar.gz |
|---|---|
| Size | 41.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
854db08ad14b1278aff0415fca24582c086d87a08e84011e48cafe3ba6e1b897
|
|
BLAKE2b-256 checksum How to use checksums |
d18d5bb214620dd8614fae02dd5fddb87f6d41af48d4f81f51e064f50a78fc35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Release files / gancho-0.1.5-py3-none-any.whl
| Download URL | gancho-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2778b1899a4ce15e097e40c8b23fb63796c1ee0d9ab0d6dce078c753afd5f79d
|
|
BLAKE2b-256 checksum How to use checksums |
b61af42d624cda0997d92f4a13532c2fbe34fb8509abb459685820cef8e9554c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|