grim/local-pipelines

2576d73b59b4
Parents 1de5185e6bf7
Children cf5a505d3e73
Add an option to run a shell instead of the build script.
--- a/pipelines/core.py Sat Sep 10 22:09:37 2016 -0500
+++ b/pipelines/core.py Mon Sep 19 13:26:47 2016 -0500
@@ -65,6 +65,16 @@
action='append',
)
+ parser.add_argument(
+ "-n",
+ help="Run a shell instead of the script in the container. The " +
+ "script can be run via /tmp/bitbucket-pipelines.sh. This " +
+ "will get weird if you're running more than one step.",
+ dest="run_shell",
+ action="store_true",
+ default=False,
+ )
+
return parser.parse_args()
@@ -127,6 +137,6 @@
k, v = _split_env_var(var)
env[k] = v
- pipeline = Pipeline(config, path, repo, env)
+ pipeline = Pipeline(config, path, repo, args.run_shell, env)
sys.exit(pipeline.run())
--- a/pipelines/pipeline.py Sat Sep 10 22:09:37 2016 -0500
+++ b/pipelines/pipeline.py Mon Sep 19 13:26:47 2016 -0500
@@ -26,12 +26,15 @@
class Pipeline(object):
- def __init__(self, config, path, repo, env=None):
+ def __init__(self, config, path, repo, run_shell=False, env=None):
self.config = config
self.build_path = os.path.abspath(path)
self.repo = repo
+ self.run_shell = run_shell
self._env = env or {}
+ print('{}({})'.format(self.run_shell, type(self.run_shell)))
+
# add special variables
self._env["BITBUCKET_BRANCH"] = self.repo.branch
self._env["BITBUCKET_COMMIT"] = self.repo.node
@@ -80,14 +83,23 @@
# assemble the pieces together
script = '/' + drive + spath.replace('\\', '/')
+ script_internal = "/tmp/bitbucket-pipelines.sh"
+
volumes = [
- "{filename}:{filename}:ro".format(filename=script),
+ "{filename}:{script_internal}:ro".format(
+ filename=script,
+ script_internal=script_internal,
+ ),
"{path}:{workdir}:rw".format(
path=self.build_path,
workdir=workdir,
),
]
+ command = script_internal
+ if self.run_shell:
+ command = ""
+
cmd = [
"docker",
"run",
@@ -102,7 +114,7 @@
self.public_env.items()]),
" ".join(["-e " + k for k in self.private_env.keys()]),
self._determine_image(step),
- script,
+ command,
]
return " ".join(cmd)