Skip to content

Commit 7d6423c

Browse files
authoredJan 27, 2025··
refactor: remove rules_docker dependency (#512)
1 parent 3c0f9f9 commit 7d6423c

16 files changed

+146
-119
lines changed
 

‎BUILD.bazel

-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
22
load("@pypi//:requirements.bzl", "all_whl_requirements")
3-
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
43
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")
54
load("@rules_python_gazelle_plugin//:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS")
65
load("@rules_python_gazelle_plugin//manifest:defs.bzl", "gazelle_python_manifest")
@@ -43,24 +42,3 @@ modules_mapping(
4342
name = "modules_map",
4443
wheels = all_whl_requirements,
4544
)
46-
47-
py_runtime(
48-
name = "container_py3_runtime",
49-
interpreter_path = "/usr/bin/python",
50-
python_version = "PY3",
51-
)
52-
53-
py_runtime_pair(
54-
name = "container_py_runtime_pair",
55-
py2_runtime = None,
56-
py3_runtime = ":container_py3_runtime",
57-
)
58-
59-
toolchain(
60-
name = "container_py_toolchain",
61-
exec_compatible_with = [
62-
"@io_bazel_rules_docker//platforms:run_in_container",
63-
],
64-
toolchain = ":container_py_runtime_pair",
65-
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
66-
)

‎MODULE.bazel

+17
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ crate.from_cargo(
8282
],
8383
)
8484
use_repo(crate, "crate_index")
85+
86+
# For building test images with py_image_layer
87+
bazel_dep(name = "container_structure_test", version = "1.19.1", dev_dependency = True)
88+
bazel_dep(name = "rules_oci", version = "2.0.1", dev_dependency = True)
89+
90+
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci", dev_dependency = True)
91+
oci.pull(
92+
name = "ubuntu",
93+
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
94+
image = "ubuntu",
95+
platforms = [
96+
"linux/arm64/v8",
97+
"linux/amd64",
98+
],
99+
tag = "latest",
100+
)
101+
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

‎WORKSPACE

+26-19
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ load("//py:toolchains.bzl", "rules_py_toolchains")
1919

2020
rules_py_toolchains()
2121

22-
# Load the Python toolchain for rules_docker
23-
register_toolchains("//:container_py_toolchain")
24-
2522
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
2623

2724
python_register_toolchains(
@@ -139,22 +136,6 @@ load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_se
139136

140137
bazel_skylib_gazelle_plugin_setup(register_go_toolchains = False)
141138

142-
############################################
143-
# rules_docker dependencies for containers
144-
load(
145-
"@io_bazel_rules_docker//repositories:repositories.bzl",
146-
container_repositories = "repositories",
147-
)
148-
149-
container_repositories()
150-
151-
load(
152-
"@io_bazel_rules_docker//python3:image.bzl",
153-
_py_image_repos = "repositories",
154-
)
155-
156-
_py_image_repos()
157-
158139
############################################
159140
# rules_rust dependencies for building tools
160141
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set")
@@ -306,3 +287,29 @@ crates_repository(
306287
load("@crate_index//:defs.bzl", "crate_repositories")
307288

308289
crate_repositories()
290+
291+
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
292+
293+
rules_oci_dependencies()
294+
295+
load("@rules_oci//oci:repositories.bzl", "oci_register_toolchains")
296+
297+
oci_register_toolchains(name = "oci")
298+
299+
# You can pull your base images using oci_pull like this:
300+
load("@rules_oci//oci:pull.bzl", "oci_pull")
301+
302+
oci_pull(
303+
name = "ubuntu",
304+
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
305+
image = "ubuntu",
306+
platforms = [
307+
"linux/arm64/v8",
308+
"linux/amd64",
309+
],
310+
tag = "latest",
311+
)
312+
313+
load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain")
314+
315+
container_structure_test_register_toolchain(name = "cst")

‎internal_deps.bzl

+14-7
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,27 @@ def rules_py_internal_deps():
7878
],
7979
)
8080

81-
http_archive(
82-
name = "io_bazel_rules_docker",
83-
sha256 = "9d41cbe09688d4de137b19091f162de05be9a629a4355bfc1a993f378231730a",
84-
strip_prefix = "rules_docker-3040e1fd74659a52d1cdaff81359f57ee0e2bb41",
85-
urls = ["https://github.com/bazelbuild/rules_docker/archive/3040e1fd74659a52d1cdaff81359f57ee0e2bb41.zip"],
86-
)
87-
8881
http_archive(
8982
name = "rules_python_gazelle_plugin",
9083
sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311",
9184
strip_prefix = "rules_python-0.31.0/gazelle",
9285
url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz",
9386
)
9487

88+
http_archive(
89+
name = "rules_oci",
90+
sha256 = "1bd16e455278d523f01326e0c3964cd64d7840a7e99cdd6e2617e59f698f3504",
91+
strip_prefix = "rules_oci-2.2.0",
92+
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v2.2.0/rules_oci-v2.2.0.tar.gz",
93+
)
94+
95+
http_archive(
96+
name = "container_structure_test",
97+
integrity = "sha256-TLs4LT1+3JcSn3n4MZbJXmAG2QY9ntuzOiMRupNyrTk=",
98+
strip_prefix = "container-structure-test-1.19.3",
99+
url = "https://github.com/GoogleContainerTools/container-structure-test/archive/refs/tags/v1.19.3.zip",
100+
)
101+
95102
http_archive(
96103
name = "rules_rust",
97104
integrity = "sha256-heIBNyerJvsiq9/+SyrAwnotW2KWFnumPY9uExQPUfk=",

‎py/tests/containers/BUILD.bazel

-38
This file was deleted.

‎py/tests/containers/branding/BUILD.bazel

-8
This file was deleted.

‎py/tests/containers/py_image_test.yaml

-14
This file was deleted.

‎py/tests/internal-deps/adder/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ py_library(
1010
# This library contributes to the container test, testing we can pull in and use a library from another
1111
# package in the repo.
1212
visibility = [
13-
"//py/tests/containers:__pkg__",
1413
"//py/tests/internal-deps:__pkg__",
14+
"//py/tests/py_image_layer:__pkg__",
1515
],
1616
)

‎py/tests/py_image_layer/BUILD.bazel

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@container_structure_test//:defs.bzl", "container_structure_test")
2+
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
13
load("//py:defs.bzl", "py_binary", "py_image_layer")
24
load("asserts.bzl", "assert_tar_listing")
35

@@ -9,10 +11,15 @@ platform(
911
],
1012
)
1113

12-
# Case 1: Basic usage
1314
py_binary(
1415
name = "my_app_bin",
15-
srcs = ["main.py"],
16+
srcs = ["__main__.py"],
17+
tags = ["manual"],
18+
deps = [
19+
"//py/tests/internal-deps/adder",
20+
"//py/tests/py_image_layer/branding",
21+
"@pypi_colorama//:pkg",
22+
],
1623
)
1724

1825
py_image_layer(
@@ -26,3 +33,26 @@ assert_tar_listing(
2633
actual = [":my_app_layers"],
2734
expected = ":my_app_layers.listing",
2835
)
36+
37+
oci_image(
38+
name = "image",
39+
# This is defined by an oci.pull() call in /MODULE.bazel
40+
base = "@ubuntu",
41+
entrypoint = ["/{}/my_app_bin".format(package_name())],
42+
tars = [":my_app_layers"],
43+
)
44+
45+
# To build the image and load it into it into a local runtime:
46+
# $ bazel run //py/tests/py_image_layer:image_load
47+
# $ docker run --rm gcr.io/oci_python_hello_world:latest
48+
oci_load(
49+
name = "image_load",
50+
image = ":image",
51+
repo_tags = ["gcr.io/oci_python_hello_world:latest"],
52+
)
53+
54+
container_structure_test(
55+
name = "py_image_test",
56+
configs = ["py_image_test.yaml"],
57+
image = ":image",
58+
)
File renamed without changes.

‎py/tests/py_image_layer/asserts.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ def assert_tar_listing(name, actual, expected):
1919
in_file = actual_listing,
2020
out_file = expected,
2121
testonly = True,
22-
tags = ["skip-on-bazel6"],
2322
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@aspect_rules_py//py:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "branding",
5+
srcs = ["__init__.py"],
6+
imports = [".."],
7+
visibility = ["//py/tests/py_image_layer:__pkg__"],
8+
)

‎py/tests/py_image_layer/main.py

-1
This file was deleted.

‎py/tests/py_image_layer/my_app_layers.listing

+36-6
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,29 @@ drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app
828828
-rwxr-xr-x 0 0 0 3697 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/warnings.py
829829
-rwxr-xr-x 0 0 0 8628 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/wheel.py
830830
-rwxr-xr-x 0 0 0 719 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/lib/python3.9/site-packages/setuptools/windows_support.py
831+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/
832+
-rwxr-xr-x 0 0 0 149 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/__init__.py
833+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/
834+
-rwxr-xr-x 0 0 0 266 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/__init__.py
835+
-rwxr-xr-x 0 0 0 2522 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/ansi.py
836+
-rwxr-xr-x 0 0 0 11128 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/ansitowin32.py
837+
-rwxr-xr-x 0 0 0 3325 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/initialise.py
838+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/
839+
-rwxr-xr-x 0 0 0 75 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/__init__.py
840+
-rwxr-xr-x 0 0 0 2839 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/ansi_test.py
841+
-rwxr-xr-x 0 0 0 10678 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/ansitowin32_test.py
842+
-rwxr-xr-x 0 0 0 6741 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/initialise_test.py
843+
-rwxr-xr-x 0 0 0 1866 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/isatty_test.py
844+
-rwxr-xr-x 0 0 0 1079 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/utils.py
845+
-rwxr-xr-x 0 0 0 3709 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/tests/winterm_test.py
846+
-rwxr-xr-x 0 0 0 6181 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/win32.py
847+
-rwxr-xr-x 0 0 0 7134 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/winterm.py
848+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/
849+
-rwxr-xr-x 0 0 0 42 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/INSTALLER
850+
-rwxr-xr-x 0 0 0 17158 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/METADATA
851+
-rwxr-xr-x 0 0 0 105 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/WHEEL
852+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/licenses/
853+
-rwxr-xr-x 0 0 0 1491 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama-0.4.6.dist-info/licenses/LICENSE.txt
831854
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/
832855
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/bin/
833856
-rwxr-xr-x 0 0 0 20960 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/python_toolchain_x86_64-unknown-linux-gnu/bin/python3
@@ -2438,20 +2461,27 @@ drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app
24382461
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/
24392462
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/
24402463
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/
2441-
-rwxr-xr-x 0 0 0 2887 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin
2442-
-rwxr-xr-x 0 0 0 16 Jan 1 2023 ./py/tests/py_image_layer/main.py
2443-
-rwxr-xr-x 0 0 0 40 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.venv.pth
2464+
-rwxr-xr-x 0 0 0 2895 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin
2465+
-rwxr-xr-x 0 0 0 204 Jan 1 2023 ./py/tests/py_image_layer/__main__.py
2466+
-rwxr-xr-x 0 0 0 183 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.venv.pth
24442467
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/
24452468
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/
24462469
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/
24472470
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/
2471+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/
2472+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/
2473+
-rwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/__init__.py
2474+
-rwxr-xr-x 0 0 0 32 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/internal-deps/adder/add.py
24482475
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/
2449-
-rwxr-xr-x 0 0 0 16 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/main.py
2450-
-rwxr-xr-x 0 0 0 40 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin.venv.pth
2476+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/branding/
2477+
-rwxr-xr-x 0 0 0 42 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/branding/__init__.py
2478+
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/
2479+
-rwxr-xr-x 0 0 0 204 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/__main__.py
2480+
-rwxr-xr-x 0 0 0 183 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin.venv.pth
24512481
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/
24522482
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/
24532483
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/
24542484
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/runfiles/
24552485
-rwxr-xr-x 0 0 0 21622 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash
24562486
drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tools/
2457-
-rwxr-xr-x 0 0 0 2887 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin
2487+
-rwxr-xr-x 0 0 0 2895 Jan 1 2023 ./py/tests/py_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_image_layer/my_app_bin
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schemaVersion: 2.0.0
2+
3+
fileExistenceTests:
4+
- name: __main__ is present
5+
path: /py/tests/py_image_layer/__main__.py
6+
- name: runfiles dependencies are present
7+
path: /py/tests/py_image_layer/my_app_bin.runfiles/pypi_colorama/site-packages/colorama/__init__.py
8+
commandTests:
9+
- name: can run binary
10+
exitCode: 0
11+
command: /py/tests/py_image_layer/my_app_bin
12+
expectedOutput: ["Hello rules_py - 3.14"]

0 commit comments

Comments
 (0)
Please sign in to comment.