/Git-Auto-Deploy

Deploy your GitHub, GitLab or Bitbucket projects automatically on Git push events or webhooks using this small HTTP server written in Python. Continuous deployment in it's most simple form.

Primary LanguagePythonOtherNOASSERTION

What is it?

GitAutoDeploy.py consists of a small HTTP server that listens for Web hook requests sent from GitHub, GitLab or Bitbucket servers. This application allows you to continuously and automatically deploy you projects each time you push new commits to GitHub, GitLab or Bitbucket repository.

workflow

How does it work?

When commits are pushed to your Git repository, the Git server will notify GitAutoDeploy.py by sending a HTTP POST request with a JSON body to a pre configured URL (your-host:8001). The JSON body contains detailed information about the repository and what event that triggered the request. GitAutoDeploy.py parses and validates the request, and if all goes well it issues a git pull.

Additionally, GitAutoDeploy.py can be configured to execute a shell command upon each successful "git pull", which can be used to trigger custom build actions.

Getting started

Dependencies

  • Git (tested on version 2.5.0)
  • Python (tested on version 2.7)

Configuration

  • Copy GitAutoDeploy.conf.json.example to GitAutoDeploy.conf.json
  • Modify GitAutoDeploy.conf.json to match your project setup
  • Make sure that the pidfilepath path is writable for the user running the script, as well as any other path configured for your repositories.

Running the application

python GitAutoDeploy.py

Command line options

--daemon-mode (-d) Run in background (daemon mode) --quiet (-q) Suppress all output --ssh-keygen --force --config Specify custom configuration file

Start automatically on boot

Crontab

The easiest way to configure your system to automatically start GitAutoDeploy.py after a reboot is through crontab. Open crontab in edit mode using crontab -e and add the following:

@reboot /usr/bin/python /path/to/GitAutoDeploy.py --daemon-mode --quiet

Debian and Sys-V like init system.

  • Copy file initfiles/debianLSBInitScripts/gitautodeploy to /etc/init.d/
  • Make it executable: chmod 755 /etc/init.d/gitautodeploy
  • Also you need to make GitAutoDeploy.py executable (if it isn't already): chmod 755 GitAutoDeploy.py
  • This init script assumes that you have GitAutoDeploy.py in /opt/Gitlab_Auto_Deploy/GitAutoDeploy.py. If this is not the case, edit gitautodeploy init script and modify DAEMON and PWD.
  • Now you need to add the correct symbolic link to your specific runlevel dir to get the script executed on each start up. On Debian_Sys-V just do update.rc.d gitautodeploy defaults

Configure GitHub

  • Go to your repository -> Settings -> Webhooks and Services -> Add webhook
  • In "Payload URL", enter your hostname and port (your-host:8001)
  • Hit "Add webhook"

Configure GitLab

  • Go to your repository -> Settings -> Web hooks
  • In "URL", enter your hostname and port (your-host:8001)
  • Hit "Add Web Hook"

Configure Bitbucket

  • Go to your repository -> Settings -> Webhooks -> Add webhook
  • In "URL", enter your hostname and port (your-host:8001)
  • Hit "Save"