build-counter

Build Counter

A modern HTTP service for tracking build start and finish times in CI/CD pipelines with web dashboard, metrics, and dual storage modes.

CI/CD Pipeline Go Version License Docker Pulls Helm Chart

✨ Features

🎯 Core Functionality

📊 Monitoring & Observability

🚀 Production Ready

🖥️ Web Interface

The build counter includes a modern web dashboard accessible at http://localhost:8080/:

Main Dashboard:

Features by Mode:

⚡ Quick Start

Option 1: Database Mode (Full Features)

Prerequisites:

Setup:

# 1. Create database schema
psql -d your_db -f builds.sql

# 2. Set database connection
export DATABASE_URL="postgres://user:password@localhost:5432/builddb?sslmode=disable"

# 3. Run the service
./build-counter
# or
make run

Option 2: Lightweight Mode (Kubernetes ConfigMap)

Prerequisites:

Setup:

# Set Kubernetes namespace (optional)
export NAMESPACE="your-namespace"
export CONFIGMAP_NAME="build-counter"

# Run in lightweight mode
./build-counter --lightweight

Option 3: Docker

# Pull from GitHub Container Registry (recommended)
docker pull ghcr.io/rossigee/build-counter:latest

# Or from Docker Hub
docker pull rossigee/build-counter:latest

# Run in database mode
docker run -p 8080:8080 \
  -e DATABASE_URL="postgres://user:pass@host:5432/db" \
  ghcr.io/rossigee/build-counter:latest

# Run in lightweight mode  
docker run -p 8080:8080 \
  -v ~/.kube/config:/root/.kube/config \
  -e NAMESPACE="default" \
  ghcr.io/rossigee/build-counter:latest --lightweight

📖 Usage

Command Line Options

build-counter [options]

Options:
  --version          Show version information
  --help             Show help message  
  --lightweight      Use Kubernetes ConfigMap storage
  --health-check     Check if service is healthy

API Endpoints

Build Management

# Start a build
curl -X POST "http://localhost:8080/start?name=my-project&build_id=abc123"
# Response: {"next_id": 42}

# Finish a build  
curl -X POST "http://localhost:8080/finish?name=my-project&build_id=abc123"
# Response: HTTP 201 Created

Data Access

# Get all projects (JSON)
curl http://localhost:8080/api/projects

# Get builds for a project (JSON)  
curl "http://localhost:8080/api/projects?name=my-project"

# Web dashboard
open http://localhost:8080/

Health & Monitoring

# Health check
curl http://localhost:8080/health

# Kubernetes probes
curl http://localhost:8080/healthz   # Liveness
curl http://localhost:8080/readyz    # Readiness

# Prometheus metrics
curl http://localhost:8080/metrics

⚙️ Configuration

Environment Variables

Variable Description Required Default
DATABASE_URL PostgreSQL connection string Yes (database mode) -
NAMESPACE Kubernetes namespace No default
CONFIGMAP_NAME ConfigMap name No build-counter

OpenTelemetry Tracing (Optional)

# Enable OTLP tracing
export OTEL_EXPORTER_OTLP_ENDPOINT="http://jaeger:4318"
export OTEL_SERVICE_NAME="build-counter"
export OTEL_SERVICE_VERSION="1.0.0"

# For insecure connections
export OTEL_EXPORTER_OTLP_INSECURE="true"

🛠️ Development

Building

# Build binary
make build

# Run tests
make test

# Run with hot reload
make run

# Build Docker image
make image

Code Quality

# Install development dependencies
make dev-deps

# Run linting
make lint

# Format code
make fmt

# Security scan
make sec

Pre-commit Setup

# Install pre-commit
pip install pre-commit

# Install hooks
pre-commit install

# Run manually
pre-commit run --all-files

📊 Metrics

The /metrics endpoint provides Prometheus-compatible metrics:

🐳 Kubernetes Deployment

# Add Helm repository
helm repo add build-counter https://rossigee.github.io/build-counter
helm repo update

# Install with database mode (default)
helm install my-build-counter build-counter/build-counter \
  --set storage.database.url="postgres://user:pass@host:5432/db"

# Install with lightweight mode
helm install my-build-counter build-counter/build-counter \
  --set storage.mode=lightweight

# Install from GitHub Container Registry (OCI)
helm install my-build-counter oci://ghcr.io/rossigee/helm/build-counter \
  --version 1.0.0

See the Helm chart documentation for all configuration options.

Manual Deployment

Database Mode

apiVersion: apps/v1
kind: Deployment
metadata:
  name: build-counter
spec:
  replicas: 2
  selector:
    matchLabels:
      app: build-counter
  template:
    metadata:
      labels:
        app: build-counter
    spec:
      containers:
      - name: build-counter
        image: ghcr.io/rossigee/build-counter:latest
        ports:
        - containerPort: 8080
        env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: build-counter-secret
              key: database-url
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8080

Lightweight Mode (ConfigMap)

apiVersion: v1
kind: ServiceAccount
metadata:
  name: build-counter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: build-counter
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "list", "create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: build-counter
subjects:
- kind: ServiceAccount
  name: build-counter
roleRef:
  kind: Role
  name: build-counter
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: build-counter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: build-counter
  template:
    metadata:
      labels:
        app: build-counter
    spec:
      serviceAccountName: build-counter
      containers:
      - name: build-counter
        image: ghcr.io/rossigee/build-counter:latest
        args: ["--lightweight"]
        ports:
        - containerPort: 8080
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (make test)
  5. Run linting (make lint)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

📋 Roadmap

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments