summaryrefslogtreecommitdiff
path: root/ick
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-05-09 18:01:28 +0300
committerLars Wirzenius <liw@liw.fi>2015-05-09 18:08:59 +0300
commit9c7c79ca2c463e55199016087e081f00cfa4e60e (patch)
tree6766537d5e8f1d30488051bf1a6217403599be98 /ick
parent48113a55507c666092c272cd0063359a2b5e2cbc (diff)
downloadick-9c7c79ca2c463e55199016087e081f00cfa4e60e.tar.gz
Clone git repository to each target
Diffstat (limited to 'ick')
-rwxr-xr-xick47
1 files changed, 38 insertions, 9 deletions
diff --git a/ick b/ick
index 1d30a23..6776b56 100755
--- a/ick
+++ b/ick
@@ -18,7 +18,9 @@
import logging
+import shutil
import subprocess
+import tempfile
import cliapp
import yaml
@@ -51,19 +53,45 @@ class Ick(cliapp.Application):
with self.logger:
self.logger.log(
'Building project {project_name}', project_name=project_name)
- for target_name, target in targets.items():
- self.build_on_target(
- project_name, project, target_name, target)
-
- def build_on_target(self, project_name, project, target_name, target):
+ git_dir = self.clone_git_repository_locally(
+ project['git'], project['branch'])
+ try:
+ for target_name, target in targets.items():
+ self.build_on_target(
+ project_name, project, target_name, target, git_dir)
+ except Exception:
+ shutil.rmtree(git_dir)
+ raise
+
+ def clone_git_repository_locally(self, url, branch):
+ git_dir = tempfile.mkdtemp()
+ cliapp.runcmd(['git', 'clone', '--verbose', '--branch', branch, url, git_dir])
+ return git_dir
+
+ def build_on_target(self, project_name, project, target_name, target,
+ git_dir):
with self.logger:
self.logger.log(
'Building {project_name} on {target_name}',
project_name=project_name, target_name=target_name)
- for command in project.get('commands', []):
- self.run_on_target(target['address'], command)
-
- def run_on_target(self, address, command):
+ address = target['address']
+ remote_git_dir = self.rsync_to_target(git_dir, address)
+ try:
+ for command in project.get('commands', []):
+ self.run_on_target(address, command, remote_git_dir)
+ except cliapp.AppException:
+ cliapp.ssh_runcmd(address, ['rm', '-rf', remote_git_dir])
+ raise
+
+ def rsync_to_target(self, source, address):
+ output = cliapp.ssh_runcmd(address, ['mktemp', '-d'])
+ remote_git_dir = output.strip()
+ cliapp.runcmd(
+ ['rsync', '-aHSs', source + '/.',
+ '%s:%s/.' % (address, remote_git_dir)])
+ return remote_git_dir
+
+ def run_on_target(self, address, command, remote_cwd):
with self.logger:
self.logger.log(
'On {address} run {command}',
@@ -71,6 +99,7 @@ class Ick(cliapp.Application):
output = cliapp.ssh_runcmd(
address,
['sh', '-euxc', command],
+ remote_cwd=remote_cwd,
stderr=subprocess.STDOUT)
self.log_output(output)