Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Jan 21, 2025
1 parent 6280e70 commit 0799334
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 101 deletions.
16 changes: 11 additions & 5 deletions oci_python_image/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_library")
load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_library", "py_image_layer")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@pip//:requirements.bzl", "requirement")
load("@rules_oci//oci:defs.bzl", "oci_load")
load("//oci_python_image:py_layer.bzl", "py_oci_image")
load("@rules_oci//oci:defs.bzl", "oci_load", "oci_image")

py_library(
name = "hello_world_lib",
Expand Down Expand Up @@ -32,14 +31,21 @@ py_binary(
#2f2353bd5bea: Loading layer [==================================================>] 47.13MB/47.13MB
#f02532d45017: Loading layer [==================================================>] 3.62MB/3.62MB
#9296e9071c11: Loading layer [==================================================>] 16.24kB/16.24kB
py_oci_image(
py_image_layer(
name = "layers",
binary = ":hello_world",
)

oci_image(
name = "image",
# This is defined by an oci.pull() call in /MODULE.bazel
base = "@ubuntu",
binary = "hello_world",
entrypoint = ["/oci_python_image/hello_world/hello_world"],
tars = [":layers"],
)

# This is defined by an oci.pull() call in /MODULE.bazel

platform(
name = "aarch64_linux",
constraint_values = [
Expand Down
31 changes: 14 additions & 17 deletions oci_python_image/hello_world/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,20 @@ def OCIImageContainer(image):
# Probe and layer loading phase
layers = manifest["layers"]
needed = []
i = 0
while i < len(layers):
layer = layers[i]


# Probing phase
for i, layer in enumerate(layers):
tmp = tempfile.NamedTemporaryFile(suffix=".tar")
tar = tarfile.open(fileobj=tmp, mode="w")

add_json_file(
tar,
name="manifest.json",
contents=[
{
"Config": "config.json",
"RepoTags": [],
"Layers": list(
map(lambda x: x["digest"], manifest["layers"][: i + 1])
),
"Layers": [layer['digest']],
}
],
)
Expand All @@ -73,27 +71,22 @@ def OCIImageContainer(image):
contents={
"rootfs": {
"type": "layers",
"diff_ids": config["rootfs"]["diff_ids"][: i + 1],
"diff_ids": [config["rootfs"]["diff_ids"][i]],
}
},
)

if layer["digest"] in needed:
add_file(
tar, name=layer["digest"], fileobj=open_blob(image, layer["digest"])
)

tar.close()

try:
r = client.images.load(open(tmp.name, "rb"))
i += 1
# print(r[0].id)
# os.system("tar -tvf %s" % tmp.name)
client.images.load(
open(tmp.name, "rb"),
)
except docker.errors.ImageLoadError as e:
needed.append(layer["digest"])

# Config loading phase
# Loading phase
tmp = tempfile.NamedTemporaryFile(suffix=".tar")
tar = tarfile.open(fileobj=tmp, mode="w")
add_json_file(
Expand All @@ -110,12 +103,16 @@ def OCIImageContainer(image):
add_file(
tar, name="config.json", fileobj=open_blob(image, manifest["config"]["digest"])
)
for layer in needed:
add_file(tar, name=layer, fileobj=open_blob(image, layer))

tar.close()
r = client.images.load(open(tmp.name, "rb"))
return DockerContainer(r[0].id)


def test_wait_for_hello():
print("Starting container")
with OCIImageContainer("oci_python_image/hello_world/image") as container:
wait_for_logs(container, "hello py_image_layer!")

Expand Down
79 changes: 0 additions & 79 deletions oci_python_image/py_layer.bzl

This file was deleted.

0 comments on commit 0799334

Please sign in to comment.