Skip to content

Commit

Permalink
refactor: use rules_py instead (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Sep 27, 2023
1 parent 474217a commit bedd87b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
22 changes: 14 additions & 8 deletions oci_python_image/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
bazel_dep(name = "aspect_bazel_lib", version = "1.31.2")
bazel_dep(name = "container_structure_test", version = "1.15.0")
bazel_dep(name = "rules_pkg", version = "0.9.1")
bazel_dep(name = "aspect_rules_py", version = "0.3.0")
bazel_dep(name = "rules_python", version = "0.21.0")
bazel_dep(name = "rules_oci", version = "1.3.1")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "platforms", version = "0.0.7")

python = use_extension("@rules_python//python:extensions.bzl", "python")
python.toolchain(
Expand All @@ -14,6 +15,7 @@ python.toolchain(
)
use_repo(python, "python3_9")
use_repo(python, "python3_9_toolchains")

register_toolchains("@python3_9_toolchains//:all")

pip = use_extension("@rules_python//python:extensions.bzl", "pip")
Expand All @@ -25,13 +27,17 @@ use_repo(pip, "pip")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "distroless_python",
# tag = "latest", # as of 30 August 2023
digest = "sha256:5148968d8ae02a0f6d12efaca7a16e711ab43a4695a285e22dbbae70d6048937",
name = "python_base",
digest = "sha256:844b3044eef9d990d3c640e046241ac3963cf6bf4a4cd6b831bf3e1752687698",
image = "index.docker.io/library/python",
platforms = [
"linux/amd64",
"linux/arm64/v8"
"linux/386",
"linux/amd64",
"linux/arm/v5",
"linux/arm/v7",
"linux/arm64/v8",
"linux/ppc64le",
"linux/s390x",
],
image = "gcr.io/distroless/python3",
)
use_repo(oci, "distroless_python")
use_repo(oci, "python_base")
6 changes: 3 additions & 3 deletions oci_python_image/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_library")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@container_structure_test//:defs.bzl", "container_structure_test")
Expand Down Expand Up @@ -35,8 +35,8 @@ py_image_layer(

oci_image(
name = "image",
base = "@distroless_python",
cmd = ["/opt/hello_world/hello_world"],
base = "@python_base",
entrypoint = ["/opt/hello_world/hello_world"],
tars = [":hello_world_layer"],
)

Expand Down
4 changes: 2 additions & 2 deletions oci_python_image/hello_world/test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# See https://github.com/GoogleContainerTools/container-structure-test#command-tests
schemaVersion: 2.0.0
metadataTest:
cmd: ['/opt/hello_world/hello_world']
entrypoint: ['/opt/hello_world/hello_world']
commandTests:
- name: run
command: python3
command: bash
args: [/opt/hello_world/hello_world]
expectedOutput: ['| hello py_image_layer! |']

0 comments on commit bedd87b

Please sign in to comment.