Skip to content

Commit

Permalink
feat(ci): Use taskgraph for generating CI tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
hneiva committed Jun 20, 2024
1 parent 6fbbb10 commit fdc24ae
Show file tree
Hide file tree
Showing 8 changed files with 830 additions and 48 deletions.
340 changes: 292 additions & 48 deletions .taskcluster.yml

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions taskcluster/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
trust-domain: "mozilla"
task-priority: low

taskgraph:
cached-task-prefix: "mozilla.v2.redo"
repositories:
redo:
name: "redo"

workers:
aliases:
b-linux:
provisioner: '{trust-domain}-{level}'
implementation: docker-worker
os: linux
worker-type: '{alias}-gcp'
images:
provisioner: '{trust-domain}-{level}'
implementation: docker-worker
os: linux
worker-type: '{alias}-gcp'
t-linux-large:
provisioner: '{trust-domain}-t'
implementation: docker-worker
os: linux
worker-type: '{alias}-gcp'
34 changes: 34 additions & 0 deletions taskcluster/docker/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

#%ARG PYTHON_VERSION
FROM python:$PYTHON_VERSION-slim
LABEL maintainer="Release Engineering <release@mozilla.com>"

# Add worker user
RUN mkdir /builds && \
useradd -d /builds/worker -s /bin/bash -m worker && \
mkdir /builds/worker/artifacts && \
chown worker:worker /builds/worker/artifacts

# %include-run-task

RUN apt-get update \
&& apt-get install -y --reinstall ca-certificates \
&& apt-get install -y --force-yes --no-install-recommends \
build-essential \
mercurial \
git

RUN pip install tox

ENV SHELL=/bin/bash \
HOME=/builds/worker \
PATH=/builds/worker/.local/bin:$PATH

VOLUME /builds/worker/checkouts
VOLUME /builds/worker/.cache

# Set a default command useful for debugging
CMD ["/bin/bash", "--login"]
29 changes: 29 additions & 0 deletions taskcluster/kinds/docker-image/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
loader: taskgraph.loader.transform:loader

transforms:
- taskgraph.transforms.docker_image:transforms
- taskgraph.transforms.cached_tasks:transforms
- taskgraph.transforms.task:transforms

tasks:
py38:
definition: python
args:
PYTHON_VERSION: "3.8"
py39:
definition: python
args:
PYTHON_VERSION: "3.9"
py310:
definition: python
args:
PYTHON_VERSION: "3.10"
py311:
definition: python
args:
PYTHON_VERSION: "3.11"
py312:
definition: python
args:
PYTHON_VERSION: "3.12"
39 changes: 39 additions & 0 deletions taskcluster/kinds/tox/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---
loader: taskgraph.loader.transform:loader

kind-dependencies:
- docker-image

transforms:
- redo_taskgraph.transforms.python_version:transforms
- taskgraph.transforms.run:transforms
- taskgraph.transforms.task:transforms

task-defaults:
description: "{name} py{python_version}"
run-on-tasks-for:
- "github-pull-request"
- "github-push"
attributes:
code-review: true
worker-type: b-linux
worker:

docker-image: {in-tree: 'py{python_version}'}
max-run-time: 1800
run:
using: run-task
cache-dotcache: false
cwd: '{checkout}'
command:
- sh
- -lxce
- >-
tox -e py{python_version}
tasks:
tox:
python-versions: [38, 39, 310, 311, 312]
78 changes: 78 additions & 0 deletions taskcluster/redo_taskgraph/transforms/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Create a task per python-version
"""

from copy import deepcopy

from taskgraph.transforms.base import TransformSequence

transforms = TransformSequence()


def _replace_string(obj, subs):
if isinstance(obj, dict):
return {k: v.format(**subs) for k, v in obj.items()}
elif isinstance(obj, list):
for c in range(0, len(obj)):
obj[c] = obj[c].format(**subs)
else:
obj = obj.format(**subs)
return obj


def _resolve_replace_string(item, field, subs):
# largely from resolve_keyed_by
container, subfield = item, field
while "." in subfield:
f, subfield = subfield.split(".", 1)
if f not in container:
return item
container = container[f]
if not isinstance(container, dict):
return item

if subfield not in container:
return item

container[subfield] = _replace_string(container[subfield], subs)
return item


@transforms.add
def set_script_name(config, tasks):
for task in tasks:
task.setdefault("attributes", {}).update(
{
"script-name": task["name"],
}
)
yield task


@transforms.add
def tasks_per_python_version(config, tasks):
fields = [
"description",
"docker-repo",
"run.command",
"worker.command",
"worker.docker-image",
]
for task_raw in tasks:
for python_version in task_raw.pop("python-versions"):
task = deepcopy(task_raw)
subs = {"name": task["name"], "python_version": python_version}
for field in fields:
_resolve_replace_string(task, field, subs)
task["attributes"]["python-version"] = python_version
yield task


@transforms.add
def update_name_with_python_version(config, tasks):
for task in tasks:
task["name"] = "{}-python{}".format(task["name"], task["attributes"]["python-version"])
yield task
1 change: 1 addition & 0 deletions taskcluster/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
taskcluster-taskgraph>=7.0.0
Loading

1 comment on commit fdc24ae

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

["assume:repo:github.com/mozilla-releng/redo:pull-request","queue:route:checks","queue:scheduler-id:taskcluster-github"]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AllOf": [
    "queue:scheduler-id:mozilla-level-1",
    {
      "AnyOf": [
        "queue:create-task:highest:mozilla-1/decision-gcp",
        "queue:create-task:very-high:mozilla-1/decision-gcp",
        "queue:create-task:high:mozilla-1/decision-gcp",
        "queue:create-task:medium:mozilla-1/decision-gcp",
        "queue:create-task:low:mozilla-1/decision-gcp",
        "queue:create-task:very-low:mozilla-1/decision-gcp"
      ]
    }
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "queue:route:checks",
    "queue:create-task:project:none",
    "queue:scheduler-id:mozilla-level-1",
    {
      "AnyOf": [
        "queue:create-task:highest:mozilla-1/decision-gcp",
        "queue:create-task:very-high:mozilla-1/decision-gcp",
        "queue:create-task:high:mozilla-1/decision-gcp",
        "queue:create-task:medium:mozilla-1/decision-gcp",
        "queue:create-task:low:mozilla-1/decision-gcp",
        "queue:create-task:very-low:mozilla-1/decision-gcp"
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2024-06-20T05:08:50.979Z

Please sign in to comment.