|
| 1 | +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") |
| 2 | +load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_image_index") |
| 3 | +load("@aspect_rules_py//py:defs.bzl", "py_image_layer") |
| 4 | +load("@aspect_rules_py//py/unstable:defs.bzl", "py_venv_binary") |
| 5 | +load("@container_structure_test//:defs.bzl", "container_structure_test") |
| 6 | +load("@aspect_rules_py//py/tests/py_image_layer:asserts.bzl", "assert_tar_listing") |
| 7 | + |
| 8 | +platform( |
| 9 | + name = "arm64_linux", |
| 10 | + constraint_values = [ |
| 11 | + "@platforms//os:linux", |
| 12 | + "@platforms//cpu:aarch64", |
| 13 | + ], |
| 14 | + flags = [ |
| 15 | + "--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc", |
| 16 | + "--@aspect_rules_py//uv/private/constraints/platform:platform_version=2.39", |
| 17 | + "--@rules_rust//:extra_rustc_flag=-Cstrip=debuginfo", |
| 18 | + "--@rules_rust//rust/settings:lto=fat", |
| 19 | + "--stripopt=--strip-all", |
| 20 | + ], |
| 21 | +) |
| 22 | + |
| 23 | +platform( |
| 24 | + name = "amd64_linux", |
| 25 | + constraint_values = [ |
| 26 | + "@platforms//os:linux", |
| 27 | + "@platforms//cpu:x86_64", |
| 28 | + ], |
| 29 | + flags = [ |
| 30 | + "--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc", |
| 31 | + "--@aspect_rules_py//uv/private/constraints/platform:platform_version=2.39", |
| 32 | + "--@rules_rust//:extra_rustc_flag=-Cstrip=debuginfo", |
| 33 | + "--@rules_rust//rust/settings:lto=fat", |
| 34 | + "--stripopt=--strip-all", |
| 35 | + ], |
| 36 | +) |
| 37 | + |
| 38 | +py_venv_binary( |
| 39 | + name = "app_bin", |
| 40 | + srcs = ["__main__.py"], |
| 41 | + main = "__main__.py", |
| 42 | + deps = [ |
| 43 | + "@pypi//psycopg2_binary", |
| 44 | + ], |
| 45 | + python_version = "3.12", |
| 46 | + venv = "psql", |
| 47 | +) |
| 48 | + |
| 49 | +py_image_layer( |
| 50 | + name = "app_layers", |
| 51 | + binary = ":app_bin", |
| 52 | +) |
| 53 | + |
| 54 | +platform_transition_filegroup( |
| 55 | + name = "amd64_layers", |
| 56 | + srcs = [":app_layers"], |
| 57 | + target_platform = ":amd64_linux", |
| 58 | +) |
| 59 | + |
| 60 | +assert_tar_listing( |
| 61 | + name = "app_amd64_layers", |
| 62 | + actual = [":amd64_layers"], |
| 63 | + expected = ":app_amd64_layers_listing.yaml", |
| 64 | +) |
| 65 | + |
| 66 | +platform_transition_filegroup( |
| 67 | + name = "arm64_layers", |
| 68 | + srcs = [":app_layers"], |
| 69 | + target_platform = ":arm64_linux", |
| 70 | +) |
| 71 | + |
| 72 | +assert_tar_listing( |
| 73 | + name = "app_arm64_layers", |
| 74 | + actual = [":arm64_layers"], |
| 75 | + expected = ":app_arm64_layers_listing.yaml", |
| 76 | +) |
| 77 | + |
| 78 | +oci_image( |
| 79 | + name = "image", |
| 80 | + # This is defined by an oci.pull() call in /MODULE.bazel |
| 81 | + base = "@ubuntu", |
| 82 | + entrypoint = ["/{}/app_bin".format(package_name())], |
| 83 | + tars = [":app_layers"], |
| 84 | +) |
| 85 | + |
| 86 | +platform_transition_filegroup( |
| 87 | + name = "amd64_image", |
| 88 | + srcs = [":image"], |
| 89 | + target_platform = ":amd64_linux", |
| 90 | +) |
| 91 | + |
| 92 | +platform_transition_filegroup( |
| 93 | + name = "arm64_image", |
| 94 | + srcs = [":image"], |
| 95 | + target_platform = ":arm64_linux", |
| 96 | +) |
| 97 | + |
| 98 | +oci_image_index( |
| 99 | + name = "image_index", |
| 100 | + images = [ |
| 101 | + ":arm64_image", |
| 102 | + ":amd64_image", |
| 103 | + ], |
| 104 | +) |
0 commit comments