|
| 1 | +Load Task Locally |
| 2 | +================= |
| 3 | + |
| 4 | +For tasks that use Docker, it might be useful to run the task's payload in a |
| 5 | +local container. This allows for faster debugging and iteration. |
| 6 | + |
| 7 | +Run: |
| 8 | + |
| 9 | +.. code-block:: shell |
| 10 | +
|
| 11 | + taskgraph load-task <task id> |
| 12 | +
|
| 13 | +This command does a few things: |
| 14 | + |
| 15 | +1. Retrieves the task's definition. |
| 16 | +2. Parses out the image that it uses. |
| 17 | +3. Fetches the image into your local Docker registry. |
| 18 | +4. Creates a container with the task's environment variables set. |
| 19 | +5. Runs the task's command in the container. |
| 20 | + |
| 21 | +Only tasks using the `docker-worker payload format`_ are supported. |
| 22 | + |
| 23 | +Load Tasks Interactively |
| 24 | +------------------------ |
| 25 | + |
| 26 | +For debugging purposes, you might want to do some set up before executing the |
| 27 | +task. To accomplish this, use the ``-i/--interactive`` flag: |
| 28 | + |
| 29 | +.. code-block:: shell |
| 30 | +
|
| 31 | + taskgraph load-task -i <task id> |
| 32 | +
|
| 33 | +This does all the same things up until step 5 above. Instead of running the |
| 34 | +task's command, it saves it to a binary called ``exec-task`` and drops you |
| 35 | +into an interactive shell. The task's environment variables will be set, and |
| 36 | +the repository will be cloned (if the task requires a source checkout). |
| 37 | + |
| 38 | +This allows you to inspect the state of the container, setup debuggers, etc. If |
| 39 | +and when you are ready, run ``exec-task`` to resume task execution. |
| 40 | + |
| 41 | +.. warning:: |
| 42 | + |
| 43 | + Only tasks that use the ``run-task`` script to bootstrap their commands |
| 44 | + are currently supported. |
| 45 | + |
| 46 | + |
| 47 | +Reading Task Definitions from Stdin |
| 48 | +----------------------------------- |
| 49 | + |
| 50 | +Instead of specifying a task id, you may also pipe the entire task definition |
| 51 | +via stdin. This is useful if you are making changes to the definition in your |
| 52 | +local Taskgraph and want to quickly test it without submitting a real task. |
| 53 | + |
| 54 | +For example, you can run: |
| 55 | + |
| 56 | +.. code-block:: shell |
| 57 | +
|
| 58 | + taskgraph morphed -J --tasks test-unit-py | jq -r 'to_entries | first | .value.task' | taskgraph load-task - |
| 59 | +
|
| 60 | +In this example, we're piping the definition of the task named ``test-unit-py`` |
| 61 | +into ``taskgraph load-task``. This allows you to quickly iterate on the task |
| 62 | +and test that it runs as expected. |
| 63 | + |
| 64 | +.. note:: |
| 65 | + |
| 66 | + The output of ``taskgraph morphed -J`` looks something like: |
| 67 | + |
| 68 | + ``{ "<task id>": { "task": { <task definition> }}}`` |
| 69 | + |
| 70 | + So we need to use ``jq`` to extract the definition of the first listed task. |
| 71 | + |
| 72 | +Using a Custom Image |
| 73 | +-------------------- |
| 74 | + |
| 75 | +We've seen how ``taskgraph load-task`` can be useful to debug and test tasks, |
| 76 | +but it is also useful when working on images! You can pass the ``--image`` flag |
| 77 | +to make the supplied task run in a custom Docker image. The image can be one of: |
| 78 | + |
| 79 | +* ``task-id=<task id>`` - Loads the image from the specified task id. The task |
| 80 | + id must reference a ``docker-image`` task. |
| 81 | +* ``index=<index>`` - Loads the image from the specified index path. The index |
| 82 | + path must reference a ``docker-image`` task. |
| 83 | +* ``<name>`` - Build the image produced by the ``docker-image`` task from the |
| 84 | + local Taskgraph called ``<name>``. |
| 85 | +* ``<registry>`` - Load the image from the specified Docker registry. |
| 86 | + |
| 87 | +Specifying ``<image name>`` is particularly useful when working on changes to |
| 88 | +the image. For example, let's say you're making changes to |
| 89 | +``taskcluster/docker/python/Dockerfile``, you can run: |
| 90 | + |
| 91 | +.. code-block:: shell |
| 92 | +
|
| 93 | + taskgraph load-task --image python <task id> |
| 94 | +
|
| 95 | +Where the task id is a task that uses the ``python`` image. |
| 96 | + |
| 97 | +Working on an Image and Task Simultaneously |
| 98 | +------------------------------------------- |
| 99 | + |
| 100 | +Sometimes you might need to make changes to the task definition and the image |
| 101 | +it uses in conjunction with one another. You can test changes to both simultaneously |
| 102 | +by combining passing in a custom image locally, and piping a task definition via stdin: |
| 103 | + |
| 104 | +.. code-block:: shell |
| 105 | +
|
| 106 | + taskgraph morphed -J --tasks test-unit-py | jq -r 'to_entries | first | .value.task' | taskgraph load-task --image python - |
| 107 | +
|
| 108 | +.. _docker-worker payload format: https://docs.taskcluster.net/docs/reference/workers/docker-worker/payload |
0 commit comments