Zum Inhalt

Dependencies

Polycrate unterstützt Block-Abhängigkeiten durch Vererbung. Dependencies werden automatisch anhand der from: Stanza in den Block-Konfigurationen ermittelt.

Wie funktionieren Dependencies?

Wenn ein Block von einem anderen Block erbt, entsteht automatisch eine Dependency:

# blocks/my-postgres/block.poly
name: my-postgres
from: postgres-base  # <- Dependency zu postgres-base
kind: k8sapp

config:
  namespace: production

In diesem Beispiel ist postgres-base eine Dependency von my-postgres. Polycrate erkennt dies automatisch.

Dependency-Auflösung

Automatische Auflösung mit --blocks-auto-pull

Der einfachste Weg ist, das --blocks-auto-pull Flag zu verwenden. Polycrate pullt dann automatisch alle fehlenden Dependencies:

# Bei jeder Workspace-Interaktion
polycrate run my-postgres install --blocks-auto-pull

# Bei Workflow-Ausführung
polycrate workflows run deploy-stack --blocks-auto-pull

# Bei Block-Inspection
polycrate blocks inspect my-postgres --blocks-auto-pull

Mit --blocks-auto-pull werden alle Dependencies automatisch von der Registry gepullt, falls sie nicht lokal vorhanden sind.

Manuelles Pullen von Dependencies

Sie können Dependencies auch manuell pullen:

# Einzelne Dependency pullen
polycrate blocks pull postgres-base

# Mit spezifischer Version
polycrate blocks pull postgres-base:1.2.0

# Von spezifischer Registry
polycrate blocks pull cargo.ayedo.cloud/ayedo/k8s/postgres-base:1.2.0

Dependency-Hierarchie

Dependencies können verschachtelt sein:

# Block: base
name: base
kind: generic

# Block: database-base
name: database-base
from: base  # <- Dependency zu base

# Block: postgres-base
name: postgres-base
from: database-base  # <- Dependency zu database-base (und transitiv zu base)

# Block: my-postgres
name: my-postgres
from: postgres-base  # <- Dependency zu postgres-base (und transitiv zu database-base und base)

Polycrate löst die gesamte Dependency-Kette automatisch auf.

Dependency-Quellen

Dependencies können aus verschiedenen Quellen stammen:

1. Lokale Blocks

name: my-app
from: base-app  # Lokaler Block im Workspace

Wenn base-app im lokalen Workspace existiert (in blocks/base-app/), wird er direkt verwendet.

2. Registry-Blocks

name: my-app
from: cargo.ayedo.cloud/ayedo/k8s/base-app:1.0.0

Wenn der Block nicht lokal vorhanden ist, wird er von der angegebenen Registry gepullt.

3. Polycrate Hub

name: my-app
from: postgres-base  # Wird von hub.polycrate.io gepullt

Wenn keine Registry angegeben ist, sucht Polycrate im Polycrate Hub.

Praktische Workflows

Workflow 1: Projekt-Setup mit Dependencies

# 1. Workspace klonen
git clone https://github.com/myorg/my-workspace.git
cd my-workspace

# 2. Alle Dependencies automatisch pullen
polycrate run my-app install --blocks-auto-pull

# Oder manuell:
# polycrate blocks pull postgres-base
# polycrate blocks pull redis-base
# polycrate run my-app install

Workflow 2: Dependency aktualisieren

# Neue Version einer Dependency pullen
polycrate blocks pull postgres-base:2.0.0

# Block-Config anpassen
# blocks/my-postgres/block.poly:
#   from: postgres-base:2.0.0

# Testen
polycrate run my-postgres install

Workflow 3: CI/CD mit Dependencies

# .github/workflows/deploy.yml
name: Deploy

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install Polycrate
        run: |
          curl -sSL https://get.polycrate.io | bash

      - name: Deploy with auto-pull
        run: |
          polycrate run my-app install --blocks-auto-pull

Dependency-Management Best Practices

1. Versionierung verwenden

Nutzen Sie spezifische Versionen für stabile Dependencies:

# ✅ Gut: Spezifische Version
name: my-postgres
from: postgres-base:1.2.0

# ❌ Schlecht: Latest (kann unerwartet brechen)
name: my-postgres
from: postgres-base:latest

2. Lokale Kopien für Anpassungen

Wenn Sie eine Dependency anpassen müssen, pullen Sie sie lokal:

# Dependency lokal pullen
polycrate blocks pull postgres-base

# Jetzt ist sie in blocks/postgres-base/
# Sie können sie anpassen und dann referenzieren:
name: my-postgres
from: postgres-base  # Nutzt jetzt die lokale Kopie

3. Private Registries

Für private/proprietäre Blocks nutzen Sie private Registries:

name: my-internal-app
from: registry.mycompany.com/apps/base-app:1.0.0

Authentifizierung über:

# Docker Registry Login
docker login registry.mycompany.com

# Polycrate nutzt Docker-Credentials
polycrate blocks pull registry.mycompany.com/apps/base-app:1.0.0

4. Dependency-Dokumentation

Dokumentieren Sie Dependencies in der README:

# my-postgres

## Dependencies
- `postgres-base:1.2.0` - Basis PostgreSQL-Block
  - `database-base:1.0.0` - Generische Datenbank-Features
    - `base:1.0.0` - Basis-Block für alle Blocks

## Installation
polycrate run my-postgres install --blocks-auto-pull

Troubleshooting

Dependency nicht gefunden

Error: Block 'postgres-base' not found

Lösung:

# Manuell pullen
polycrate blocks pull postgres-base

# Oder auto-pull verwenden
polycrate run my-app install --blocks-auto-pull

Version-Konflikt

Wenn mehrere Blocks verschiedene Versionen derselben Dependency benötigen:

# Block A
from: base:1.0.0

# Block B
from: base:2.0.0

Polycrate pulled beide Versionen, aber nur eine kann aktiv genutzt werden.

Lösung: Nutzen Sie konsistente Versionen oder separate Workspaces.

Registry nicht erreichbar

Error: Failed to pull from registry

Lösung:

# Prüfen Sie Netzwerk und Authentifizierung
docker login cargo.ayedo.cloud

# Alternativen Hub verwenden
export POLYCRATE_HUB_URL=https://alternative-hub.example.com

Polycrate Hub

Von ayedo bereitgestellte, öffentlich verfügbare Blocks finden Sie im Polycrate Hub:

🌐 hub.polycrate.io

Der Hub bietet: - Fertige Blocks für häufige Use Cases (Postgres, Redis, Nginx, etc.) - Versionierte Releases für stabile Deployments - Dokumentation für jeden Block - Suchfunktion um passende Blocks zu finden

Zusammenhang mit anderen Konzepten

  • Vererbung: Dependencies basieren auf der from: Vererbung
  • Registry: Dependencies werden von OCI-Registries gepullt
  • Polycrate Hub: Zentrale Registry für öffentliche Blocks
  • Blocks: Dependencies sind Blocks, die von anderen Blocks genutzt werden

Auto-Pull im Alltag

Fügen Sie --blocks-auto-pull als Alias hinzu für einfacheren Alltags-Workflow:

alias pr='polycrate run --blocks-auto-pull'
pr my-app install  # Pullt automatisch alle Dependencies