summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--GitAutoDeploy.conf.json.example16
-rwxr-xr-xGitAutoDeploy.py11
-rw-r--r--README.md73
4 files changed, 66 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index 9b5e74b..e226abf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,4 +58,6 @@ docs/_build/
target/
GitAutoDeploy.conf.json
-.idea \ No newline at end of file
+.idea
+.DS_Store
+._.DS_Store
diff --git a/GitAutoDeploy.conf.json.example b/GitAutoDeploy.conf.json.example
index b3b2c4e..5e038f1 100644
--- a/GitAutoDeploy.conf.json.example
+++ b/GitAutoDeploy.conf.json.example
@@ -1,20 +1,20 @@
{
- "pidfilepath": "/var/run/gitautodeploy/gitautodeploy.pid",
- "host": "localhost",
+ "pidfilepath": "~/.gitautodeploy.pid",
+ "host": "0.0.0.0",
"port": 8001,
"global_deploy": [
- "echo Starting deploy!",
- "echo Ending deploy!"
+ "echo Deploy started!",
+ "echo Deploy completed!"
],
"repositories":
[{
- "url": "https://github.com/logsol/Test-Repo",
+ "url": "https://github.com/olipo186/Github-Gitlab-Auto-Deploy.git",
"branch": "master",
- "path": "/home/logsol/projects/Test-Repo",
+ "path": "~/repositories/Github-Gitlab-Auto-Deploy",
"deploy": "echo deploying"
},
{
- "url": "https://github.com/logsol/Katharsis-Framework",
- "path": "/home/logsol/projects/Katharsis-Framework"
+ "url": "https://github.com/github/gitignore",
+ "path": "~/repositories/gitignore"
}]
}
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index 126e86e..5420774 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -321,8 +321,16 @@ class GitAutoDeploy(object):
print "%s file is not valid JSON\n" % self.config_path
raise e
+ # Translate any ~ in the path into /home/<user>
+ if 'pidfilepath' in self._config:
+ self._config['pidfilepath'] = os.path.expanduser(self._config['pidfilepath'])
+
for repo_config in self._config['repositories']:
+ # Translate any ~ in the path into /home/<user>
+ if 'path' in repo_config:
+ repo_config['path'] = os.path.expanduser(repo_config['path'])
+
if not os.path.isdir(repo_config['path']):
print "Directory %s not found" % repo_config['path']
@@ -393,7 +401,7 @@ class GitAutoDeploy(object):
f.write(str(os.getpid()))
def read_pid_file(self):
- with open(self.get_config()['pidfilepath'],'r') as f:
+ with open(self.get_config()['pidfilepath'], 'r') as f:
return f.readlines()
def remove_pid_file(self):
@@ -402,7 +410,6 @@ class GitAutoDeploy(object):
def exit(self):
import sys
-
print '\nGoodbye'
self.remove_pid_file()
sys.exit(0)
diff --git a/README.md b/README.md
index aa9fe00..31ee33c 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,43 @@
-![How it works](http://olipo186.github.com/Github-Gitlab-Auto-Deploy/images/Github-Gitlab-Auto-Deploy.png)
-
# What is it?
+GitAutoDeploy.py consists of a small HTTP server that listens for Web hook requests sent from GitHub, GitLab or Bitbucket servers. The script allows you to continuously and automatically deploy you projects during development each time you push new commits to GitHub, GitLab or Bitbucket.</p>
+
+![Flow](http://olipo186.github.com/Github-Gitlab-Auto-Deploy/images/Github-Gitlab-Auto-Deploy.png)
+
+# 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.</p>
+
+# Getting started
+## Dependencies
+* Git (tested on version 2.5.0)
+* Python (tested on version 2.7)
+
+## Configuration
-This is a small HTTP server written in python.
-It allows you to have a version of your project installed, that will be updated automatically on each Github or Gitlab push.
+* 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.
-To set it up, do the following:
-* Install python
-* Copy the ```GitAutoDeploy.conf.json.example``` to ```GitAutoDeploy.conf.json```. This file will be gitignored and can be environment specific.
-* Enter the matching for your project(s) in the ```GitAutoDeploy.conf.json``` file
-* Start the server by typing ```python GitAutoDeploy.py```
-* To run it as a daemon add ```--daemon-mode```
-* On the Github or Gitlab page go to a repository, then "Admin", "Service Hooks",
-"Post-Receive URLs" and add the url of your machine + port (e.g. ```http://example.com:8001```).
+## Running the application
+```python GitAutoDeploy.py```
-You can even test the whole thing here, by clicking on the "Test Hook" button, whohoo!
+## Command line options
-# Configure GitAutoDeploy to get executed at start up
+```--daemon-mode (-d)``` Run in background (daemon mode)
+```--quiet (-q)``` Suppress all output
+```--ssh-keygen```
+```--force```
+```--config <path>``` 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.
@@ -27,19 +47,18 @@ You can even test the whole thing here, by clicking on the "Test Hook" button, w
* 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```
-### Systemd
-
-* TODO
-
-# How this works
-
-When someone pushes changes into Github or Gitlab, it sends a json file to the service hook url.
-It contains information about the repository that was updated.
+## Configure GitHub
-All it really does is match the repository urls to your local repository paths in the config file,
-move there and run "git pull".
+* Go to your repository -> Settings -> Webhooks and Services -> Add webhook</li>
+* 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"
-Additionally it runs a deploy bash command that you can add to the config file optionally, and it also
-allows you to add two global deploy commands, one that would run at the beginning and one that would run at the end of the deploy.
-Make sure that you start the server as the user that is allowed to pull from the github or gitlab repository.
+## Configure Bitbucket
+* Go to your repository -> Settings -> Webhooks -> Add webhook
+* In "URL", enter your hostname and port (your-host:8001)
+* Hit "Save"