A simple CI/CD server written in Flask that listens for GitHub webhooks, verifies the signature, and performs an action.
- Navigate to your repository > "Settings" > "Webhooks" > "Add a webhook".
- Generate a new secret (e.g.
ruby -rsecurerandom -e 'puts SecureRandom.hex(20)'
). - Add the newly generated secret to the webhook.
- Store the secret somewhere safe.
- Clone the project.
- Create a new virtual environment.
- Install the requirements using
pip install -r requirements.txt
. - Create a
.env
file inside the project root with the following content:# this information is displayed when visting the index page (/) API_NAME=flask-github-webhook-server API_DESCRIPTION=made by duplxey API_VERSION=1.0 # this command is going to run everytime you receive a webhook message DEPLOY_COMMAND=bash ./deploy.sh GITHUB_WEBHOOK_SECRET=<your_secret>
- Add custom commands/functionality to deploy.sh.
- Run the server
flask run --host 0.0.0.0 --port 5000
. - Navigate to http://localhost:5000/.
For production setup follow How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 18.04 or find a similar tutorial.