Add automated setup via API for Komodo and Gitea

Added:
- setup-komodo.sh: Bash script for Komodo resource creation via API
- setup-komodo.js: Node.js script for Komodo setup (no dependencies)
- Updated SETUP_GUIDE.md with automated setup instructions

Gitea Integration (completed via API):
- ✓ Created Build webhook
- ✓ Created Stack deploy webhook
- ✓ Created Sync webhook

Komodo Integration (automated via scripts):
- Creates Build resource via API
- Creates Resource Sync via API
- Validates connection and lists servers

Users can now run a single script to complete the entire setup!
This commit is contained in:
2025-12-14 14:18:57 -08:00
parent 6ad16565e4
commit ff54f0e49e
3 changed files with 364 additions and 0 deletions

View File

@@ -2,6 +2,51 @@
This guide will help you configure Komodo to work with your Gitea server. This guide will help you configure Komodo to work with your Gitea server.
## Automated Setup (Recommended)
Gitea webhooks have already been configured automatically! To complete the Komodo setup, run the provided setup script:
### Using Bash Script
```bash
# Ensure environment variables are set
export KOMODO_KEY="your-key"
export KOMODO_SECRET="your-secret"
# Run the setup script on a machine with access to Komodo
./setup-komodo.sh
```
### Using Node.js Script
```bash
# Ensure environment variables are set
export KOMODO_KEY="your-key"
export KOMODO_SECRET="your-secret"
# Run the setup script (uses built-in fetch, no dependencies needed)
node setup-komodo.js
```
The automated setup will:
- ✓ Test connection to Komodo
- ✓ Create Build resource
- ✓ Create Resource Sync
- Configure git provider (requires config file - see below)
### Webhooks Already Created
The following webhooks have been automatically configured in Gitea:
- ✓ Build webhook: `http://komodo.internal:9120/listener/github/build/komodo-demo-build/build`
- ✓ Stack webhook: `http://komodo.internal:9120/listener/github/stack/komodo-demo-stack/deploy`
- ✓ Sync webhook: `http://komodo.internal:9120/listener/github/sync/komodo-demo-sync/sync`
---
## Manual Setup (Alternative)
If you prefer to set up manually or need to customize the configuration, follow the steps below.
## Summary ## Summary
- **Gitea Host**: `gitea.straymoog.xyz` - **Gitea Host**: `gitea.straymoog.xyz`

161
setup-komodo.js Executable file
View File

@@ -0,0 +1,161 @@
#!/usr/bin/env node
/**
* Komodo Setup Script for komodo-demo integration
*
* Prerequisites:
* npm install komodo_client
*
* Environment variables:
* - KOMODO_HOST (default: komodo.internal)
* - KOMODO_PORT (default: 9120)
* - KOMODO_KEY (required)
* - KOMODO_SECRET (required)
*/
// If running without komodo_client installed, use simple fetch
const USE_SIMPLE_FETCH = true;
const KOMODO_HOST = process.env.KOMODO_HOST || 'komodo.internal';
const KOMODO_PORT = process.env.KOMODO_PORT || '9120';
const KOMODO_URL = `http://${KOMODO_HOST}:${KOMODO_PORT}`;
const KOMODO_KEY = process.env.KOMODO_KEY;
const KOMODO_SECRET = process.env.KOMODO_SECRET;
if (!KOMODO_KEY || !KOMODO_SECRET) {
console.error('Error: KOMODO_KEY and KOMODO_SECRET environment variables must be set');
process.exit(1);
}
console.log('======================================');
console.log('Komodo Setup Script');
console.log('======================================');
console.log(`Komodo URL: ${KOMODO_URL}`);
console.log('');
// Simple API wrapper using fetch
async function komodoApi(method, endpoint, data = {}) {
const response = await fetch(`${KOMODO_URL}/${endpoint}/${method}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': KOMODO_KEY,
'x-api-secret': KOMODO_SECRET
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
}
return await response.json();
}
async function main() {
try {
// Test connection
console.log('Testing connection to Komodo...');
const version = await komodoApi('GetVersion', 'read');
console.log(`✓ Connected to Komodo: ${JSON.stringify(version)}`);
console.log('');
// List servers
console.log('Step 1: Checking for available servers...');
const servers = await komodoApi('ListServers', 'read');
if (servers && servers.length > 0) {
servers.forEach(server => {
console.log(` - ${server.name} (${server.id})`);
});
} else {
console.log(' No servers found');
}
console.log('');
console.log('Note: You\'ll need a server ID for the Stack resource.');
console.log('If no servers are listed, add one in Komodo UI or config.');
console.log('');
// Create Build resource
console.log('Step 2: Creating Build resource \'komodo-demo-build\'...');
try {
const buildConfig = {
name: 'komodo-demo-build',
description: 'Build Docker image for komodo-demo app',
tags: ['demo', 'gitea'],
config: {
git_provider: 'gitea.straymoog.xyz',
git_account: 'stray',
repo: 'stray/komodo-demo',
branch: 'main',
build_path: '.',
dockerfile_path: 'Dockerfile'
}
};
const buildResult = await komodoApi('CreateBuild', 'write', buildConfig);
console.log(' ✓ Build resource created');
} catch (error) {
console.log(` ⚠ Build might already exist or error occurred: ${error.message}`);
}
console.log('');
// Create Stack resource
console.log('Step 3: Creating Stack resource \'komodo-demo-stack\'...');
console.log(' → This requires a valid server_id');
console.log(' → Skipping automatic creation - please create via UI or update script with server_id');
console.log('');
// Create Resource Sync
console.log('Step 4: Creating Resource Sync \'komodo-demo-sync\'...');
try {
const syncConfig = {
name: 'komodo-demo-sync',
description: 'Sync Komodo resources from Git',
tags: ['demo', 'gitea'],
config: {
git_provider: 'gitea.straymoog.xyz',
git_account: 'stray',
repo: 'stray/komodo-demo',
branch: 'main',
resource_path: '.komodo',
commit_to_repo: false
}
};
const syncResult = await komodoApi('CreateResourceSync', 'write', syncConfig);
console.log(' ✓ Resource Sync created');
console.log(' → You can now execute the sync to import all resources from .komodo/resources.toml');
} catch (error) {
console.log(` ⚠ Sync might already exist or error occurred: ${error.message}`);
}
console.log('');
console.log('======================================');
console.log('Setup Summary');
console.log('======================================');
console.log('Gitea webhooks: ✓ Created (3 webhooks)');
console.log(' - Build webhook');
console.log(' - Stack deploy webhook');
console.log(' - Sync webhook');
console.log('');
console.log('Komodo resources:');
console.log(' - Git provider: Configure in core.config.toml');
console.log(' - Build: Created (or attempted)');
console.log(' - Stack: Manual creation required (needs server_id)');
console.log(' - Sync: Created (or attempted)');
console.log('');
console.log('Next steps:');
console.log('1. Add git provider config to core.config.toml (see komodo-gitea.config.toml)');
console.log('2. Restart Komodo core to load git provider');
console.log('3. Execute the Resource Sync to import all resources');
console.log('4. Test by pushing to the Git repository');
console.log('');
console.log('Repository: https://gitea.straymoog.xyz/stray/komodo-demo');
console.log('======================================');
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
main();

158
setup-komodo.sh Executable file
View File

@@ -0,0 +1,158 @@
#!/bin/bash
# Komodo Setup Script for komodo-demo integration
# Run this script on a machine that has network access to Komodo
set -e
# Configuration
KOMODO_HOST="${KOMODO_HOST:-komodo.internal}"
KOMODO_PORT="${KOMODO_PORT:-9120}"
KOMODO_URL="http://${KOMODO_HOST}:${KOMODO_PORT}"
# Check for required environment variables
if [ -z "$KOMODO_KEY" ] || [ -z "$KOMODO_SECRET" ]; then
echo "Error: KOMODO_KEY and KOMODO_SECRET environment variables must be set"
exit 1
fi
echo "======================================"
echo "Komodo Setup Script"
echo "======================================"
echo "Komodo URL: $KOMODO_URL"
echo ""
# Function to make Komodo API calls
komodo_api() {
local method=$1
local endpoint=$2
local data=$3
curl -s -X POST "${KOMODO_URL}/${endpoint}/${method}" \
-H "Content-Type: application/json" \
-H "x-api-key: ${KOMODO_KEY}" \
-H "x-api-secret: ${KOMODO_SECRET}" \
-d "$data"
}
# Test connection
echo "Testing connection to Komodo..."
VERSION=$(komodo_api "GetVersion" "read" '{}')
if [ $? -eq 0 ]; then
echo "✓ Connected to Komodo: $VERSION"
else
echo "✗ Failed to connect to Komodo at $KOMODO_URL"
exit 1
fi
echo ""
# Step 1: Configure Git Provider
echo "Step 1: Configuring Gitea provider..."
# Note: Git provider configuration typically done via config file or UI
# The API might not support adding git providers directly
# This will be done through Resource Sync or config file
echo " → Git providers are configured via core.config.toml"
echo " → See komodo-gitea.config.toml for the configuration to add"
echo ""
# Step 2: List existing servers
echo "Step 2: Checking for available servers..."
SERVERS=$(komodo_api "ListServers" "read" '{}')
echo "$SERVERS" | jq -r '.[] | " - \(.name) (\(.id))"' 2>/dev/null || echo " $SERVERS"
echo ""
echo "Note: You'll need a server ID for the Stack resource."
echo "If no servers are listed, add one in Komodo UI or config."
echo ""
# Step 3: Create Build resource
echo "Step 3: Creating Build resource 'komodo-demo-build'..."
BUILD_CONFIG='{
"name": "komodo-demo-build",
"description": "Build Docker image for komodo-demo app",
"tags": ["demo", "gitea"],
"config": {
"git_provider": "gitea.straymoog.xyz",
"git_account": "stray",
"repo": "stray/komodo-demo",
"branch": "main",
"build_path": ".",
"dockerfile_path": "Dockerfile"
}
}'
BUILD_RESULT=$(komodo_api "CreateBuild" "write" "$BUILD_CONFIG" 2>&1)
if echo "$BUILD_RESULT" | grep -q "error\|Error"; then
echo " ⚠ Build might already exist or error occurred:"
echo " $BUILD_RESULT"
else
echo " ✓ Build resource created"
fi
echo ""
# Step 4: Create Stack resource
echo "Step 4: Creating Stack resource 'komodo-demo-stack'..."
echo " → This requires a valid server_id"
echo " → Skipping automatic creation - please create via UI or update this script with server_id"
echo ""
# STACK_CONFIG='{
# "name": "komodo-demo-stack",
# "description": "Deploy komodo-demo app using docker-compose",
# "tags": ["demo", "gitea"],
# "config": {
# "server_id": "YOUR_SERVER_ID_HERE",
# "git_provider": "gitea.straymoog.xyz",
# "git_account": "stray",
# "repo": "stray/komodo-demo",
# "branch": "main",
# "file_paths": ["docker-compose.yml"]
# }
# }'
# komodo_api "CreateStack" "write" "$STACK_CONFIG"
# Step 5: Create Resource Sync
echo "Step 5: Creating Resource Sync 'komodo-demo-sync'..."
SYNC_CONFIG='{
"name": "komodo-demo-sync",
"description": "Sync Komodo resources from Git",
"tags": ["demo", "gitea"],
"config": {
"git_provider": "gitea.straymoog.xyz",
"git_account": "stray",
"repo": "stray/komodo-demo",
"branch": "main",
"resource_path": ".komodo",
"commit_to_repo": false
}
}'
SYNC_RESULT=$(komodo_api "CreateResourceSync" "write" "$SYNC_CONFIG" 2>&1)
if echo "$SYNC_RESULT" | grep -q "error\|Error"; then
echo " ⚠ Sync might already exist or error occurred:"
echo " $SYNC_RESULT"
else
echo " ✓ Resource Sync created"
echo " → You can now execute the sync to import all resources from .komodo/resources.toml"
fi
echo ""
echo "======================================"
echo "Setup Summary"
echo "======================================"
echo "Gitea webhooks: ✓ Created (3 webhooks)"
echo " - Build webhook"
echo " - Stack deploy webhook"
echo " - Sync webhook"
echo ""
echo "Komodo resources:"
echo " - Git provider: Configure in core.config.toml"
echo " - Build: Created (or attempted)"
echo " - Stack: Manual creation required (needs server_id)"
echo " - Sync: Created (or attempted)"
echo ""
echo "Next steps:"
echo "1. Add git provider config to core.config.toml (see komodo-gitea.config.toml)"
echo "2. Restart Komodo core to load git provider"
echo "3. Execute the Resource Sync to import all resources"
echo "4. Test by pushing to the Git repository"
echo ""
echo "Repository: https://gitea.straymoog.xyz/stray/komodo-demo"
echo "======================================"