kind-angle-20894
02/02/2023, 1:50 PMexperimental_shell_command(
command="./script.sh",
tools=["echo", "bash"],
dependencies=[":docker"],
)
fresh-cat-90827
02/02/2023, 2:51 PMexperimental_run_shell_command
if you want to run the script directly in your workspacefresh-cat-90827
02/02/2023, 2:51 PMkind-angle-20894
02/02/2023, 3:07 PMkind-angle-20894
02/02/2023, 3:08 PM./pants publish <my-image>
the images will build, then my script will runfresh-cat-90827
02/02/2023, 3:14 PMexperimental_shell_command
like this:
python_tests(name="root-run-py", dependencies=[":root-script"], sources=["test_run.py"])
experimental_shell_command(
name="root-script",
command="./script.sh",
tools=["echo", "bash"],
dependencies=[":shell-scripts"],
outputs=["my-script.log"],
log_output=True,
)
shell_sources(name="shell-scripts", sources=["script.sh"])
# test_run.py
def test_example():
with open("my-script.log") as fh:
assert fh.read().strip() == "hello"
script.sh
#!/usr/bin/env bash
echo "hello" > my-script.log
fresh-cat-90827
02/02/2023, 3:14 PM❯ ./pants test test_run.py
15:11:05.83 [INFO] Completed: Run Pytest - //test_run.py:root-run-py succeeded.
✓ //test_run.py:root-run-py succeeded in 0.23s.
fresh-cat-90827
02/02/2023, 3:15 PMscript.sh
before running the test (it creates a file in the sandbox where test is run). And we declare the dependency via dependencies=[":root-script"]
in the python_tests
targetfresh-cat-90827
02/02/2023, 3:19 PMSo that when I run ./pants publish <my-image> the images will build, then my script will runI don't think it is possible OOTB. Without writing a plugin, I think it would be just easier to do a separate
./pants run
. Perhaps all the information you need can be extracted from the targets via the peek
goal?kind-angle-20894
02/02/2023, 3:20 PMkind-angle-20894
02/02/2023, 3:22 PMkind-angle-20894
02/02/2023, 3:22 PMexperimental_run_shell_command(
name="hello",
command="docker images",
dependencies=[":docker"],
)
./pants run packages/backend:hello
This triggers a docker build and then runs the commandkind-angle-20894
02/02/2023, 3:22 PMfresh-cat-90827
02/02/2023, 3:23 PMIs it possible to pass arguments to the docker target in this way?sorry, I am not sure I follow
kind-angle-20894
02/02/2023, 3:25 PM--tag
argument to the docker target as though I was calling /pants --tag=blabla publish packages/backend:docker
kind-angle-20894
02/02/2023, 3:25 PMpackage
with no arguments on my docker targetfresh-cat-90827
02/02/2023, 3:27 PMkind-angle-20894
02/02/2023, 3:30 PMcurved-television-6568
02/02/2023, 4:07 PM./pants …
you can pass additional options for any/all subsystems as needed along with it, so something like ./pants run --docker-build-args="…" packages/backend:hello
would allow you to provide options for docker on the command line when running your shell script target.curved-television-6568
02/02/2023, 4:08 PM