Closed mvgijssel closed 1 year ago
Maybe also cool to support is a Python entrypoint, like target_postgres:main
! This makes it easier to wrap existing Python executables with new logic.
Possible api:
task_test(
name = "provisioner_test",
cmds = [
cmd.python("""
print("we are done!")
""").defer(),
"CONTAINER_ID=$($start_dev_image)",
{"defer": "docker rm -f $CONTAINER_ID"},
"$provision @docker/$CONTAINER_ID deploy.py",
"$test --hosts='docker://$CONTAINER_ID'",
],
desc = "Test the provisioner by creating a container, running pyinfra, and running tests.",
env = {
"SETUP_ENV": "test",
"start_dev_image": cmd.shell(cmd.r("//provisioner:dev_image"), '--', '--detach'),
"provision": cmd.r("//provisioner:provision"),
"test": cmd.r("//provisioner:test"),
},
)
With communication between Python and bash:
task(
name = "connect",
cmds = [
"source $($aws_credentials)",
"$connect $@",
],
env = {
"aws_credentials": cmd.python("""
print("export AWS_ACCESS_KEY=something")
"""),
"connect": cmd.l("//tools/dev_env:connect")
}
)
cmd.shell: run a shell command, can do exec form or regular form cmd.python: run a piece of python code cmd.python_inline: run a piece of python code which is attached to the task runtime, meaning it's able to modify the overall behaviour of the task cmd.l: return the file location of the target cmd.e: return the executable file location (not sure if this is needed next to cmd.l) {defer: ...}: defer the execution of the command until the end of the task
Potential API: