Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Nov 1, 2024
1 parent 7778711 commit 2c851fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
6 changes: 3 additions & 3 deletions pulp_container/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ def deferred_files_validation(self, data):
raise serializers.ValidationError(
_("Could not find the Containerfile in the build_context provided")
)
if not data.get("containerfile_name",None):
data["containerfile_name"]="Containerfile"

if not data.get("containerfile_name", None):
data["containerfile_name"] = "Containerfile"

return data

Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/tasks/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def build_image(
context_path, content_artifact.relative_path, content_artifact.artifact.file
)

#containerfile_name = containerfile_name or "Containerfile"
containerfile_name = containerfile_name or "Containerfile"
_copy_file_from_artifact(working_directory, containerfile_name, containerfile_artifact)
containerfile_path = os.path.join(working_directory, containerfile_name)

Expand Down
61 changes: 22 additions & 39 deletions pulp_container/tests/functional/api/test_build_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,31 @@ def test_build_image_from_repo_version_with_creator_user(

def test_build_image_without_containerfile(
build_image,
check_manifest_fields,
container_distribution_api,
container_repo,
delete_orphans_pre,
gen_object_with_cleanup,
local_registry,
populated_file_repo,
):
"""Test build an OCI image without a containerfile"""
with pytest.raises(ApiException):
build_image(
repository=container_repo.pulp_href,
build_context=f"{populated_file_repo.pulp_href}versions/2/",
)
"""Test build an OCI image without explicitly passing a Containerfile"""
build_image(
repository=container_repo.pulp_href,
build_context=f"{populated_file_repo.pulp_href}versions/2/",
)

distribution = gen_object_with_cleanup(
container_distribution_api,
ContainerContainerDistribution(**gen_distribution(repository=container_repo.pulp_href)),
)

local_registry.pull(distribution.base_path)
image = local_registry.inspect(distribution.base_path)
assert image[0]["Config"]["Cmd"] == ["cat", "/tmp/inside-image.txt"]
assert check_manifest_fields(
manifest_filters={"digest": image[0]["Digest"]}, fields={"type": MANIFEST_TYPE.IMAGE}
)


def test_build_image_without_expected_files(
Expand Down Expand Up @@ -256,36 +272,3 @@ def test_with_containerfilename_and_containerfile(
)
assert e.value.status == 400
assert "Only one of 'containerfile' or 'containerfile_name' must be specified." in e.value.body



def test_build_image_with_uploaded_containerfile_without_passing_it(
build_image,
check_manifest_fields,
container_distribution_api,
container_repo,
populated_file_repo,
delete_orphans_pre,
gen_object_with_cleanup,
local_registry,
):
"""
Test build an OCI image from a file repository_version without needing to provide the
Containerfile (it should look for a file called Containerfile in the file repository).
"""
build_image(
repository=container_repo.pulp_href,
build_context=f"{populated_file_repo.pulp_href}versions/2/",
)

distribution = gen_object_with_cleanup(
container_distribution_api,
ContainerContainerDistribution(**gen_distribution(repository=container_repo.pulp_href)),
)

local_registry.pull(distribution.base_path)
image = local_registry.inspect(distribution.base_path)
assert image[0]["Config"]["Cmd"] == ["cat", "/tmp/inside-image.txt"]
assert check_manifest_fields(
manifest_filters={"digest": image[0]["Digest"]}, fields={"type": MANIFEST_TYPE.IMAGE}
)

0 comments on commit 2c851fc

Please sign in to comment.