Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Oct 31, 2024
1 parent 8a5edd1 commit 5fc9c7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
41 changes: 25 additions & 16 deletions pulp_container/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@ 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)):
# only one of containerfile or containerfile_name should be provided, none of them is ok
# in case we have a build_context because Pulp will try to find a file called Containerfile
# in the build_context provided
if data.get("containerfile", None) and data.get("containerfile_name", None):
raise serializers.ValidationError(
_("Only one of 'containerfile' or 'containerfile_name' must be specified.")
Expand All @@ -808,17 +810,19 @@ def validate(self, 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

# with none of build_context nor containerfile_name nor 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)
data.get("containerfile", None)
or data.get("containerfile_name", None)
or data.get("build_context", None)
):
raise serializers.ValidationError(
_("""At least one of 'build_context' or 'containerfile' or 'containerfile_name'
must be provided""")
_(
"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
Expand All @@ -834,6 +838,12 @@ def deferred_files_validation(self, data):
"""
if build_context := data.get("build_context", None):

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

# if a containerfile was passed with the build_context we can skip the following checks
if data.get("containerfile", None):
return data

# check if the on_demand_artifacts exist
for on_demand_artifact in build_context.on_demand_artifacts.iterator():
if not on_demand_artifact.content_artifact.artifact:
Expand All @@ -859,21 +869,20 @@ 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(
if (
not data.get("containerfile_name", None)
and not FileContent.objects.filter(
repositories__in=[build_context.repository.pk],
relative_path="Containerfile",
).exists():
).exists()
):
raise serializers.ValidationError(
_(
'Could not find the Containerfile in the build_context provided'
)
_("Could not find the Containerfile in the build_context provided")
)

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

return data

class Meta:
Expand Down
3 changes: 0 additions & 3 deletions pulp_container/app/tasks/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ 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 containerfile_tempfile_pk:
containerfile_artifact = PulpTemporaryFile.objects.get(pk=containerfile_tempfile_pk)

Expand Down

0 comments on commit 5fc9c7d

Please sign in to comment.