Skip to content

Commit 7e132f9

Browse files
authored
Domain migrate oci (#1237)
* fix missing domain group * Add support for OCI storage in domain migrate * url fix * formatter
1 parent 9a60ec6 commit 7e132f9

3 files changed

Lines changed: 91 additions & 4 deletions

File tree

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ RUN patch -p1 -d /usr/local/lib/pulp/lib/python${PYTHON_VERSION}/site-packages <
176176
COPY images/assets/patches/0057-Optimize-Simple-API-upload_time-and-provenance.patch /tmp/
177177
RUN patch -p1 -d /usr/local/lib/pulp/lib/python${PYTHON_VERSION}/site-packages < /tmp/0057-Optimize-Simple-API-upload_time-and-provenance.patch
178178

179-
COPY images/assets/patches/0058-Domain-Migrate-support-for-OCI.patch /tmp/
180-
RUN patch -p1 -d /usr/local/lib/pulp/lib/python${PYTHON_VERSION}/site-packages < /tmp/0058-Domain-Migrate-support-for-OCI.patch
179+
180+
COPY images/assets/patches/0058-fix-migrate.patch /tmp/
181+
RUN patch -p1 -d /usr/local/lib/pulp/lib/python${PYTHON_VERSION}/site-packages < /tmp/0058-fix-migrate.patch
182+
181183

182184
RUN mkdir /licenses
183185
COPY LICENSE /licenses/LICENSE
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From 298018f116419e3a944f663a7d7fc89e426d0d1a Mon Sep 17 00:00:00 2001
2+
From: Yasen <yasen@trahnov.eu>
3+
Date: Tue, 26 May 2026 13:18:58 +0200
4+
Subject: [PATCH] fix migrate
5+
6+
---
7+
pulpcore/app/tasks/migrate.py | 36 +++++++++++++++++++++++------------
8+
1 file changed, 24 insertions(+), 12 deletions(-)
9+
10+
diff --git a/pulpcore/app/tasks/migrate.py b/pulpcore/app/tasks/migrate.py
11+
index dd15adc1e..789c857d1 100644
12+
--- a/pulpcore/app/tasks/migrate.py
13+
+++ b/pulpcore/app/tasks/migrate.py
14+
@@ -2,7 +2,6 @@ import logging
15+
from gettext import gettext as _
16+
17+
from django.utils.timezone import now
18+
-from rest_framework.serializers import ValidationError
19+
20+
from pulpcore.app.models import Artifact, ProgressReport, storage
21+
from pulpcore.app.serializers import DomainBackendMigratorSerializer
22+
@@ -25,24 +24,30 @@ def migrate_backend(data):
23+
artifacts = Artifact.objects.filter(pulp_domain=domain)
24+
date = now()
25+
26+
+ skipped = []
27+
with ProgressReport(
28+
message=_("Migrating Artifacts"), code="migrate", total=artifacts.count()
29+
) as pb:
30+
while True:
31+
- for digest in pb.iter(artifacts.values_list("sha256", flat=True)):
32+
- filename = storage.get_artifact_path(digest)
33+
- if not new_storage.exists(filename):
34+
+ for artifact in pb.iter(artifacts.iterator()):
35+
+ old_name = artifact.file.name
36+
+ new_name = storage.get_artifact_path(artifact.sha256)
37+
+ if not new_storage.exists(new_name):
38+
try:
39+
- file = old_storage.open(filename)
40+
- except FileNotFoundError:
41+
- raise ValidationError(
42+
- _(
43+
- "Found missing file for artifact(sha256={}). Please run the repair "
44+
- "task or delete the offending artifact."
45+
- ).format(digest)
46+
+ file = old_storage.open(old_name)
47+
+ except Exception as e:
48+
+ _logger.warning(
49+
+ "Skipping artifact(sha256=%s): unable to read from old storage: %s",
50+
+ artifact.sha256,
51+
+ e,
52+
)
53+
- new_storage.save(filename, file)
54+
+ skipped.append(artifact.sha256)
55+
+ continue
56+
+ new_storage.save(new_name, file)
57+
file.close()
58+
+ if old_name != new_name:
59+
+ artifact.file.name = new_name
60+
+ artifact.save(update_fields=["file"])
61+
# Handle new artifacts saved by the content app
62+
artifacts = Artifact.objects.filter(pulp_domain=domain, pulp_created__gte=date)
63+
if count := artifacts.count():
64+
@@ -52,6 +57,13 @@ def migrate_backend(data):
65+
continue
66+
break
67+
68+
+ if skipped:
69+
+ _logger.warning(
70+
+ "Migration completed with %d skipped artifacts (missing from old storage): %s",
71+
+ len(skipped),
72+
+ ", ".join(skipped),
73+
+ )
74+
+
75+
# Update the current domain to the new storage backend settings
76+
msg = _("Update Domain({domain})'s Backend Settings").format(domain=domain.name)
77+
with ProgressReport(message=msg, code="update", total=1) as pb:
78+
--
79+
2.53.0
80+

pulp_service/pulp_service/app/storage.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,17 @@ def url(self, artifact_name, parameters={}, **kwargs):
241241
# Load auth configs
242242
client.auth.load_configs(container, configs=["/tmp/.docker/config.json"])
243243

244-
# Use download_blob with return_blob_url=True to get the URL
245-
blob_url = client.download_blob(
244+
# Use download_blob with return_blob_url=True to get the redirect response
245+
response = client.download_blob(
246246
container=container,
247247
digest=digest,
248248
outfile="", # Not used when return_blob_url=True
249249
return_blob_url=True,
250250
)
251251

252+
# response is a requests.Response with a 302 redirect (allow_redirects=False).
253+
# The actual blob URL is in the Location header.
254+
blob_url = response.headers.get("Location")
255+
if not blob_url:
256+
raise ValueError(f"No redirect URL returned for blob {digest} (status={response.status_code})")
252257
return blob_url

0 commit comments

Comments
 (0)