-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathBUILD.bazel
77 lines (68 loc) · 1.8 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
load("@rules_python//python: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("//:py_image_layer.bzl", "py_image_layer")
load("@container_structure_test//:defs.bzl", "container_structure_test")
py_library(
name = "hello_world",
srcs = [
"__init__.py",
"app.py",
],
imports = [".."],
visibility = ["//:__subpackages__"],
)
py_binary(
name = "hello_world_bin",
srcs = ["__main__.py"],
imports = [".."],
main = "__main__.py",
visibility = ["//:__subpackages__"],
deps = [":hello_world"],
)
py_image_layer(
name = "hello_world_layer",
binary = ":hello_world_bin",
root = "/opt",
)
oci_image(
name = "image",
base = "@docker_python",
entrypoint = ["/opt/hello_world/hello_world_bin"],
tars = [":hello_world_layer"],
)
platform(
name = "aarch64_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
)
platform(
name = "x86_64_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)
platform_transition_filegroup(
name = "transitioned_image",
srcs = [":image"],
target_platform = select({
"@platforms//cpu:arm64": ":aarch64_linux",
"@platforms//cpu:x86_64": ":x86_64_linux",
}),
)
# $ bazel build //hello_world:tarball
# $ docker load --input $(bazel cquery --output=files //hello_world:tarball)
# $ docker run --rm gcr.io/oci_python_hello_world:latest
oci_tarball(
name = "tarball",
image = ":image",
repo_tags = ["gcr.io/oci_python_hello_world:latest"],
)
container_structure_test(
name = "test",
configs = ["test.yaml"],
image = ":image",
)