Skip to content

Commit 7d6423c

Browse files
authored
refactor: remove rules_docker dependency (#512)
1 parent 3c0f9f9 commit 7d6423c

File tree

16 files changed

+146
-119
lines changed

16 files changed

+146
-119
lines changed

BUILD.bazel

Lines changed: 0 additions & 22 deletions
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

Lines changed: 17 additions & 0 deletions
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

Lines changed: 26 additions & 19 deletions
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

Lines changed: 14 additions & 7 deletions
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

Lines changed: 0 additions & 38 deletions
This file was deleted.

py/tests/containers/branding/BUILD.bazel

Lines changed: 0 additions & 8 deletions
This file was deleted.

py/tests/containers/py_image_test.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 32 additions & 2 deletions
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.

0 commit comments

Comments
 (0)