--- a/pipelines/core.py Mon Jul 25 20:41:45 2016 -0500
+++ b/pipelines/core.py Mon Jul 25 23:55:16 2016 -0500
@@ -8,6 +8,8 @@
+from docker import Client from pipelines import vcs
from pipelines.pipeline import Pipeline
@@ -23,6 +25,14 @@
dest="pipeline_filename",
+ help="Daemon socket to connect to", + default="unix://var/run/docker.sock", return parser.parse_args()
@@ -39,10 +49,12 @@
+ client = Client(base_url=args.host) path, config = _load_config(args.pipeline_filename)
branch = vcs.get_branch(path)
- pipeline = Pipeline(config, path, branch)
+ pipeline = Pipeline(client, config, path, branch) --- a/pipelines/pipeline.py Mon Jul 25 20:41:45 2016 -0500
+++ b/pipelines/pipeline.py Mon Jul 25 23:55:16 2016 -0500
@@ -2,12 +2,12 @@
- def __init__(self, config, path, branch):
+ def __init__(self, client, config, path, branch): self.build_path = os.path.abspath(path)
@@ -32,52 +32,70 @@
filename = os.path.realpath(filename)
with os.fdopen(fd, "w") as ofp:
+ ofp.write("#!/bin/bash\n") content = " && \\\n".join(step["script"])
- def get_command(self, step):
- # TODONT cidfile This is only used by the host.
- "--entrypoint=/bin/bash",
- "-v {script_filename}:/tmp/{script_filename}:ro",
- "-v {build_path}:/opt/atlassian/bitbucketci/agent/build:rw",
- "-w /opt/atlassian/bitbucketci/agent/build",
- "--label com.atlassian.pipelines.agent=\"local\"",
- # TODO didn't work for me... "-i",
- "/tmp/{script_filename}",
+ def _container(self, step): + script_filename = self._build_script(step) + "com.atlassian.pipelines.agent": "local", - return " ".join(cmd).format(
- script_filename=self._build_script(step),
- build_path=self.build_path,
+ "bind": script_filename, + "bind": "/opt/atlassian/bitbucketci/agent/build", + return self.client.create_container( image=self._determine_image(step),
+ command=script_filename, + working_dir="/opt/atlassian/bitbucketci/agent/build", + entrypoint="/bin/bash", + host_config=self.client.create_host_config(
- for container in self.steps:
- step = container["step"]
- commands.append(self.get_command(step))
+ return [s["step"] for s in self.steps] - for command in self._commands():
- print('+ {}'.format(command))
- proc = subprocess.Popen(command.split())
+ for n, step in enumerate(self._steps()): + container = self._container(step) + self.client.start(container=container.get("Id")) - return_code = proc.wait()
+ logs = self.client.logs( + container=container.get("Id"), + print('step-{} {}'.format(n, line.strip())) + return_code = self.client.wait(container.get("Id")) + self.client.remove_container(container["Id"]) --- a/requirements.txt Mon Jul 25 20:41:45 2016 -0500
+++ b/requirements.txt Mon Jul 25 23:55:16 2016 -0500
@@ -1,1 +1,3 @@