diff --git a/spring_image.bzl b/spring_image.bzl index 4cbc6f8..41914ae 100644 --- a/spring_image.bzl +++ b/spring_image.bzl @@ -124,10 +124,20 @@ def tar_jars(ctx, files, out): java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] jar_path = "%s/bin/jar" % java_runtime.java_home paths = [f.path for f in files] + spring_components_file_path = "spring.components" + spring_components_file = ctx.actions.declare_file(spring_components_file_path) ctx.actions.run_shell( inputs = ctx.files._jdk + files, + outputs = [spring_components_file], + command = "touch {file}; for i in {all_paths}; do {jar} xf $i && if [ -s META-INF/spring.components ]; then cat META-INF/spring.components >> {file}; fi; done".format(file = spring_components_file.path, jar = jar_path, all_paths = " ".join(paths)), + ) + + ctx.actions.run_shell( + inputs = ctx.files._jdk + files + [spring_components_file], outputs = [out], - command = 'tar cf %s -T /dev/null && for i in %s; do %s xf ${i} && %s tf ${i} | tar rf %s --transform "s,^,BOOT-INF/classes/," -T -; done' % (out.path, " ".join(paths), jar_path, jar_path, out.path), + # Create an empty tarball, then extract all the jars and append the contents into it. + # TODO: get rid of the hardcoded bazel-out path in the first transform. + command = 'tar cf {out} -T /dev/null && if [ -s {scf} ]; then tar rhf {out} --transform "s,bazel-out/k8-fastbuild/bin/,BOOT-INF/classes/META-INF/," {scf}; fi && for i in {all_paths}; do {jar} xf $i && {jar} tf $i | tar rf {out} --transform "s,^,BOOT-INF/classes/," -T -; done'.format(out = out.path, all_paths = " ".join(paths), jar = jar_path, scf = spring_components_file.path), ) def _application_copier_rule_impl(ctx):