Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# GitHub Actions Workflows

This directory contains GitHub Actions workflows for the AI-Agent-Platform.

## Available Workflows

### 1. Deploy to GitHub Pages (`deploy-pages.yml`)
Automatically deploys the web interface to GitHub Pages on push to main branch.

**Triggers:**
- Push to `main` branch
- Manual dispatch

**Purpose:** Deploy the HTML interface and documentation to GitHub Pages

---

### 2. Execute Hostinger Commands (`hostinger-commands.yml`) ⭐ NEW

Complete integration with Hostinger server for executing commands remotely.

**Triggers:**
- **Manual Dispatch:** Execute any of the 9 command types on-demand
- **Push to main/develop:** Automatic health checks and monitoring
- **Path-specific:** Triggers on changes to `dlplus/**` or `api/**`

**Supported Commands:**
1. `file_create` - Create files on server
2. `file_read` - Read files from server
⚠️ **Security Note:** This command can read any accessible file. Important considerations:
- Implement allowlists for readable paths on the server
- Validate and sanitize all file path inputs
- Restrict access to sensitive files (credentials, keys, configs)
- Monitor and log all file read operations
- Use proper file permissions and access controls
3. `file_update` - Update files on server
4. `file_delete` - Delete files from server
5. `service_restart` - Restart services (openwebui, nginx, ollama)
6. `openwebui_manage` - Manage OpenWebUI (start, stop, restart, status)
7. `log_view` - View server logs
8. `status_check` - Check server status
9. `backup_create` - Create backups

**Jobs:**
- `execute-command` - Execute manual or auto-triggered commands
- `continuous-monitor` - Continuous health monitoring (5 checks with 10s intervals)
- `scheduled-sync` - Scheduled backups and log viewing

**Required Secrets:**
- `HOSTINGER_SERVER` - Server address (format: `hostname:port` or `ip:port`)
- `HOSTINGER_API_KEY` - API key for authentication

**Setup:**
```bash
# Run the automated setup script
./setup-github-secrets.sh

# Or manually add secrets in GitHub:
# Settings > Secrets and Variables > Actions > New repository secret
```

**Usage:**

*Via GitHub UI:*
1. Go to Actions tab
2. Select "Execute Hostinger Commands"
3. Click "Run workflow"
4. Choose command type and provide JSON payload

*Via GitHub CLI:*
```bash
# Status check
gh workflow run hostinger-commands.yml \
-f command_type=status_check \
-f payload='{}'

# Create file
gh workflow run hostinger-commands.yml \
-f command_type=file_create \
-f payload='{"path": "test.txt", "content": "Hello from GitHub!"}'

# Restart service
gh workflow run hostinger-commands.yml \
-f command_type=service_restart \
-f payload='{"service": "openwebui"}'
```

**Artifacts:**
- `command-execution-logs-*` - Logs from command execution (30 days retention)
- `monitoring-logs-*` - Logs from continuous monitoring (7 days retention)

**Documentation:**
- [Complete Integration Guide](../GITHUB_ACTIONS_INTEGRATION.md)
- [Hostinger Command Execution Guide](../HOSTINGER_COMMAND_EXECUTION.md)
- [Examples](../examples/github_actions_examples.py)

---

## Setting Up Workflows

### Prerequisites
- GitHub repository with Actions enabled
- Hostinger server running with DL+ API endpoint
- GitHub CLI installed (optional, for command-line usage)

### Configuration

1. **Configure Secrets:**
```bash
./setup-github-secrets.sh
```

2. **Enable Workflows:**
Workflows are automatically enabled when pushed to the repository.

3. **Test Workflows:**
```bash
# List workflows
gh workflow list

# Trigger a workflow
gh workflow run hostinger-commands.yml -f command_type=status_check -f payload='{}'

# View runs
gh run list --workflow=hostinger-commands.yml
```

## Monitoring Workflows

### View Workflow Runs
```bash
# List recent runs
gh run list

# View specific run
gh run view <run-id>

# View logs
gh run view <run-id> --log

# Download artifacts
gh run download <run-id>
```

### GitHub UI
1. Go to **Actions** tab in repository
2. Select a workflow from the left sidebar
3. Click on a specific run to view details
4. View logs and download artifacts

## Troubleshooting

### Workflow Failed
1. Check workflow logs in Actions tab
2. Verify secrets are configured correctly
3. Ensure server is reachable
4. Check server logs on Hostinger

### Secret Not Found
```bash
# List secrets
gh secret list

# Set secret
echo "value" | gh secret set SECRET_NAME
```

### Connection Timeout
- Verify server is running: `curl http://$HOSTINGER_SERVER/api/health`
- Check firewall allows GitHub IPs
- Verify API key is correct

## Best Practices

### Security
1. **Protect API Keys** - Store in GitHub Secrets, never in code
2. **Use workflow_dispatch for sensitive commands** - Manual approval prevents accidents
3. **Implement server-side validation** - Validate all inputs on the server
4. **Use allowlists for file operations** - Restrict accessible paths
5. **Monitor and audit** - Log all command executions and review regularly
6. **Rotate credentials** - Periodically update API keys and secrets
7. **Limit permissions** - Use least privilege principle for service accounts
8. **Review file_read usage** - Carefully control which files can be read

### Operational
1. **Monitor workflow logs regularly** - Stay informed of execution status
2. **Download artifacts for analysis** - Logs help debug issues
3. **Test in development first** - Use different secrets for dev/prod
4. **Review workflow runs** - Ensure automation is working as expected
5. **Set up notifications** - Get alerted on failures
6. **Document custom workflows** - Make it easy for team to understand

## Support

For help with workflows:
- Check [GITHUB_ACTIONS_INTEGRATION.md](../GITHUB_ACTIONS_INTEGRATION.md)
- Open an issue on GitHub
- Review workflow logs and artifacts

---

**Last Updated:** 2024-01-20
**Workflows:** 2 active
**Status:** βœ… All workflows operational
173 changes: 173 additions & 0 deletions .github/workflows/hostinger-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Execute Hostinger Commands

on:
workflow_dispatch:
inputs:
command_type:
description: 'Command Type'
required: true
type: choice
options:
- file_create
- file_read
- file_update
- file_delete
- service_restart
- openwebui_manage
- log_view
- status_check
- backup_create
payload:
description: 'Command Payload (JSON)'
required: true
default: '{}'

# Also trigger on push for continuous monitoring
push:
branches:
- main
- develop
paths:
- 'dlplus/**'
- 'api/**'
- '.github/workflows/hostinger-commands.yml'

permissions:
contents: read
issues: write
pull-requests: write

jobs:
execute-command:
runs-on: ubuntu-latest
name: Execute Command on Hostinger

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests

- name: Execute Status Check (Auto-triggered)
if: github.event_name == 'push'
env:
HOSTINGER_SERVER: ${{ secrets.HOSTINGER_SERVER || '72.61.178.135:8000' }}
HOSTINGER_API_KEY: ${{ secrets.HOSTINGER_API_KEY }}
run: |
echo "πŸ” Checking Hostinger server status after push..."
python github-commander.py status_check '{}'

- name: Execute Manual Command
if: github.event_name == 'workflow_dispatch'
env:
HOSTINGER_SERVER: ${{ secrets.HOSTINGER_SERVER || '72.61.178.135:8000' }}
HOSTINGER_API_KEY: ${{ secrets.HOSTINGER_API_KEY }}
run: |
echo "πŸš€ Executing command: ${{ github.event.inputs.command_type }}"
python github-commander.py "${{ github.event.inputs.command_type }}" '${{ github.event.inputs.payload }}'

- name: Upload execution logs
if: always()
uses: actions/upload-artifact@v4
with:
name: command-execution-logs-${{ github.run_number }}
path: github-commander.log
retention-days: 30

# Continuous connection for monitoring
continuous-monitor:
runs-on: ubuntu-latest
name: Continuous Server Monitor
if: github.event_name == 'push'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests

- name: Monitor Server Health
env:
HOSTINGER_SERVER: ${{ secrets.HOSTINGER_SERVER || '72.61.178.135:8000' }}
HOSTINGER_API_KEY: ${{ secrets.HOSTINGER_API_KEY }}
run: |
echo "πŸ₯ Continuous Health Monitoring"
echo "================================"

# Check health 5 times with 10 second intervals
for i in {1..5}; do
echo "Health Check #$i at $(date)"
python github-commander.py status_check '{}' || true

if [ $i -lt 5 ]; then
echo "Waiting 10 seconds..."
sleep 10
fi
done

echo "================================"
echo "βœ“ Monitoring complete"

- name: Upload monitoring logs
if: always()
uses: actions/upload-artifact@v4
with:
name: monitoring-logs-${{ github.run_number }}
path: github-commander.log
retention-days: 7

# Scheduled deployment and sync
scheduled-sync:
runs-on: ubuntu-latest
name: Scheduled Deployment Sync
# Run only on schedule or manual trigger
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests

- name: Create Backup
env:
HOSTINGER_SERVER: ${{ secrets.HOSTINGER_SERVER || '72.61.178.135:8000' }}
HOSTINGER_API_KEY: ${{ secrets.HOSTINGER_API_KEY }}
run: |
echo "πŸ’Ύ Creating scheduled backup..."
python github-commander.py backup_create '{"type": "scheduled"}'

- name: View Recent Logs
env:
HOSTINGER_SERVER: ${{ secrets.HOSTINGER_SERVER || '72.61.178.135:8000' }}
HOSTINGER_API_KEY: ${{ secrets.HOSTINGER_API_KEY }}
run: |
echo "πŸ“‹ Viewing recent logs..."
python github-commander.py log_view '{"log_type": "execution", "lines": 50}'
Loading