Skip to content

Commit cdee31d

Browse files
committed
ci: split a new 'run-task' image out of Decision image
This can be used in places where we just want run-task without a specific Taskgraph version baked in. Issue: #464
1 parent 866f39f commit cdee31d

File tree

7 files changed

+141
-53
lines changed

7 files changed

+141
-53
lines changed

docs/howto/bootstrap-taskgraph.rst

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,74 @@ Bootstrap Taskgraph in Decision Task
44
This how-to guide outlines the recommended way to bootstrap Taskgraph (and
55
other task generation dependencies) in a :term:`Decision Task`.
66

7-
If you'd like to follow along, you can download the example
8-
:download:`.taskcluster.yml </tutorials/example-taskcluster.yml>` file.
7+
Using the Pre-Built Docker Images
8+
---------------------------------
9+
10+
The simplest way to make Taskgraph available to your Decision task is to use
11+
Taskgraph's pre-built Docker images under the `mozillareleases/taskgraph`_ Docker Hub
12+
repository.
13+
14+
In your Decision task definition in ``.taskcluster.yml``, add the following to the task's
15+
``payload`` section:
16+
17+
.. code-block:: yaml
18+
19+
payload:
20+
image: mozillareleases/taskgraph:decision-latest
21+
22+
This will ensure your Decision task always run with the latest version of Taskgraph.
23+
Of course, it's best practice to pin your CI dependencies, so it's recommended to pin
24+
to a specific version:
25+
26+
.. code-block:: yaml
27+
28+
payload:
29+
image: mozillareleases/taskgraph:decision-v7.3.0
30+
31+
While not required, it's also best practice to specify the image hash:
32+
33+
.. code-block:: yaml
34+
35+
payload:
36+
image: mozillareleases/taskgraph:decision-v7.3.0@sha256:f954e54d427d08b18954a4ff4541d43c76c476d0738f341e4fa82a959939d3fa
37+
38+
The hash can be found on the Docker Hub page for the specific tag you are
39+
pinning to.
40+
41+
.. _mozillareleases/taskgraph: https://hub.docker.com/r/mozillareleases/taskgraph/tags
42+
43+
44+
Using a Python Requirements File
45+
--------------------------------
46+
47+
Sometimes you might have more complex generation logic that requires other
48+
packages in addition to ``taskgraph``. In this case you'll want to use a
49+
`requirements file`_.
50+
51+
Like before, we'll use a pre-built Docker image provided by Taskgraph:
52+
53+
.. code-block:: yaml
54+
55+
payload:
56+
image: mozillareleases/taskgraph:run-task-v7.3.0
57+
58+
The only difference with this ``run-task`` image, is that it *only* contains
59+
the ``run-task`` script necessary to bootstrap the repository and not the full
60+
Taskgraph package. It leaves how to get Taskgraph bootstrapped into the task up
61+
to you.
62+
63+
This section outlines the recommended way to do that.
64+
65+
.. note::
66+
If you'd like to follow along, you can download the example
67+
:download:`.taskcluster.yml </tutorials/example-taskcluster.yml>` file.
68+
69+
.. _requirements file: https://pip.pypa.io/en/stable/reference/requirements-file-format/
970

1071
.. _define requirements:
1172

1273
Define Requirements
13-
-------------------
74+
~~~~~~~~~~~~~~~~~~~
1475

1576
We'll use a tool called `pip-compile`_ to help generate the
1677
``requirements.txt`` that will contain our Decision task dependencies,
@@ -27,35 +88,41 @@ First make sure you have ``pip-compile`` installed:
2788
2889
pip install pip-tools
2990
30-
Next, create the ``requirements.in`` file:
91+
Next, create the ``requirements.in`` file. For this example, let's pretend that
92+
in addition to ``taskcluster-taskgraph`` we also want to depend on
93+
``requests``:
3194

3295
.. code-block:: bash
3396
3497
cd taskcluster
35-
echo "taskcluster-taskgraph" > requirements.in
98+
cat << EOF > requirements.in
99+
taskcluster-taskgraph
100+
requests
101+
EOF
102+
36103
# This works best if you use the same Python as the one used in the Decision
37-
# image (currently 3.8).
104+
# image (currently 3.11).
38105
pip-compile --generate-hashes --output-file requirements.txt requirements.in
39106
40107
.. note::
41108
42109
You may add `version specifiers`_ to packages (e.g,
43-
``taskcluster-taskgraph==1.1.4``), but either way the actual version that
110+
``taskcluster-taskgraph==7.3.0``), but either way the actual version that
44111
gets used will be pinned once we generate the ``requirements.txt``.
45112
46-
If you intend to create transforms that require additional packages, add them to
113+
If you end up creating transforms that require additional packages, add them to
47114
``requirements.in`` and re-generate the lock file.
48115
49116
.. _pip-compile: https://github.com/jazzband/pip-tools
50117
.. _hashin: https://github.com/peterbe/hashin
51118
.. _version specifiers: https://pip.pypa.io/en/stable/cli/pip_install/#requirement-specifiers
52119
53120
Instruct ``run-task`` to Install Requirements
54-
---------------------------------------------
121+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55122
56-
The `decision docker images`_ provided by Taskgraph contain a script called
57-
`run-task`_. This script acts as a wrapper around the command you'd like to run
58-
and handles some initial setup such as cloning repositories needed by the task.
123+
The `docker images`_ provided by Taskgraph contain a script called `run-task`_.
124+
This script acts as a wrapper around the command you'd like to run and handles
125+
some initial setup such as cloning repositories needed by the task.
59126
60127
When ``run-task`` clones a repository, it can optionally install Python
61128
dependencies that are defined within it. We accomplish this with a set of
@@ -107,11 +174,11 @@ Now ``run-task`` will both clone your repo, as well as install any packages
107174
defined in ``taskcluster/requirements.txt``, ensuring Taskgraph is bootstrapped
108175
and ready to go.
109176
110-
.. _decision docker images: https://hub.docker.com/repository/docker/mozillareleases/taskgraph
177+
.. _docker images: https://hub.docker.com/repository/docker/mozillareleases/taskgraph
111178
.. _run-task: https://github.com/taskcluster/taskgraph/blob/main/src/taskgraph/run-task/run-task
112179
113180
Upgrading Taskgraph
114-
-------------------
181+
~~~~~~~~~~~~~~~~~~~
115182
116183
To upgrade Taskgraph to a newer version, re-generate the ``requirements.txt``
117184
file:
@@ -132,7 +199,7 @@ If you pinned the package to a specific version don't forget to update
132199
.. _semantic versioning: https://semver.org
133200
134201
Testing Pre-Release Versions of Taskgraph
135-
-----------------------------------------
202+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136203
137204
Sometimes you may wish to test against pre-release revisions of Taskgraph,
138205
especially if you are working on changes to Taskgraph itself. This can be
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
FROM debian:12-slim
1+
FROM $DOCKER_IMAGE_PARENT
22
LABEL maintainer="Release Engineering <[email protected]>"
33

4-
# Add worker user
5-
RUN mkdir /builds && \
6-
useradd -d /builds/worker -s /bin/bash -m worker && \
7-
mkdir /builds/worker/artifacts && \
8-
chown worker:worker /builds/worker/artifacts
9-
104
# %include src/taskgraph
115
ADD topsrcdir/src/taskgraph /setup/taskgraph/src/taskgraph
126
# %include setup.py
@@ -21,9 +15,5 @@ ADD topsrcdir/requirements/base.txt /setup/requirements.txt
2115
ADD system-setup.sh /setup/system-setup.sh
2216
RUN bash /setup/system-setup.sh
2317

24-
ENV PATH=/builds/worker/bin:$PATH \
25-
SHELL=/bin/bash \
26-
HOME=/builds/worker
27-
2818
# Set a default command useful for debugging
2919
CMD ["/bin/bash", "--login"]

taskcluster/docker/decision/system-setup.sh

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,13 @@ test "$(whoami)" == 'root'
66

77
apt-get update
88
apt-get install -y --force-yes --no-install-recommends \
9-
ca-certificates \
10-
python3 \
119
python3-pip \
1210
python3-setuptools \
1311
python3-wheel \
14-
sudo \
15-
unzip \
16-
curl \
17-
ucf \
18-
mercurial \
19-
git
2012

21-
# mercurial setup
22-
CERT_PATH=/etc/ssl/certs/ca-certificates.crt
23-
cat >/etc/mercurial/hgrc.d/cacerts.rc <<EOF
24-
[web]
25-
cacerts = ${CERT_PATH}
26-
EOF
27-
chmod 644 /etc/mercurial/hgrc.d/cacerts.rc
28-
29-
# Clone the repo in the decision image
3013
python3 -mpip install --break-system-packages -r /setup/requirements.txt
3114
python3 -mpip install --break-system-packages --no-deps /setup/taskgraph
3215

33-
# Same files as include-run-task
34-
cp /setup/taskgraph/src/taskgraph/run-task/run-task /usr/local/bin/run-task
35-
chmod 744 /usr/local/bin/run-task
36-
cp /setup/taskgraph/src/taskgraph/run-task/fetch-content /usr/local/bin/fetch-content
37-
chmod 744 /usr/local/bin/fetch-content
38-
cp /setup/taskgraph/src/taskgraph/run-task/hgrc /etc/mercurial/hgrc.d/mozilla.rc
39-
chmod 644 /etc/mercurial/hgrc.d/mozilla.rc
40-
cp /setup/taskgraph/src/taskgraph/run-task/robustcheckout.py /opt/robustcheckout.py
41-
chmod 644 /opt/robustcheckout.py
42-
4316
apt-get clean
4417
apt-get autoclean
4518
rm -rf /var/lib/apt/lists/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM debian:12-slim
2+
LABEL maintainer="Release Engineering <[email protected]>"
3+
4+
# Add worker user
5+
RUN mkdir /builds && \
6+
useradd -d /builds/worker -s /bin/bash -m worker && \
7+
mkdir /builds/worker/artifacts && \
8+
chown worker:worker /builds/worker/artifacts
9+
10+
# %include-run-task
11+
12+
ADD system-setup.sh /setup/system-setup.sh
13+
RUN bash /setup/system-setup.sh
14+
15+
ENV PATH=/builds/worker/bin:$PATH \
16+
SHELL=/bin/bash \
17+
HOME=/builds/worker
18+
19+
# Set a default command useful for debugging
20+
CMD ["/bin/bash", "--login"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -v -e
4+
5+
test "$(whoami)" == 'root'
6+
7+
apt-get update
8+
apt-get install -y --force-yes --no-install-recommends \
9+
ca-certificates \
10+
python3 \
11+
python3-pip \
12+
python3-setuptools \
13+
python3-wheel \
14+
sudo \
15+
unzip \
16+
curl \
17+
ucf \
18+
mercurial \
19+
git
20+
21+
# mercurial setup
22+
CERT_PATH=/etc/ssl/certs/ca-certificates.crt
23+
cat >/etc/mercurial/hgrc.d/cacerts.rc <<EOF
24+
[web]
25+
cacerts = ${CERT_PATH}
26+
EOF
27+
chmod 644 /etc/mercurial/hgrc.d/cacerts.rc
28+
29+
apt-get clean
30+
apt-get autoclean
31+
rm -rf /var/lib/apt/lists/
32+
rm -rf /setup

taskcluster/kinds/docker-image/kind.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ transforms:
1818
tasks:
1919
decision:
2020
symbol: I(d)
21+
parent: run-task
2122
fetch:
2223
symbol: I(fetch)
2324
index-task:
@@ -26,5 +27,7 @@ tasks:
2627
symbol: I(py)
2728
args:
2829
PYENV_VERSIONS: "3.12, 3.11, 3.10, 3.9, 3.8"
30+
run-task:
31+
symbol: I(rt)
2932
skopeo:
3033
symbol: I(skopeo)

taskcluster/kinds/push-image/kind.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ tasks:
4343
decision:
4444
dependencies:
4545
image: build-docker-image-decision
46+
run-task:
47+
dependencies:
48+
image: build-docker-image-run-task

0 commit comments

Comments
 (0)