vgijssel / setup

Workstation and server setup
MIT License
8 stars 0 forks source link

Create rules_task #182

Closed mvgijssel closed 1 year ago

mvgijssel commented 1 year ago

Potential API:

command(
  name = "hello",
  ops = [
    "ls -la somedir",
    ["ls", "-la", "somedir"],
    [ops.r(":ls"), "-la", "somedir"]
    ops.shell("ls", "-la", "somedir"),
    ops.shell(ops.r(":ls"), "-la", "somedir"),
    ops.python('print(' + ops.r(":ls") + ')'),
  ]
  cwd = "{{ os.environ['BUILD_WORKSPACE_DIRECTORY'] }}"
)
mvgijssel commented 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.

mvgijssel commented 1 year ago

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"),
    },
)
mvgijssel commented 1 year ago

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")
    }
)
mvgijssel commented 1 year ago

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