Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Oct 30, 2024
1 parent 23bf3a3 commit 8a5edd1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
31 changes: 28 additions & 3 deletions pulp_container/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,15 +798,28 @@ def validate(self, data):
"""Validates that all the fields make sense."""
data = super().validate(data)

if bool(data.get("containerfile", None)) == bool(data.get("containerfile_name", None)):
#if bool(data.get("containerfile", None)) == bool(data.get("containerfile_name", None)):
if data.get("containerfile", None) and data.get("containerfile_name", None):
raise serializers.ValidationError(
_("Exactly one of 'containerfile' or 'containerfile_name' must be specified.")
_("Only one of 'containerfile' or 'containerfile_name' must be specified.")
)

if "containerfile_name" in data and "build_context" not in data:
raise serializers.ValidationError(
_("A 'build_context' must be specified when 'containerfile_name' is present.")
)

# with none of build_context and containerfile_name and containerfile
# there is not enough information to build
if not (
data.get("containerfile", None) and
data.get("containerfile_name", None) and
data.get("build_context",None)
):
raise serializers.ValidationError(
_("""At least one of 'build_context' or 'containerfile' or 'containerfile_name'
must be provided""")
)

# TODO: this can be removed after https://github.com/pulp/pulpcore/issues/5786
if data.get("build_context", None):
Expand All @@ -831,7 +844,7 @@ def deferred_files_validation(self, data):
)
)

# check if the containerfile_name exists in the build_context (File Repository)
# check if the provided containerfile_name exists in the build_context (File Repository)
if (
data.get("containerfile_name", None)
and not FileContent.objects.filter(
Expand All @@ -846,6 +859,18 @@ def deferred_files_validation(self, data):
+ '" in the build_context provided'
)
)

# check if a Containerfile exists in the build_context when
# no containerfile_name is provided
if not data.get("containerfile_name",None) and not FileContent.objects.filter(
repositories__in=[build_context.repository.pk],
relative_path="Containerfile",
).exists():
raise serializers.ValidationError(
_(
'Could not find the Containerfile in the build_context provided'
)
)

data["build_context_pk"] = build_context.repository.pk

Expand Down
4 changes: 2 additions & 2 deletions pulp_container/app/tasks/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def build_image(
image and tag.
"""
if not containerfile_tempfile_pk and not containerfile_name:
raise RuntimeError("Neither a name nor temporary file for the Containerfile was specified.")
#if not containerfile_tempfile_pk and not containerfile_name:
# raise RuntimeError("Neither a name nor temporary file for the Containerfile was specified.")

if containerfile_tempfile_pk:
containerfile_artifact = PulpTemporaryFile.objects.get(pk=containerfile_tempfile_pk)
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def build_image(self, request, pk):
temp_file.save()
containerfile_tempfile_pk = str(temp_file.pk)

containerfile_name = serialized_data.get("containerfile_name", None)
containerfile_name = serialized_data.get("containerfile_name", "Containerfile")
tag = serialized_data["tag"]

result = dispatch(
Expand Down

0 comments on commit 8a5edd1

Please sign in to comment.