Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 8.46 KB

README.md

File metadata and controls

41 lines (30 loc) · 8.46 KB

CWB WebHook Deployer Script

  • This is PHP webhook deployer script to auto git pull source code on server.

  • This webhook script can be used in Github, Bitbucket and Gitlab.

  • Use deploy.example.php as working script. E.g. deploy.cwb2.php

  • Setup a webhook URL and Public Key at Github, Bitbucket and Gitlab.

Configuration in deploy.example.php

define("TOKEN", ""); // generate by "openssl rand -base64 32"
define("REMOTE_REPOSITORY", "[email protected]:username/reponame.git"); // edit repo remote address
define("DIR", "/var/www/html/reponame"); // repo path
define("BRANCH", "main"); // branch name
define("LOGFILE", "/var/www/html/githook/logs/".date('YmdHis')."_reponame_deploy.log"); // log path
define("GIT", "/usr/bin/git");
define("MAX_EXECUTION_TIME", 180);
define("BEFORE_PULL", "");
define("AFTER_PULL", "");

Webhook Deployer Test Script - deploy.tester.php

This script is to simulate the Github, Bitbucket and Gitlab payloads to hit our deployer script.

Get the payloads data on Github, Bitbucket and Gitlab and paste to variables below:-

$data = '{"zen":"Non-blocking is better than blocking.","hook_id":350825890,"hook":{"type":"Repository","id":350825890,"name":"web","active":true,"events":["*"],"config":{"content_type":"json","insecure_ssl":"0","secret":"********","url":"http://54.169.130.158/deploy.cwb2.php"},"updated_at":"2022-03-31T09:08:16Z","created_at":"2022-03-31T09:08:16Z","url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/hooks/350825890","test_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/hooks/350825890/test","ping_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/hooks/350825890/pings","deliveries_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/hooks/350825890/deliveries","last_response":{"code":null,"status":"unused","message":null}},"repository":{"id":428559037,"node_id":"R_kgDOGYtKvQ","name":"CWB-bussiness2.0","full_name":"sjkhew/CWB-bussiness2.0","private":true,"owner":{"login":"sjkhew","id":94550728,"node_id":"U_kgDOBaK6yA","avatar_url":"https://avatars.githubusercontent.com/u/94550728?v=4","gravatar_id":"","url":"https://api.github.com/users/sjkhew","html_url":"https://github.com/sjkhew","followers_url":"https://api.github.com/users/sjkhew/followers","following_url":"https://api.github.com/users/sjkhew/following{/other_user}","gists_url":"https://api.github.com/users/sjkhew/gists{/gist_id}","starred_url":"https://api.github.com/users/sjkhew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjkhew/subscriptions","organizations_url":"https://api.github.com/users/sjkhew/orgs","repos_url":"https://api.github.com/users/sjkhew/repos","events_url":"https://api.github.com/users/sjkhew/events{/privacy}","received_events_url":"https://api.github.com/users/sjkhew/received_events","type":"User","site_admin":false},"html_url":"https://github.com/sjkhew/CWB-bussiness2.0","description":null,"fork":false,"url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0","forks_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/forks","keys_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/teams","hooks_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/hooks","issue_events_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/issues/events{/number}","events_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/events","assignees_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/assignees{/user}","branches_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/branches{/branch}","tags_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/tags","blobs_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/git/refs{/sha}","trees_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/statuses/{sha}","languages_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/languages","stargazers_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/stargazers","contributors_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/contributors","subscribers_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/subscribers","subscription_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/subscription","commits_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/commits{/sha}","git_commits_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/git/commits{/sha}","comments_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/comments{/number}","issue_comment_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/issues/comments{/number}","contents_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/contents/{+path}","compare_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/merges","archive_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/downloads","issues_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/issues{/number}","pulls_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/pulls{/number}","milestones_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/milestones{/number}","notifications_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/labels{/name}","releases_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/releases{/id}","deployments_url":"https://api.github.com/repos/sjkhew/CWB-bussiness2.0/deployments","created_at":"2021-11-16T07:30:36Z","updated_at":"2022-02-22T03:35:34Z","pushed_at":"2022-03-31T02:04:24Z","git_url":"git://github.com/sjkhew/CWB-bussiness2.0.git","ssh_url":"[email protected]:sjkhew/CWB-bussiness2.0.git","clone_url":"https://github.com/sjkhew/CWB-bussiness2.0.git","svn_url":"https://github.com/sjkhew/CWB-bussiness2.0","homepage":null,"size":58249,"stargazers_count":0,"watchers_count":0,"language":"Blade","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"allow_forking":true,"is_template":false,"topics":[],"visibility":"private","forks":0,"open_issues":0,"watchers":0,"default_branch":"main"},"sender":{"login":"sjkhew","id":94550728,"node_id":"U_kgDOBaK6yA","avatar_url":"https://avatars.githubusercontent.com/u/94550728?v=4","gravatar_id":"","url":"https://api.github.com/users/sjkhew","html_url":"https://github.com/sjkhew","followers_url":"https://api.github.com/users/sjkhew/followers","following_url":"https://api.github.com/users/sjkhew/following{/other_user}","gists_url":"https://api.github.com/users/sjkhew/gists{/gist_id}","starred_url":"https://api.github.com/users/sjkhew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjkhew/subscriptions","organizations_url":"https://api.github.com/users/sjkhew/orgs","repos_url":"https://api.github.com/users/sjkhew/repos","events_url":"https://api.github.com/users/sjkhew/events{/privacy}","received_events_url":"https://api.github.com/users/sjkhew/received_events","type":"User","site_admin":false}}';
$header = array('Accept: */*','Content-type: application/json','User-Agent: GitHub-Hookshot/ded62e5','X-GitHub-Delivery: 19d716f0-b0d2-11ec-8ceb-749330235434','X-GitHub-Event: ping','X-GitHub-Hook-ID: 350825890','X-GitHub-Hook-Installation-Target-ID: 428559037','X-GitHub-Hook-Installation-Target-Type: repository','X-Hub-Signature: sha1=32fadce637aac6a8aa6249e25a18e9b9c38ea296','X-Hub-Signature-256: sha256=128bd101b73742a8a54802ff169bfd9304b502ef368e98c4f1416de9269aa181');
$url = 'http://127.0.0.1/deploy.example.php';

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT