diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-12-05 18:48:16 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2018-01-11 17:13:10 +0000 |
commit | 1490802c9a2b13bce8762e73db0a1110441223e5 (patch) | |
tree | ecc40fb2016929241730e5d81cb5b773ab139054 | |
parent | d7959bd45493dc58ed6bc84aa2cf40b69b6854c6 (diff) | |
download | buildstream-1490802c9a2b13bce8762e73db0a1110441223e5.tar.gz |
Add `bst push --remote` and `bst pull --remote`
This allows pushing and pulling from a specific cache, ignoring what is
configured.
If we choose to add a --remote option to `bst build` in future that
would now be simple to do.
-rw-r--r-- | buildstream/_frontend/main.py | 34 | ||||
-rw-r--r-- | buildstream/_pipeline.py | 25 |
2 files changed, 44 insertions, 15 deletions
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index 2dd7ae701..200d6b5d9 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -219,7 +219,7 @@ def build(app, elements, all, track, track_save, track_all, track_except): track = elements app.initialize(elements, except_=track_except, rewritable=track_save, - use_remote_cache=True, inconsistent=track) + use_configured_remote_caches=True, inconsistent=track) app.print_heading() try: app.pipeline.build(app.scheduler, all, track, track_save) @@ -319,19 +319,26 @@ def track(app, elements, deps, except_): @click.option('--deps', '-d', default='none', type=click.Choice(['none', 'all']), help='The dependency artifacts to pull (default: none)') +@click.option('--remote', '-r', + help="The URL of the remote cache (defaults to the first configured cache)") @click.argument('elements', nargs=-1, type=click.Path(dir_okay=False, readable=True)) @click.pass_obj -def pull(app, elements, deps): +def pull(app, elements, deps, remote): """Pull a built artifact from the configured remote artifact cache. + By default the artifact will be pulled one of the configured caches + if possible, following the usual priority order. If the `--remote` flag + is given, only the specified cache will be queried. + Specify `--deps` to control which artifacts to pull: \b none: No dependencies, just the element itself all: All dependencies """ - app.initialize(elements, use_remote_cache=True) + app.initialize(elements, use_configured_remote_caches=(remote is None), + add_remote_cache=remote) try: to_pull = app.pipeline.deps_elements(deps) app.pipeline.pull(app.scheduler, to_pull) @@ -349,11 +356,16 @@ def pull(app, elements, deps): @click.option('--deps', '-d', default='none', type=click.Choice(['none', 'all']), help='The dependencies to push (default: none)') +@click.option('--remote', '-r', default=None, + help="The URL of the remote cache (defaults to the first configured cache)") @click.argument('elements', nargs=-1, type=click.Path(dir_okay=False, readable=True)) @click.pass_obj -def push(app, elements, deps): - """Push a built artifact to the configured remote artifact cache. +def push(app, elements, deps, remote): + """Push a built artifact to a remote artifact cache. + + The default destination is the highest priority configured cache. You can + override this by passing a different cache URL with the `--remote` flag. Specify `--deps` to control which artifacts to push: @@ -361,7 +373,8 @@ def push(app, elements, deps): none: No dependencies, just the element itself all: All dependencies """ - app.initialize(elements, use_remote_cache=True) + app.initialize(elements, use_configured_remote_caches=(remote is None), + add_remote_cache=remote) try: to_push = app.pipeline.deps_elements(deps) app.pipeline.push(app.scheduler, to_push) @@ -440,7 +453,7 @@ def show(app, elements, deps, except_, order, format, downloadable): bst show target.bst --format \\ $'---------- %{name} ----------\\n%{vars}' """ - app.initialize(elements, except_=except_, use_remote_cache=downloadable) + app.initialize(elements, except_=except_, use_configured_remote_caches=downloadable) try: dependencies = app.pipeline.deps_elements(deps) except PipelineError as e: @@ -770,7 +783,8 @@ class App(): # Initialize the main pipeline # def initialize(self, elements, except_=tuple(), rewritable=False, - inconsistent=None, use_remote_cache=False): + use_configured_remote_caches=False, add_remote_cache=None, + inconsistent=None): profile_start(Topics.LOAD_PIPELINE, "_".join(t.replace(os.sep, '-') for t in elements)) @@ -857,7 +871,9 @@ class App(): # Initialize pipeline try: - self.pipeline.initialize(use_remote_cache=use_remote_cache, inconsistent=inconsistent) + self.pipeline.initialize(use_configured_remote_caches=use_configured_remote_caches, + add_remote_cache=add_remote_cache, + inconsistent=inconsistent) except BstError as e: click.echo("Error initializing pipeline: {}".format(e), err=True) sys.exit(-1) diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index db4c7fa85..01f3e41be 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -94,7 +94,13 @@ class Planner(): # current source refs will not be the effective refs. # rewritable (bool): Whether the loaded files should be rewritable # this is a bit more expensive due to deep copies -# use_remote_cache (bool): Whether to connect with remote artifact cache +# use_configured_remote_caches (bool): Whether to connect to configured artifact remotes. +# add_remote_cache (str): Adds an additional artifact remote URL, which is +# prepended to the list of remotes (and thus given highest priority). +# +# The ticker methods will be called with an element name for each tick, a final +# tick with None as the argument is passed to signal that processing of this +# stage has terminated. # # Raises: # LoadError @@ -137,7 +143,8 @@ class Pipeline(): self.targets = resolved_elements[:len(targets)] self.exceptions = resolved_elements[len(targets):] - def initialize(self, use_remote_cache=False, inconsistent=None): + def initialize(self, use_configured_remote_caches=False, + add_remote_cache=None, inconsistent=None): # Preflight directly, before ever interrogating caches or # anything. self.preflight() @@ -146,8 +153,15 @@ class Pipeline(): self.initialize_workspaces() - if use_remote_cache: - self.initialize_remote_caches() + # Initialize remote artifact caches. We allow the commandline to override + # the user config in some cases (for example `bst push --remote=...`). + artifact_urls = [] + if add_remote_cache: + artifact_urls += [add_remote_cache] + if use_configured_remote_caches: + artifact_urls += configured_artifact_cache_urls(self.context, self.project) + if len(artifact_urls) > 0: + self.initialize_remote_caches(artifact_urls) self.resolve_cache_keys(inconsistent) @@ -175,12 +189,11 @@ class Pipeline(): self.project._set_workspace(element, source, workspace) - def initialize_remote_caches(self): + def initialize_remote_caches(self, artifact_urls): def remote_failed(url, error): self.message(MessageType.WARN, "Failed to fetch remote refs from {}: {}\n".format(url, error)) with self.timed_activity("Initializing remote caches", silent_nested=True): - artifact_urls = configured_artifact_cache_urls(self.context, self.project) self.artifacts.set_remotes(artifact_urls, on_failure=remote_failed) def resolve_cache_keys(self, inconsistent): |