Skip to content

Commit

Permalink
Adds models, viewsets, and serializers needed for publishing
Browse files Browse the repository at this point in the history
This patch also updates the publish task to simply create a pass_through Publication.

Required PR: pulp/pulp#3675

closes: #3991
https://pulp.plan.io/issues/3991

closes: #3992
https://pulp.plan.io/issues/3992
  • Loading branch information
dkliban committed Sep 28, 2018
1 parent d4e57d1 commit 84f44f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ dist: xenial
language: python
python:
# python versions used in el7 SCL & supported fedora
- "3.5"
- "3.6"
- "3.7"
env:
Expand Down
13 changes: 12 additions & 1 deletion pulp_docker/app/models.py
Expand Up @@ -3,7 +3,7 @@

from django.db import models

from pulpcore.plugin.models import Content, Remote, Publisher
from pulpcore.plugin.models import BaseDistribution, Content, Remote, Publisher


logger = getLogger(__name__)
Expand Down Expand Up @@ -192,3 +192,14 @@ class DockerRemote(Remote):
"""

TYPE = 'docker'


class DockerDistribution(BaseDistribution):
"""
A docker distribution defines how a publication is distributed by Pulp's webserver.
All docker distributions are made available at /v2/<base_path>/.
"""

class Meta:
default_related_name = 'docker_distributions'
28 changes: 3 additions & 25 deletions pulp_docker/app/tasks/publishing.py
Expand Up @@ -3,12 +3,8 @@

from pulpcore.plugin.models import ( # noqa
RepositoryVersion,
Publication,
PublishedArtifact,
PublishedMetadata,
RemoteArtifact
Publication
)
from pulpcore.plugin.tasking import WorkingDirectory

from pulp_docker.app.models import DockerPublisher

Expand All @@ -32,25 +28,7 @@ def publish(publisher_pk, repository_version_pk):
ver=repository_version.number,
pub=publisher.name
))
with WorkingDirectory():
with Publication.create(repository_version, publisher) as publication:
# Write any Artifacts (files) to the file system, and the database.
#
# artifact = YourArtifactWriter.write(relative_path)
# published_artifact = PublishedArtifact(
# relative_path=artifact.relative_path,
# publication=publication,
# content_artifact=artifact)
# published_artifact.save()

# Write any metadata files to the file system, and the database.
#
# metadata = YourMetadataWriter.write(relative_path)
# metadata = PublishedMetadata(
# relative_path=os.path.basename(manifest.relative_path),
# publication=publication,
# file=File(open(manifest.relative_path, 'rb')))
# metadata.save()
pass

publication = Publication.create(repository_version, publisher, pass_through=True)

log.info(_('Publication: {publication} created').format(publication.pk))
19 changes: 8 additions & 11 deletions pulp_docker/app/viewsets.py
Expand Up @@ -7,24 +7,24 @@

from drf_yasg.utils import swagger_auto_schema

from pulpcore.plugin import viewsets as core
from pulpcore.plugin.serializers import (
AsyncOperationResponseSerializer,
RepositoryPublishURLSerializer,
RepositorySyncURLSerializer,
)
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.viewsets import (
RemoteViewSet,
OperationPostponedResponse,
PublisherViewSet)
from rest_framework.decorators import detail_route

from . import models, serializers, tasks


class DockerRemoteViewSet(core.RemoteViewSet):
class DockerRemoteViewSet(RemoteViewSet):
"""
A ViewSet for DockerRemote.
Similar to the DockerContentViewSet above, define endpoint_name,
queryset and serializer, at a minimum.
"""

endpoint_name = 'docker'
Expand Down Expand Up @@ -56,15 +56,12 @@ def sync(self, request, pk):
'repository_pk': repository.pk
}
)
return core.OperationPostponedResponse(result, request)
return OperationPostponedResponse(result, request)


class DockerPublisherViewSet(core.PublisherViewSet):
class DockerPublisherViewSet(PublisherViewSet):
"""
A ViewSet for DockerPublisher.
Similar to the DockerContentViewSet above, define endpoint_name,
queryset and serializer, at a minimum.
"""

endpoint_name = 'docker'
Expand Down Expand Up @@ -101,4 +98,4 @@ def publish(self, request, pk):
'repository_version_pk': str(repository_version.pk)
}
)
return core.OperationPostponedResponse(result, request)
return OperationPostponedResponse(result, request)

0 comments on commit 84f44f0

Please sign in to comment.