Files
2025-10-17 08:52:12 -04:00

284 lines
8.4 KiB
Markdown

# Deploy CleverMicro Action
This Forgejo action deploys CleverMicro to a Kubernetes cluster using Kind (Kubernetes in Docker). It sets up a complete CleverMicro environment with all necessary components including KEDA for autoscaling.
## Description
The action performs the following steps:
1. Creates a Kubernetes cluster using Kind with custom networking configuration
2. Adds required Helm chart repositories (KEDA and CleverThis)
3. Installs KEDA for Kubernetes-based Event Driven Autoscaling
4. Deploys CleverMicro using the Helm chart with specified image tags
5. Creates additional Kubernetes resources for testing
6. Waits for all pods to be ready
## Inputs
| Input | Description | Required | Example |
| ------------------------ | ---------------------------------------- | -------- | ---------------------------------- |
| `registry-url` | Registry URL for pulling Docker images | ✅ | `git.cleverthis.com` |
| `registry-user` | Username for registry authentication | ✅ | `deployment-user` |
| `registry-password` | Password for registry authentication | ✅ | `${{ secrets.REGISTRY_PASSWORD }}` |
| `amqp-router-tag` | Docker image tag for AMQP Router | ✅ | `v1.0.0` |
| `management-service-tag` | Docker image tag for Management Service | ✅ | `v1.0.0` |
| `client-lib-demo-tag` | Docker image tag for Client Library Demo | ✅ | `v1.0.0` |
## Usage
### Basic Usage
```yaml
name: Deploy CleverMicro
on:
push:
branches: [master]
jobs:
deploy:
runs-on: docker
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy CleverMicro
uses: https://git.cleverthis.com/actions/clevermicro@master
with:
registry-url: git.cleverthis.com
registry-user: ${{ secrets.REGISTRY_USER }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
amqp-router-tag: v1.2.3
management-service-tag: v1.2.3
client-lib-demo-tag: v1.2.3
```
### Advanced Usage with Environment Variables
```yaml
name: Deploy CleverMicro with Dynamic Tags
on:
workflow_dispatch:
inputs:
environment:
description: "Deployment environment"
required: true
default: "staging"
type: choice
options:
- staging
- production
jobs:
deploy:
runs-on: docker
environment: ${{ forge.event.inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set image tags based on environment
id: tags
run: |
if [ "${{ forge.event.inputs.environment }}" == "production" ]; then
echo "tag=latest" >> $FORGEJO_OUTPUT
else
echo "tag=develop" >> $FORGEJO_OUTPUT
fi
- name: Deploy CleverMicro
uses: https://git.cleverthis.com/actions/clevermicro@master
with:
registry-url: ${{ secrets.REGISTRY_URL }}
registry-user: ${{ secrets.REGISTRY_USER }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
amqp-router-tag: ${{ steps.tags.outputs.tag }}
management-service-tag: ${{ steps.tags.outputs.tag }}
client-lib-demo-tag: ${{ steps.tags.outputs.tag }}
```
## Prerequisites
- Docker must be available on the runner
- kubectl must be available on the runner
- Helm must be available on the runner
- Access to the CleverThis registry and Helm repositories
## Components Deployed
### Core CleverMicro Components
- **AMQP Router**: Message routing service
- **Management Service**: CleverMicro management interface
- **Client Library Demo**: Demonstration client application
### Supporting Infrastructure
- **KEDA**: Kubernetes Event-driven Autoscaling
- **RabbitMQ**: Message broker (part of CleverMicro deployment)
- **Additional Services**: NodePort services for external access
## Network Configuration
The Kind cluster is configured with the following port mappings:
| Service | Container Port | Host Port | Description |
| ------------------- | -------------- | --------- | -------------------- |
| AMQP Router HTTP | 30080 | 30080 | HTTP API endpoint |
| Management Service | 8001 | 8001 | Management interface |
| RabbitMQ AMQP | 5672 | 5672 | Message broker |
| RabbitMQ Management | 15672 | 15672 | RabbitMQ web UI |
| PostgreSQL | 5432 | 5432 | Database |
| Consul | 8500 | 8500 | Service discovery |
| Jaeger | 16686 | 16686 | Distributed tracing |
## Accessing Services
After deployment, you can access the services at:
- **CleverMicro AMQP Router**: http://localhost:30080
- **RabbitMQ Management UI**: http://localhost:30672
- **Management Service**: http://localhost:8001
- **Jaeger UI**: http://localhost:16686
- **Consul UI**: http://localhost:8500
## Troubleshooting
### Common Issues
1. **Registry Authentication Failure**
```
Error: failed to authorize: failed to fetch anonymous token
```
- Ensure `registry-user` and `registry-password` are correct
- Verify the registry URL is accessible
2. **Helm Repository Access**
```
Error: failed to fetch https://git.cleverthis.com/api/packages/infra/helm
```
- Check network connectivity to the registry
- Verify credentials have access to Helm repositories
3. **Pod Startup Timeout**
```
Error: timed out waiting for the condition
```
- Check if images are available and accessible
- Verify resource limits and node capacity
- Use `kubectl logs` to check pod logs
### Debugging Commands
```bash
# Check cluster status
kubectl cluster-info
# Check pod status
kubectl -n clevermicro get pods
# Check pod logs
kubectl -n clevermicro logs <pod-name>
# Check services
kubectl -n clevermicro get svc
# Check KEDA installation
kubectl -n keda get pods
```
## File Structure
```
.
├── action.yaml # Main action definition
├── README.md # This documentation
├── clevermicro-kind-config.yaml # Kind cluster configuration
└── service.yaml # Additional Kubernetes services
```
## Dependencies
This action depends on:
- [kubernetes action](https://git.cleverthis.com/actions/kubernetes@master) for Kind cluster setup
- KEDA Helm chart from kedacore/keda
- CleverMicro Helm chart from cleverthis/clevermicro-deployment
## Additional Examples
### CI/CD Pipeline with Testing
```yaml
name: CleverMicro CI/CD Pipeline
on:
push:
branches: [master, develop]
pull_request:
branches: [master]
jobs:
test:
runs-on: docker
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run unit tests
run: |
# Add your test commands here
echo "Running tests..."
deploy-staging:
needs: test
if: forge.ref == 'refs/heads/develop'
runs-on: docker
environment: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Staging
uses: https://git.cleverthis.com/actions/clevermicro@master
with:
registry-url: ${{ secrets.REGISTRY_URL }}
registry-user: ${{ secrets.REGISTRY_USER }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
amqp-router-tag: develop
management-service-tag: develop
client-lib-demo-tag: develop
deploy-production:
needs: test
if: forge.ref == 'refs/heads/master'
runs-on: docker
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Production
uses: https://git.cleverthis.com/actions/clevermicro@master
with:
registry-url: ${{ secrets.REGISTRY_URL }}
registry-user: ${{ secrets.REGISTRY_USER }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
amqp-router-tag: latest
management-service-tag: latest
client-lib-demo-tag: latest
```
## Contributing
When contributing to this action:
1. Test changes in a development environment
2. Update documentation for any new inputs or behavior changes
3. Ensure backward compatibility or provide migration notes
4. Update version tags appropriately