summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2015-08-20 19:38:21 +0200
committerOliver Poignant <oliver@poignant.se>2015-08-20 19:38:21 +0200
commitbc73b20fb8b1074cedb188b59a8045cdd4ef6952 (patch)
treeed3486ed556520b849626a2e97c594aee4025dd7
parent79a6544498d048f00d48088478bc2535acd45189 (diff)
downloadGit-Auto-Deploy-bc73b20fb8b1074cedb188b59a8045cdd4ef6952.zip
Git-Auto-Deploy-bc73b20fb8b1074cedb188b59a8045cdd4ef6952.tar.gz
Git-Auto-Deploy-bc73b20fb8b1074cedb188b59a8045cdd4ef6952.tar.bz2
Fixed new bug in daemon mode. Fixed bug where git pull were invoked twice.
-rw-r--r--.gitignore2
-rwxr-xr-xGitAutoDeploy.py46
2 files changed, 27 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index e226abf..9e9de5f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,6 +58,8 @@ docs/_build/
target/
GitAutoDeploy.conf.json
+*.json
+
.idea
.DS_Store
._.DS_Store
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index 205997c..eb471fd 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -61,12 +61,18 @@ class GitWrapper():
print "Post push request received"
print 'Updating ' + repo_config['path']
- res = call(['sleep 5; cd "' +
- repo_config['path'] +
- '" && unset GIT_DIR && git fetch origin && git update-index --refresh && git reset --hard origin/' +
- branch + ' && git submodule init && git submodule update'], shell=True)
- call(['echo "Pull result: ' + str(res) + '"'], shell=True)
- return res
+ cmd = 'cd "' + repo_config['path'] + '"'\
+ '&& unset GIT_DIR ' +\
+ '&& git fetch origin ' +\
+ '&& git update-index --refresh ' +\
+ '&& git reset --hard origin/' + branch + ' ' +\
+ '&& git submodule init ' +\
+ '&& git submodule update'
+
+ res = call([cmd], shell=True)
+ print 'Pull result: ' + str(res)
+
+ return int(res)
@staticmethod
def clone(url, path):
@@ -289,6 +295,7 @@ class GitAutoDeploy(object):
n = 4
while 0 < n and 0 != GitWrapper.pull(repo_config):
n -= 1
+
if 0 < n:
GitWrapper.deploy(repo_config)
@@ -364,10 +371,6 @@ class GitAutoDeploy(object):
print "Directory %s is not a Git repository" % repo_config['path']
sys.exit(2)
- # Clear any existing lock files, with no regard to possible ongoing processes
- Lock(os.path.join(repo_config['path'], 'status_running')).clear()
- Lock(os.path.join(repo_config['path'], 'status_waiting')).clear()
-
return self._config
def get_matching_repo_configs(self, urls):
@@ -379,6 +382,8 @@ class GitAutoDeploy(object):
for url in urls:
for repo_config in config['repositories']:
+ if repo_config in configs:
+ continue
if repo_config['url'] == url:
configs.append(repo_config)
elif 'url_without_usernme' in repo_config and repo_config['url_without_usernme'] == url:
@@ -440,13 +445,11 @@ class GitAutoDeploy(object):
import sys
from BaseHTTPServer import HTTPServer
import socket
+ import os
if '-d' in argv or '--daemon-mode' in argv:
self.daemon = True
- if '-q' in argv or '--quiet' in argv:
- sys.stdout = open(os.devnull, 'w')
-
if '--ssh-keygen' in argv:
print 'Scanning repository hosts for ssh keys...'
self.ssh_key_scan()
@@ -456,28 +459,29 @@ class GitAutoDeploy(object):
self.kill_conflicting_processes()
if '--config' in argv:
- import os
pos = argv.index('--config')
if len(argv) > pos + 1:
self.config_path = os.path.realpath(argv[argv.index('--config') + 1])
print 'Using custom configuration file \'%s\'' % self.config_path
- if GitAutoDeploy.daemon:
+ if self.daemon:
pid = os.fork()
if pid > 0:
+ print 'Git Auto Deploy started in daemon mode'
sys.exit(0)
os.setsid()
+ else:
+ print 'Git Auto Deploy started'
self.create_pid_file()
- if self.daemon:
- print 'GitHub & GitLab auto deploy service v 0.1 started in daemon mode'
-
- # Disable output in daemon mode
+ if '-q' in argv or '--quiet' in argv or self.daemon is True:
sys.stdout = open(os.devnull, 'w')
- else:
- print 'GitHub & GitLab auto deploy service v 0.1 started'
+ # Clear any existing lock files, with no regard to possible ongoing processes
+ for repo_config in self.get_config()['repositories']:
+ Lock(os.path.join(repo_config['path'], 'status_running')).clear()
+ Lock(os.path.join(repo_config['path'], 'status_waiting')).clear()
try:
self._server = HTTPServer((self.get_config()['host'], self.get_config()['port']), WebhookRequestHandler)