Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosIntel Devs: Smart AI Edge Solutions - 0 Introduction | Intel Software(22.09.2026 um 23:48 Uhr)
Windows Tipps & SecurityGoogles gibt Chrome 154 frei und schließt über 100 Lücken(23.09.2026 um 09:11 Uhr)
Windows Tipps & SecurityKlangerlebnis & Sicherheit im Vonovia Ruhrstadion(23.09.2026 um 08:45 Uhr)
Unix & Linux ServerLocal AI Jargon Quiz: Do You Know All These Buzzwords?(23.09.2026 um 08:38 Uhr)
Sichere ProgrammierungNeu von AWS: Weniger Kontextpflege für selbst gebaute KI-Agenten(23.09.2026 um 09:52 Uhr)
Sichere ProgrammierungLINQ GroupBy: The Operator Everyone Uses Wrong(23.09.2026 um 09:41 Uhr)
Sichere ProgrammierungIT Heard About the Acquisition Nine Days Before It Closed(23.09.2026 um 09:45 Uhr)
YouTube Security VideosIntel Devs: Smart AI Edge Solutions - 0 Introduction | Intel Software(22.09.2026 um 23:48 Uhr)
Windows Tipps & SecurityGoogles gibt Chrome 154 frei und schließt über 100 Lücken(23.09.2026 um 09:11 Uhr)
Windows Tipps & SecurityKlangerlebnis & Sicherheit im Vonovia Ruhrstadion(23.09.2026 um 08:45 Uhr)
Unix & Linux ServerLocal AI Jargon Quiz: Do You Know All These Buzzwords?(23.09.2026 um 08:38 Uhr)
Sichere ProgrammierungNeu von AWS: Weniger Kontextpflege für selbst gebaute KI-Agenten(23.09.2026 um 09:52 Uhr)
Sichere ProgrammierungLINQ GroupBy: The Operator Everyone Uses Wrong(23.09.2026 um 09:41 Uhr)
Sichere ProgrammierungIT Heard About the Acquisition Nine Days Before It Closed(23.09.2026 um 09:45 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

GCP publish python package in production

GCP: Publish Python Package in Production This guide explains how to use Google Artifact Registry to manage shared Python code as a package. This approach eliminates code duplication between your Cloud Functions and server. …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




GCP: Publish Python Package in Production



This guide explains how to use Google Artifact Registry to manage shared Python code as a package. This approach eliminates code duplication between your Cloud Functions and server.









Step 1: Structure Your Shared Code



Create a new Python package for your shared logic (e.g., common_logic).




common_logic/
├── setup.py
├── common_logic/
│ ├── __init__.py












Step 2: Create setup.py



Define your package configuration in a setup.py file:




from setuptools import setup, find_packages

setup(
name="common_logic",
version="0.1.0",
packages=find_packages(),
install_requires=[
"pandas>=1.3.0",
],
author="Your Name",
author_email="[email protected]",
description="Common logic for app",
)












Step 3: Set Up Google Artifact Registry




  1. Enable the Artifact Registry API:




   gcloud services enable artifactregistry.googleapis.com







  1. Create a Python repository:




   gcloud artifacts repositories create python-packages \
--repository-format=python \
--location=us-central1 \
--description="Python packages repository"












Step 4: Configure Authentication




  1. Create a service account:




   gcloud iam service-accounts create artifact-publisher \
--description="Service account for publishing to Artifact Registry"







  1. Grant necessary permissions:




   gcloud artifacts repositories add-iam-policy-binding python-packages \
--location=us-central1 \
--member="serviceAccount:artifact-publisher@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/artifactregistry.writer"







  1. Create and download a key:




   gcloud iam service-accounts keys create key.json \
--iam-account=artifact-publisher@${PROJECT_ID}.iam.gserviceaccount.com












Step 5: Build and Upload Package




  1. Install build tools:




   pip install build twine







  1. Build the package:




   python -m build







  1. Configure twine for Artifact Registry:




   cat > ~/.pypirc << EOL
[distutils]
index-servers = common-logic-repo
[common-logic-repo]
repository: https://us-central1-python.pkg.dev/
${PROJECT_ID}/python-packages/
username: _json_key_base64
password:
$(base64 -w0 key.json)
EOL







  1. Upload the package:




   twine upload --repository common-logic-repo dist/*












Step 6: Use the Package






In Cloud Functions




  1. Create a requirements.txt file:




   --index-url https://pypi.org/simple
--extra-index-url https://oauth2accesstoken:${ARTIFACT_REGISTRY_TOKEN}@us-central1-python.pkg.dev/${PROJECT_ID}/python-packages/simple/
common-logic==0.1.0







  1. Use the package in your Cloud Function:




   from common_logic import ...

def cloud_function(request):
# Your cloud function code using the imported functions
pass









In Server Code




  1. Add to your server's requirements.txt:




   --index-url https://pypi.org/simple
--extra-index-url https://oauth2accesstoken:${ARTIFACT_REGISTRY_TOKEN}@us-central1-python.pkg.dev/${PROJECT_ID}/python-packages/simple/
common-logic==0.1.0







  1. Use it in your server code:




   from common_logic import ...
# Your server code using the imported functions












Step 7: CI/CD Integration




  1. Add the service account key as a secret in your GitHub repository.

  2. Update your Cloud Build configuration:




   steps:
- name: 'python'
entrypoint: pip
args: ['install', 'build', 'twine']

- name: 'python'
entrypoint: python
args: ['-m', 'build']
dir: 'common_logic'

- name: 'python'
entrypoint: twine
args: ['upload', '--repository', 'common-logic-repo', 'dist/*']
dir: 'common_logic'
env:
- 'TWINE_USERNAME=_json_key_base64'
- 'TWINE_PASSWORD=${_ARTIFACT_REGISTRY_KEY}'












Step 8: Version Management




  1. Update the version in setup.py.

  2. Build and upload the new version.

  3. Update requirements.txt in both Cloud Functions and server code.

  4. Deploy both components.









Best Practices




  • Use semantic versioning for your package.

  • Pin specific versions in requirements.txt.

  • Test new versions thoroughly before deploying.

  • Keep a changelog of version changes.

  • Use environment variables for PROJECT_ID and LOCATION.

  • Include comprehensive documentation in your package.









Common Issues and Solutions






Authentication Errors




  • Verify service account permissions.

  • Ensure key.json is properly encoded.

  • Check .pypirc configuration.






Package Not Found




  • Verify repository URL format.

  • Check if the package was successfully uploaded.

  • Ensure requirements.txt uses the correct URL format.






Version Conflicts




  • Pin specific versions of dependencies.

  • Use virtual environments for testing.

  • Document dependency requirements clearly.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten GCP publish python package in production

Thematisch verwandte Begriffe: publish, python, package, production · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-96258 | A vulnerability has been found in onSite internet GmbH Auktion NG Auktio…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick