Skip to content

Latest commit

 

History

History
195 lines (151 loc) · 3.47 KB

File metadata and controls

195 lines (151 loc) · 3.47 KB

Python Dagger Module

This module provides Dagger functions for Python CI/CD workflows including linting, testing, security scanning, and Docker image building.

Features

  • ✅ Python linting with ruff
  • ✅ Format checking with ruff
  • ✅ Testing with pytest
  • ✅ Test coverage reporting with pytest-cov
  • ✅ Security scanning with bandit
  • ✅ Docker image building and pushing

Prerequisites

  • Dagger CLI installed
  • Docker runtime available

Quick Start

Lint

# Lint Python source code
dagger call -m python lint \
  --src tests/python/ \
  --progress plain

Format Check

# Check Python code formatting
dagger call -m python format-check \
  --src tests/python/ \
  --progress plain

Test

# Run pytest
dagger call -m python test \
  --src tests/python/ \
  --progress plain

Test with Coverage

# Run pytest with coverage reporting
dagger call -m python test-with-coverage \
  --src tests/python/ \
  --coverage-path src/ \
  --progress plain

Security Scan

# Run bandit security scanner
dagger call -m python security-scan \
  --src tests/python/ \
  --scan-path src/ \
  --progress plain

Build Image

# Build Docker image from Dockerfile
dagger call -m python build-image \
  --src tests/python/ \
  --progress plain

Build and Push Image

# Build and push to temporary registry (no auth)
dagger call -m python build-and-push-image \
  --src tests/python/ \
  --image-ref ttl.sh/stuttgart-things/python-test:1h \
  --token env:GITHUB_TOKEN \
  --progress plain

# Build and push to GitHub Container Registry (with auth)
dagger call -m python build-and-push-image \
  --src tests/python/ \
  --image-ref ghcr.io/stuttgart-things/python-test:1.0.0 \
  --token env:GITHUB_TOKEN \
  --username patrick-hermann-sva \
  --registry-url ghcr.io \
  --progress plain

Test Module

# Run comprehensive tests
task test-python

API Reference

Linting

dagger call -m python lint \
  --src "." \
  --ruff-version 0.8.6 \
  --paths "src/,tests/" \
  --progress plain

Format Checking

dagger call -m python format-check \
  --src "." \
  --ruff-version 0.8.6 \
  --paths "src/,tests/" \
  --progress plain

Testing

dagger call -m python test \
  --src "." \
  --python-version 3.12-slim \
  --test-path tests/ \
  --install-extra ".[dev]" \
  --progress plain

Test with Coverage

dagger call -m python test-with-coverage \
  --src "." \
  --python-version 3.12-slim \
  --test-path tests/ \
  --coverage-path src/ \
  --progress plain

Security Scanning

dagger call -m python security-scan \
  --src "." \
  --bandit-version 1.8.3 \
  --scan-path src/ \
  --progress plain

Image Building

dagger call -m python build-image \
  --src "." \
  --dockerfile Dockerfile \
  --version 1.0.0 \
  --progress plain

Build and Push

dagger call -m python build-and-push-image \
  --src "." \
  --image-ref ghcr.io/org/image:tag \
  --token env:REGISTRY_TOKEN \
  --username env:REGISTRY_USER \
  --registry-url ghcr.io \
  --progress plain

Examples

See the main README for detailed usage examples.

Testing

task test-python

Resources