Skip to main content

Gancho receives webhooks and triggers actions in response.

Project description

Gancho takes websocket payload and perform actions

Usage:

On github set websocket for the desired events, recommended [create, push, ping].

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 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gancho-0.1.3.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gancho-0.1.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file gancho-0.1.3.tar.gz.

File metadata

  • Download URL: gancho-0.1.3.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for gancho-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bc7fe01142199ef8bda7354980289c4f175418ab3ef02b6d80706aeadc2500fa
MD5 ca9fb1f29154046a2452c77f90e9e84f
BLAKE2b-256 0ff41646da47e6ddcd048dad0c55d76783805f39d1ff3b553c8f039e7e19d8ea

See more details on using hashes here.

File details

Details for the file gancho-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: gancho-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for gancho-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 92fd93eabab00fef84b99e752ff2bfb5156997365cb72a0f3adf74e26f33669e
MD5 e2deac941c7c57de210b140991ef2583
BLAKE2b-256 3a8768f8c0f63a20f91ffa23086d2aa9e35dbd93e6d59ecd73f11c573a334d22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page