Skip to content

Commit 53e3c20

Browse files
fix: updated docker tests
1 parent bf7f670 commit 53e3c20

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

src/taskgraph/docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def load_image_by_task_id(task_id, tag=None):
9797
return tag
9898

9999

100-
def build_context(name, outputFile, args=None, graph_config=None):
100+
def build_context(name, outputFile, graph_config, args=None):
101101
"""Build a context.tar for image with specified name."""
102102
if not name:
103103
raise ValueError("must provide a Docker image name")
@@ -111,7 +111,7 @@ def build_context(name, outputFile, args=None, graph_config=None):
111111
docker.create_context_tar(".", image_dir, outputFile, args)
112112

113113

114-
def build_image(name, tag, args=None, graph_config=None):
114+
def build_image(name, tag, graph_config, args=None):
115115
"""Build a Docker image of specified name.
116116
117117
Output from image building process will be printed to stdout.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
---
5+
meta:
6+
- &uv_version 0.6.1
7+
8+
loader: taskgraph.loader.transform:loader
9+
10+
transforms:
11+
- taskgraph.transforms.docker_image:transforms
12+
- taskgraph.transforms.cached_tasks:transforms
13+
- taskgraph.transforms.task:transforms
14+
15+
# make a task for each docker-image we might want. For the moment, since we
16+
# write artifacts for each, these are whitelisted, but ideally that will change
17+
# (to use subdirectory clones of the proper directory), at which point we can
18+
# generate tasks for every docker image in the directory, secure in the
19+
# knowledge that unnecessary images will be omitted from the target task graph
20+
tasks:
21+
decision:
22+
symbol: I(d)
23+
parent: run-task
24+
fetch:
25+
symbol: I(fetch)
26+
index-task:
27+
symbol: I(idx)
28+
python:
29+
symbol: I(py)
30+
args:
31+
PYTHON_VERSIONS: "3.13 3.12 3.11 3.10 3.9 3.8"
32+
UV_VERSION: *uv_version
33+
run-task:
34+
symbol: I(rt)
35+
args:
36+
UV_VERSION: *uv_version
37+
skopeo:
38+
symbol: I(skopeo)

test/test_docker.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from taskgraph import docker
7+
from taskgraph.config import GraphConfig
78

89

910
@pytest.fixture(autouse=True, scope="module")
@@ -30,7 +31,15 @@ def test_build_image(capsys, mock_docker_build):
3031
image = "hello-world-tag"
3132
tag = f"test/{image}:1.0"
3233

33-
assert docker.build_image(image, None) is None
34+
graph_config = GraphConfig(
35+
{
36+
"trust-domain": "test-domain",
37+
"docker-image-kind": "docker-image",
38+
},
39+
"test/data/taskcluster",
40+
)
41+
42+
assert docker.build_image(image, None, graph_config=graph_config) is None
3443
m_stream.assert_called_once()
3544
m_run.assert_called_once_with(
3645
["docker", "image", "build", "--no-cache", f"-t={tag}", "-"],
@@ -47,7 +56,15 @@ def test_build_image_no_tag(capsys, mock_docker_build):
4756
m_stream, m_run = mock_docker_build
4857
image = "hello-world"
4958

50-
assert docker.build_image(image, None) is None
59+
graph_config = GraphConfig(
60+
{
61+
"trust-domain": "test-domain",
62+
"docker-image-kind": "docker-image",
63+
},
64+
"test/data/taskcluster",
65+
)
66+
67+
assert docker.build_image(image, None, graph_config=graph_config) is None
5168
m_stream.assert_called_once()
5269
m_run.assert_called_once_with(
5370
["docker", "image", "build", "--no-cache", "-"],
@@ -71,8 +88,16 @@ def mock_run(*popenargs, check=False, **kwargs):
7188
m_run.side_effect = mock_run
7289
image = "hello-world"
7390

91+
graph_config = GraphConfig(
92+
{
93+
"trust-domain": "test-domain",
94+
"docker-image-kind": "docker-image",
95+
},
96+
"test/data/taskcluster",
97+
)
98+
7499
with pytest.raises(Exception):
75-
docker.build_image(image, None)
100+
docker.build_image(image, None, graph_config=graph_config)
76101
m_stream.assert_called_once()
77102
m_run.assert_called_once_with(
78103
["docker", "image", "build", "--no-cache", "-"],

0 commit comments

Comments
 (0)