ArtifactsService: Add image archives endpoint.

Add endpoint to create a .tar.xz archive for each image that
has been created. This allows easier access to specific images.

BUG=chromium:996771
TEST=./run_tests
TEST=manually ran endpoint

Change-Id: If6eb715f3e1a35f733aeb946eff70eb1f568c20d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1809253
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: David Burger <dburger@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index 83a6910..5d9ae8f 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -47,6 +47,22 @@
 
 
 @faux.all_empty
+@validate.require('build_target.name')
+@validate.exists('output_dir')
+@validate.validation_complete
+def BundleImageArchives(input_proto, output_proto, _config):
+  """Create a .tar.xz archive for each image that has been created."""
+  build_target = controller_util.ParseBuildTarget(input_proto.build_target)
+  output_dir = input_proto.output_dir
+  image_dir = _GetImageDir(constants.SOURCE_ROOT, build_target.name)
+
+  archives = artifacts.ArchiveImages(image_dir, output_dir)
+
+  for archive in archives:
+    output_proto.artifacts.add().path = os.path.join(output_dir, archive)
+
+
+@faux.all_empty
 @validate.require('build_target.name', 'output_dir')
 @validate.exists('output_dir')
 @validate.validation_complete