colossal-cricket-45577
05/18/2023, 11:29 PMfile(
name="grype",
source=
per_platform(
macos_arm64=http_source("<https://github.com/anchore/grype/releases/download/v0.61.1/grype_0.61.1_darwin_arm64.tar.gz>", sha256="6a72f55f3106c9498ec5f5f967c71da754951b61a3d6c9122e08652ec80e5e66", len=123456),
)
)
adhoc_tool(
name="grype-scan",
runnable=":grype",
args=[""],
execution_dependencies=[":scripts"],
output_directories=["logs/my-script.log"],
output_files=["results/"],
)
This does not work as file is not consider executable so it is refused by the runnable fieldbitter-ability-32190
05/18/2023, 11:33 PMbitter-ability-32190
05/18/2023, 11:34 PMdef external_tool(name, exe, url, len, sha256):
file(
name=f"downloaded-{name}",
source=http_source(
len=len,
sha256=sha256,
url=url,
),
)
filename = url.rsplit("/", 1)[-1]
command = f"chmod +x {filename}"
if filename.endswith(".tar.gz"):
command = f"tar -xf {filename} &&" + command
shell_command(
name=f"sandboxed-{name}",
command=command,
tools=["tar", "gzip", "chmod"],
execution_dependencies=[f":downloaded-{name}"],
output_directories=["."],
)
run_shell_command(
name=name,
command=f"exec -a $0 {{chroot}}/{build_file_dir() / exe}",
execution_dependencies=[f":sandboxed-{name}"],
workdir="/",
)
colossal-cricket-45577
05/18/2023, 11:38 PMbitter-ability-32190
05/19/2023, 1:07 AMbitter-ability-32190
05/19/2023, 1:07 AMcolossal-cricket-45577
05/19/2023, 1:13 AMdef external_tool(name, exe, url, len, sha256):
file(
name=f"downloaded-{name}",
source=http_source(
len=len,
sha256=sha256,
url=url,
),
)
filename = url.rsplit("/", 1)[-1]
command = f"chmod +x {filename}"
if filename.endswith(".tar.gz"):
command = f"tar -xf {filename} &&" + command
shell_command(
name=f"sandboxed-{name}",
command=command,
tools=["tar", "gzip", "chmod"],
execution_dependencies=[f":downloaded-{name}"],
output_directories=["."],
)
run_shell_command(
name=name,
command=f"exec -a $0 {{chroot}}/{build_file_dir() / exe}",
execution_dependencies=[f":sandboxed-{name}"],
workdir="/",
)
external_tool(
name="grype2",
exe="grype",
url="<https://github.com/anchore/grype/releases/download/v0.61.1/grype_0.61.1_darwin_arm64.tar.gz>",
sha256="6a72f55f3106c9498ec5f5f967c71da754951b61a3d6c9122e08652ec80e5e66",
len=16285210)
colossal-cricket-45577
05/19/2023, 1:13 AMPY=python3 PANTS_SOURCE=../pants pants run ci:grype2
Pantsd has been turned off via Env.
18:12:04.48 [INFO] Completed: Running the `shell_command` at `ci:sandboxed-grype2`
pants run ci:grype2 --: line 0: exec: run: not found
bitter-ability-32190
05/19/2023, 1:16 AM--keep-sandboxes=always
after pants
is illuminating. Let's you poke around the sandbox Pants created when runningcolossal-cricket-45577
05/19/2023, 1:19 AMbitter-ability-32190
05/19/2023, 1:22 AMcommand=f'exec -a "$0" {{chroot}}/{build_file_dir() / exe}',
colossal-cricket-45577
05/19/2023, 1:26 AMcolossal-cricket-45577
05/19/2023, 5:27 AMcolossal-cricket-45577
05/19/2023, 5:28 AMcolossal-cricket-45577
05/19/2023, 5:29 AMdocker_image(
name="website-preview",
source="Containerfile",
dependencies=[":sources", ":version"],
repository=".../website",
image_tags=["pr-{build_args.PULL_REQUEST}"],
description="Build website preview docker image",
extra_build_args=["PULL_REQUEST"],
)
grype_run(
name="grype",
tag=".../website:pr-{build_args.PULL_REQUEST}",
dependencies=[":website"],
)
colossal-cricket-45577
05/19/2023, 5:29 AMcolossal-cricket-45577
05/19/2023, 6:04 AMbitter-ability-32190
05/19/2023, 7:33 AMcurved-television-6568
05/19/2023, 11:01 AMcurved-television-6568
05/19/2023, 11:02 AMdocker_image
the field value is just a string, so you use the interpolation from a macro just as you would directly in the BUILD file.curved-television-6568
05/19/2023, 11:03 AMenv()
instead..colossal-cricket-45577
05/19/2023, 1:45 PM