Skip to content

Commit

Permalink
checkpoint bazel test //example:docker PASS
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Feb 29, 2024
1 parent e91d018 commit 70885da
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 3,706 deletions.
1 change: 1 addition & 0 deletions .dockerconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 6 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
# ----------------------------------------------------
# gazelle:prefix github.com/stackb/pycross_image

load("//tools/example_test:defs.bzl", "example_test_filegroup")
load("//bazel/tools/example_test:defs.bzl", "example_test_filegroup")

example_test_filegroup(
name = "example_test_files",
srcs = [
".dockerconfig.json",
"BUILD.bazel",
"WORKSPACE",
"//bazel:example_test_files",
"//platform:example_test_files",
"//rules:example_test_files",
"//tools/example_test:example_test_files",
"//bazel/platforms:example_test_files",
"//bazel/rules:example_test_files",
"//bazel/tools/example_test:example_test_files",
"//bazel/workspace:example_test_files",
],
)
75 changes: 17 additions & 58 deletions bazel/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,74 +1,33 @@
load("//tools/example_test:defs.bzl", "example_test_filegroup")

_darwin_x86_64 = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
]

_darwin_arm64 = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
]

_linux_x86_64 = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
]
load("//bazel/tools/example_test:defs.bzl", "example_test_filegroup")

platform(
name = "darwin_x86_64",
constraint_values = _darwin_x86_64,
name = "linux_x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

platform(
name = "darwin_arm64",
constraint_values = _darwin_arm64,
name = "darwin_x86_64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

platform(
name = "linux_x86_64",
constraint_values = _linux_x86_64,
name = "darwin_arm64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
visibility = ["//visibility:public"],
)

# pycross_target_environment(
# name = "python_darwin_x86_64",
# abis = ["cp310"],
# platforms = ["macosx_12_0_x86_64"],
# python_compatible_with = _darwin_x86_64,
# version = "3.10.11",
# visibility = ["//visibility:public"],
# )

# pycross_target_environment(
# name = "python_darwin_arm64",
# abis = ["cp310"],
# platforms = ["macosx_12_0_arm64"],
# python_compatible_with = _darwin_arm64,
# version = "3.10.11",
# visibility = ["//visibility:public"],
# )

# pycross_target_environment(
# name = "python_linux_x86_64",
# abis = ["cp310"],
# platforms = [
# "linux_x86_64",
# "manylinux2014_x86_64",
# ] + [
# "manylinux_2_%s_x86_64" % str(i)
# for i in range(17, 25)
# ],
# python_compatible_with = _linux_x86_64,
# version = "3.10.11",
# visibility = ["//visibility:public"],
# )

example_test_filegroup(
name = "example_test_files",
srcs = [
"BUILD.bazel",
],
srcs = ["BUILD.bazel"],
)
2 changes: 1 addition & 1 deletion rules/BUILD.bazel → bazel/rules/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//tools/example_test:defs.bzl", "example_test_filegroup")
load("//bazel/tools/example_test:defs.bzl", "example_test_filegroup")

example_test_filegroup(
name = "example_test_files",
Expand Down
8 changes: 3 additions & 5 deletions rules/docker.bzl → bazel/rules/docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ def _make_entrypoint(toolchain_config_setting_label, workdir, cmd):
def py_image(
name,
binary,
base = "@distroless_python3_debian12",
tars = [],
base = "@distroless_python3_debian12_container//image",
config = "@python//:x86_64-unknown-linux-gnu",
target_platform = "@pycross_image//platform:linux_x86_64",
target_platform = "@pycross_image//bazel/platforms:linux_x86_64",
**kwargs):
"""
pycross_oci_image is a macro that instantiates an oci_image from a py_binary rule
Expand Down Expand Up @@ -87,7 +86,6 @@ def py_image(
entrypoint = _make_entrypoint(config, workdir, cmd)

layer_tars = py_layers(name, cross_binary)
layer_tars = []

platform_transition_binary(
name = cross_binary,
Expand All @@ -103,7 +101,7 @@ def py_image(

container_image(
name = name + "_container",
base = "@python3-debian12//image",
base = base,
layers = [tar + "_layer" for tar in layer_tars],
workdir = workdir,
entrypoint = [entrypoint],
Expand Down
6 changes: 2 additions & 4 deletions rules/oci.bzl → bazel/rules/oci.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load(":py_layers.bzl", "py_layers")

def _make_entrypoint(toolchain_config_setting_label, workdir, cmd):
print("workdir:", workdir)
label = Label(toolchain_config_setting_label)
return "{workdir}/{cmd}.runfiles/{python_toolchains_workspace_name}_{python_toolchains_config_setting}/bin/python3".format(
workdir = workdir,
Expand All @@ -21,10 +20,10 @@ def _make_entrypoint(toolchain_config_setting_label, workdir, cmd):
def py_image(
name,
binary,
base = "@distroless_python3_debian12",
base = "@distroless_python3_debian12_oci",
tars = [],
config = "@python//:x86_64-unknown-linux-gnu",
target_platform = "@pycross_image//platform:linux_x86_64",
target_platform = "@pycross_image//bazel/platforms:linux_x86_64",
**kwargs):
"""
pycross_oci_image is a macro that instantiates an oci_image from a py_binary rule
Expand Down Expand Up @@ -89,7 +88,6 @@ def py_image(
entrypoint = _make_entrypoint(config, workdir, cmd)

layer_tars = py_layers(name, cross_binary)
layer_tars = []

platform_transition_binary(
name = cross_binary,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bazel/tools/example_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//tools/example_test:defs.bzl", "example_test_filegroup")
load("//bazel/tools/example_test:defs.bzl", "example_test_filegroup")

example_test_filegroup(
name = "example_test_files",
Expand Down
2 changes: 1 addition & 1 deletion bazel/tools/example_test/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestBuild(t *testing.T) {
),
"_generator": attr.label(
doc = "The exampl generator tool",
default = "//tools/example_test/generator",
default = "//bazel/tools/example_test/generator",
allow_single_file = True,
executable = True,
cfg = "exec",
Expand Down
2 changes: 1 addition & 1 deletion bazel/tools/example_test/generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
"main.go",
"template.go",
],
importpath = "github.com/stackb/pycross_image/tools/example_test/generator",
importpath = "github.com/stackb/pycross_image/bazel/tools/example_test/generator",
visibility = ["//visibility:private"],
)

Expand Down
2 changes: 1 addition & 1 deletion bazel/tools/pdm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@//rules:oci.bzl", "py_image")
load("@//bazel/rules:oci.bzl", "py_image")

py_binary(
name = "pdm",
Expand Down
10 changes: 5 additions & 5 deletions bazel/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
load("//tools/example_test:defs.bzl", "example_test_filegroup")
load("//bazel/tools/example_test:defs.bzl", "example_test_filegroup")

example_test_filegroup(
name = "example_test_files",
srcs = [
"BUILD.bazel",
"repositories.bzl",
"workspace0.bzl",
"workspace1.bzl",
"workspace2.bzl",
"workspace3.bzl",
"step1.bzl",
"step2.bzl",
"step3.bzl",
"step4.bzl",
],
)
9 changes: 9 additions & 0 deletions bazel/workspace/step1.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ load(
"@hermetic_cc_toolchain//toolchain:defs.bzl",
zig_toolchains = "toolchains",
)
load(
"@io_bazel_rules_docker//toolchains/docker:toolchain.bzl",
docker_toolchain_configure = "toolchain_configure",
)
load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
Expand Down Expand Up @@ -66,6 +70,11 @@ def _setup_rules_go(go_version = "1.20.12"):
go_register_toolchains(go_version = go_version)

def _setup_rules_docker():
if False:
docker_toolchain_configure(
name = "docker_config",
client_config = "@pycross_image//:.dockerconfig.json",
)
container_repositories()
container_deps()

Expand Down
5 changes: 3 additions & 2 deletions bazel/workspace/step2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ def _setup_oci_containers():
)

oci_pull(
name = "distroless_python3_debian12",
name = "distroless_python3_debian12_oci",
digest = "sha256:0078c63ba4e9bb13eef1576a183fc0bc3fd04fd3d5a9bad5ede1069bddca0ebd",
image = "gcr.io/distroless/python3-debian12",
)

def _setup_docker_containers():
container_pull(
name = "python3-debian12",
name = "distroless_python3_debian12_container",
# from 'crane manifest gcr.io/distroless/python3-debian12:latest'
digest = "sha256:0078c63ba4e9bb13eef1576a183fc0bc3fd04fd3d5a9bad5ede1069bddca0ebd",
registry = "gcr.io",
repository = "distroless/python3-debian12",
# docker_client_config = "@pycross_image//:.dockerconfig.json",
)

step2 = struct(
Expand Down
20 changes: 17 additions & 3 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//tools/example_test:defs.bzl", "example_test")
load("//bazel/tools/example_test:defs.bzl", "example_test")

example_test(
name = "oci",
Expand All @@ -8,15 +8,29 @@ example_test(
"oci/WORKSPACE.in",
"oci/pdm.lock",
"oci/pyproject.toml",
"oci/repositories.bzl",
"oci/src/app/BUILD.in",
"oci/src/app/app.py",
"oci/step3.bzl",
"oci/step4.bzl",
],
workspace_template = "local.WORKSPACE",
)

example_test(
name = "docker",
srcs = glob(["docker/**/*"]),
srcs = [
"docker/.bazelrc",
"docker/.bazelversion",
"docker/.docker/config.json",
"docker/.dockerconfig.json",
"docker/BUILD.in",
"docker/WORKSPACE.in",
"docker/pdm.lock",
"docker/pyproject.toml",
"docker/src/app/BUILD.in",
"docker/src/app/app.py",
"docker/step3.bzl",
"docker/step4.bzl",
],
workspace_template = "local.WORKSPACE",
)
2 changes: 2 additions & 0 deletions example/docker/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--repo_env=DOCKER_CONFIG=.
--spawn_strategy=standalone
1 change: 1 addition & 0 deletions example/docker/.docker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions example/docker/.dockerconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions example/docker/BUILD.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
exports_files([
"pyproject.toml",
"pdm.lock",
".dockerconfig.json",
])
6 changes: 0 additions & 6 deletions example/docker/MODULE.bazel

This file was deleted.

Loading

0 comments on commit 70885da

Please sign in to comment.