Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Jul 22, 2024
1 parent 6b7dc17 commit 1f05613
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGES/479.feature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Replaced `artifacts` by pulp-file `repo_version` (Pulp File plugin repository
Replaced `artifacts` by pulp-file `repository_version` (Pulp File plugin repository
version href) as the parameter to provide the build context for a Containerfile.
17 changes: 0 additions & 17 deletions pulp_container/app/global_access_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,3 @@ def has_distribution_perms(request, view, action, permission):
return any(
(request.user.has_perm(permission, distribution.cast()) for distribution in distributions)
)


def has_repository_perms(request, view, action, permission):
"""
Check if the user has permissions on the corresponding repository.
"""
obj = view.get_object() if view.detail else None
context = {"request": request}
serializer = view.serializer_class(instance=obj, data=request.data, context=context)
serializer.is_valid(raise_exception=True)
repo_version = serializer.validated_data.get("repo_version", None)
if not repo_version:
return True

repo_version_qs = RepositoryVersion.objects.filter(pk=repo_version)
repositories = get_objects_for_user(request.user, permission, repo_version_qs)
return repo_version_qs == repositories
7 changes: 2 additions & 5 deletions pulp_container/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ class OCIBuildImageSerializer(ValidateFieldsMixin, serializers.Serializer):
tag = serializers.CharField(
required=False, default="latest", help_text="A tag name for the new image being built."
)
repo_version = RepositoryVersionRelatedField(
repository_version = RepositoryVersionRelatedField(
required=False,
help_text=_("RepositoryVersion to be used as the build context for container images."),
allow_null=True,
Expand Down Expand Up @@ -777,9 +777,6 @@ def validate(self, data):
_("'containerfile' or 'containerfile_artifact' must " "be specified.")
)

if "repo_version" in data:
data["repo_version"] = data["repo_version"].pk

return data

class Meta:
Expand All @@ -788,7 +785,7 @@ class Meta:
"containerfile",
"repository",
"tag",
"repo_version",
"repository_version",
)


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 @@ -96,7 +96,7 @@ def add_image_from_directory_to_repository(path, repository, tag):


def build_image_from_containerfile(
containerfile_pk=None, repository_pk=None, tag=None, repo_version=None
containerfile_pk=None, repo_version=None, repository_pk=None, tag=None
):
"""
Builds an OCI container image from a Containerfile.
Expand Down
6 changes: 3 additions & 3 deletions pulp_container/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class ContainerRepositoryViewSet(
"condition": [
"has_model_or_obj_perms:container.build_image_containerrepository",
"has_model_or_obj_perms:container.view_containerrepository",
"has_repository_perms:file.view_filerepository",
"has_repo_or_repo_ver_param_model_or_obj_perms:file.view_filerepository",
],
},
{
Expand Down Expand Up @@ -947,7 +947,7 @@ def build_image(self, request, pk):
containerfile.touch()
tag = serializer.validated_data["tag"]

repo_version = serializer.validated_data.get("repo_version", None)
repo_version = serializer.validated_data.get("repository_version", None)

result = dispatch(
tasks.build_image_from_containerfile,
Expand All @@ -956,7 +956,7 @@ def build_image(self, request, pk):
"containerfile_pk": str(containerfile.pk),
"tag": tag,
"repository_pk": str(repository.pk),
"repo_version": repo_version,
"repo_version": repo_version.pk,
},
)
return OperationPostponedResponse(result, request)
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/tests/functional/api/test_build_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _build_image(repository, containerfile, repo_version=None):
build_response = container_repository_api.build_image(
container_container_repository_href=repository,
containerfile=containerfile,
repo_version=repo_version,
repository_version=repo_version,
)
monitor_task(build_response.task)

Expand Down
2 changes: 1 addition & 1 deletion staging_docs/admin/guides/build-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CMD ["cat", "/inside-image.txt"]' >> Containerfile

```bash
TASK_HREF=$(http --form POST :$CONTAINER_REPO'build_image/' "containerfile@./Containerfile" \
repo_version=${FILE_REPO}versions/1/ | jq -r '.task')
repository_version=${FILE_REPO}versions/1/ | jq -r '.task')
```


Expand Down

0 comments on commit 1f05613

Please sign in to comment.