Skip to content

A simple project to update project from github webhook

License

Notifications You must be signed in to change notification settings

sylfel/webhook-deployer

Repository files navigation

Webhook Deployer

Introduction

A simple deployer from github webhook to a unique server.

It's a Laravel application using Spatie webhook client and IPLib

How does it work ?

  • Github webhook sends a POST request to your Webhook Deployer project
  • Webhook Deployer checks and validates the request
  • Then it runs a command on the server (ex : a bash script to update a website)
flowchart LR
    id1{{Github}} -.->id2[POST Request\nWebhook]-.->id3{{Server\nCheck & Validate}}-.->id4[RUN\nCommand]
Loading

There are 3 validations :

  • IP White list (from Meta Github API)
  • Key validation (A key must be defined in your webhook call, and it's checked by app)
  • Find project in a config file (if not found, it will fail)

Installation

Clone the project on your server

git clone https://github.com/sylfel/webhook-deployer.git

Run composer

composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader

Initialize .env & deploy.json config file

cp .env.example .env
touch storage/app/deploy.json

Run database migration

php artisan migrate --force

Define laravel app key & run optimisation

php artisan key:generate --force
php artisan optimize

Define a cron to run laravel Scheduler every minute

* * * * * [PHP_PATH] [APP_PATH]/webhook-deployer/artisan schedule:run > /dev/null 2>&1

Where PHP_PATH is absolute path to php ( ex : /usr/local/bin/php) and APP_PATH is path to installed application

Define a public url to the /public directory

Configuration

  • Change APP_URL in .env file

  • Define a WEBHOOK_CLIENT_SECRET signing_secret in .env file

  • Define projects in deploy.json

[
    {
        "conditions": { // all conditions
            "headers.X-GitHub-Event":"push", // from headers
            "payload.ref":"refs/heads/main", // from payload 
            "payload.repository.full_name":"sylfel/webhook-deployer"
        },
        "path":"/path/to/project/webhook-deployer", // path from where to run command
        "command":"bash -lc .script/deploy.sh" // command to run
    },
    {
        ...
    }
]
  • Define a webhook in github with the same key as WEBHOOK_CLIENT_SECRET

About

A simple project to update project from github webhook

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages