Skip to content

Commit

Permalink
Added GCP storage support
Browse files Browse the repository at this point in the history
Required PR: pulp/pulpcore#3481
closes pulp#1140
  • Loading branch information
ipanova committed Jan 6, 2023
1 parent 61b1255 commit 8ae7e1f
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .ci/ansible/settings.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ AZURE_CONNECTION_STRING = 'DefaultEndpointsProtocol={{ pulp_scheme }};AccountNam
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
MEDIA_ROOT = ""
GS_BUCKET_NAME = "gcppulp"
GS_CUSTOM_ENDPOINT = "http://ci-gcp:4443"
GS_CUSTOM_ENDPOINT = "https://ci-gcp:4443"
GOOGLE_APPLICATION_CREDENTIALS = "/etc/pulp/credentials.json"
{% endif %}
2 changes: 1 addition & 1 deletion .github/template_gitref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.08.26-191-g8c3448a
2021.08.26-192-g3435100
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:
- TEST: pulp
- TEST: docs
- TEST: azure
- TEST: gcp
- TEST: s3
- TEST: stream
- TEST: lowerbounds
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- TEST: pulp
- TEST: docs
- TEST: azure
- TEST: gcp
- TEST: s3
- TEST: stream
- TEST: generate-bindings
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
- TEST: pulp
- TEST: docs
- TEST: azure
- TEST: gcp
- TEST: s3
- TEST: stream
- TEST: generate-bindings
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,35 @@ if [ "$TEST" = "azure" ]; then
pulp_scenario_settings: null\
' vars/main.yaml
fi
cat >> credentials.json << GCP_JSON
{
"client_id": "pulp-ci-test.apps.googleusercontent.com",
"client_secret": "pulp-Secret",
"refresh_token": "Pulp-CI-Refresh-Token",
"type": "authorized_user"
}
GCP_JSON
if [ "$TEST" = "gcp" ]; then
mkdir -p cigcp gcpdata/gcppulp
mv credentials.json cigcp/credentials.json
cd cigcp
openssl req -newkey rsa:2048 -x509 -nodes -keyout gcpkey.pem -new -out gcpcert.pem -sha256 -days 365 -addext "subjectAltName=DNS:ci-gcp" -subj "/C=CO/ST=ST/L=LO/O=OR/OU=OU/CN=CN"
sudo cp gcpcert.pem /usr/local/share/ca-certificates/gcpcert.crt
sudo dpkg-reconfigure ca-certificates
cd ..
sed -i -e '/^services:/a \
- name: ci-gcp\
image: fsouza/fake-gcs-server\
volumes:\
- ./cigcp:/etc/pulp\
- ./gcpdata:/data\
env:\
GOOGLE_APPLICATION_CREDENTIALS: "/etc/pulp/credentials.json"\
command: "-public-host https://ci-gcp:4443 -cert-location /etc/pulp/gcpcert.pem "' vars/main.yaml
sed -i -e '$a gcp_test: true\
pulp_scenario_settings: null\
' vars/main.yaml
fi

echo "PULP_API_ROOT=${PULP_API_ROOT}" >> "$GITHUB_ENV"

Expand Down
1 change: 1 addition & 0 deletions CHANGES/1140.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added GCP storage support.
18 changes: 18 additions & 0 deletions pulp_container/app/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,21 @@ def redirect_to_object_storage(self, artifact, return_media_type):
}
content_url = artifact.file.storage.url(artifact.file.name, parameters=parameters)
return redirect(content_url)


class GCloudStorageRedirects(S3StorageRedirects):
"""
A class that implements methods for the direct retrieval of manifest objects.
"""

def redirect_to_object_storage(self, artifact, return_media_type):
"""
Redirect to the passed artifact's file stored in the GCP storage.
"""
filename = f"sha256:{artifact.sha256}"
parameters = {
"content_type": return_media_type,
"response_disposition": f"attachment;filename={filename}",
}
content_url = artifact.file.storage.url(artifact.file.name, parameters=parameters)
return redirect(content_url)
3 changes: 3 additions & 0 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
FileStorageRedirects,
S3StorageRedirects,
AzureStorageRedirects,
GCloudStorageRedirects,
)
from pulp_container.app.token_verification import (
RegistryAuthentication,
Expand Down Expand Up @@ -795,6 +796,8 @@ def __init__(self, *args, **kwargs):
self.redirects_class = S3StorageRedirects
elif settings.DEFAULT_FILE_STORAGE == "storages.backends.azure_storage.AzureStorage":
self.redirects_class = AzureStorageRedirects
elif settings.DEFAULT_FILE_STORAGE == "storages.backends.gcloud.GoogleCloudStorage":
self.redirects_class = GCloudStorageRedirects
else:
raise NotImplementedError()

Expand Down
2 changes: 1 addition & 1 deletion template_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_azure: true
test_bindings: false
test_cli: true
test_deprecations: true
test_gcp: false
test_gcp: true
test_performance: false
test_released_plugin_with_next_pulpcore_release: false
test_reroute: true
Expand Down

0 comments on commit 8ae7e1f

Please sign in to comment.