fix(ci): trigger workflow on main branch to enable :latest tag

Changes:
- Create Gitea workflow for ai-stack-deployer
- Trigger on main branch (default branch)
- Use oussamadouhou + REGISTRY_TOKEN for authentication
- Build from ./Dockerfile

This enables :latest tag creation via {{is_default_branch}}.

Tags created:
- git.app.flexinit.nl/oussamadouhou/ai-stack-deployer:latest
- git.app.flexinit.nl/oussamadouhou/ai-stack-deployer:<sha>

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Oussama Douhou
2026-01-09 23:33:39 +01:00
commit 19845880e3
46 changed files with 9875 additions and 0 deletions

297
src/frontend/app.js Normal file
View File

@@ -0,0 +1,297 @@
// State Machine for Deployment
const STATE = {
FORM: 'form',
PROGRESS: 'progress',
SUCCESS: 'success',
ERROR: 'error'
};
let currentState = STATE.FORM;
let deploymentId = null;
let deploymentUrl = null;
let eventSource = null;
// DOM Elements
const formState = document.getElementById('form-state');
const progressState = document.getElementById('progress-state');
const successState = document.getElementById('success-state');
const errorState = document.getElementById('error-state');
const deployForm = document.getElementById('deploy-form');
const stackNameInput = document.getElementById('stack-name');
const deployBtn = document.getElementById('deploy-btn');
const validationMessage = document.getElementById('validation-message');
const previewName = document.getElementById('preview-name');
const progressBar = document.getElementById('progress-fill');
const progressPercent = document.getElementById('progress-percent');
const deployingName = document.getElementById('deploying-name');
const deployingUrl = document.getElementById('deploying-url');
const progressLog = document.getElementById('progress-log');
const successName = document.getElementById('success-name');
const successUrl = document.getElementById('success-url');
const openStackBtn = document.getElementById('open-stack-btn');
const deployAnotherBtn = document.getElementById('deploy-another-btn');
const errorMessage = document.getElementById('error-message');
const tryAgainBtn = document.getElementById('try-again-btn');
// State Management
function setState(newState) {
currentState = newState;
formState.style.display = 'none';
progressState.style.display = 'none';
successState.style.display = 'none';
errorState.style.display = 'none';
switch (newState) {
case STATE.FORM:
formState.style.display = 'block';
break;
case STATE.PROGRESS:
progressState.style.display = 'block';
break;
case STATE.SUCCESS:
successState.style.display = 'block';
break;
case STATE.ERROR:
errorState.style.display = 'block';
break;
}
}
// Name Validation
function validateName(name) {
if (!name) {
return { valid: false, error: 'Name is required' };
}
const trimmedName = name.trim().toLowerCase();
if (trimmedName.length < 3 || trimmedName.length > 20) {
return { valid: false, error: 'Name must be between 3 and 20 characters' };
}
if (!/^[a-z0-9-]+$/.test(trimmedName)) {
return { valid: false, error: 'Only lowercase letters, numbers, and hyphens allowed' };
}
if (trimmedName.startsWith('-') || trimmedName.endsWith('-')) {
return { valid: false, error: 'Cannot start or end with a hyphen' };
}
const reservedNames = ['admin', 'api', 'www', 'root', 'system', 'test', 'demo', 'portal'];
if (reservedNames.includes(trimmedName)) {
return { valid: false, error: 'This name is reserved' };
}
return { valid: true, name: trimmedName };
}
// Real-time Name Validation
let checkTimeout;
stackNameInput.addEventListener('input', (e) => {
const value = e.target.value.toLowerCase();
e.target.value = value; // Force lowercase
// Update preview
previewName.textContent = value || 'yourname';
// Clear previous timeout
clearTimeout(checkTimeout);
// Validate format first
const validation = validateName(value);
if (!validation.valid) {
stackNameInput.classList.remove('success');
stackNameInput.classList.add('error');
validationMessage.textContent = validation.error;
validationMessage.className = 'validation-message error';
deployBtn.disabled = true;
return;
}
// Check availability with debounce
stackNameInput.classList.remove('error', 'success');
validationMessage.textContent = 'Checking availability...';
validationMessage.className = 'validation-message';
checkTimeout = setTimeout(async () => {
try {
const response = await fetch(`/api/check/${validation.name}`);
const data = await response.json();
if (data.available && data.valid) {
stackNameInput.classList.add('success');
validationMessage.textContent = '✓ Name is available!';
validationMessage.className = 'validation-message success';
deployBtn.disabled = false;
} else {
stackNameInput.classList.add('error');
validationMessage.textContent = data.error || 'Name is not available';
validationMessage.className = 'validation-message error';
deployBtn.disabled = true;
}
} catch (error) {
console.error('Failed to check name availability:', error);
validationMessage.textContent = 'Failed to check availability';
validationMessage.className = 'validation-message error';
deployBtn.disabled = true;
}
}, 500);
});
// Form Submission
deployForm.addEventListener('submit', async (e) => {
e.preventDefault();
const validation = validateName(stackNameInput.value);
if (!validation.valid) {
return;
}
deployBtn.disabled = true;
deployBtn.innerHTML = '<span class="btn-text">Deploying...</span>';
try {
const response = await fetch('/api/deploy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: validation.name
})
});
const data = await response.json();
if (!response.ok || !data.success) {
throw new Error(data.error || 'Deployment failed');
}
deploymentId = data.deploymentId;
deploymentUrl = data.url;
// Update progress UI
deployingName.textContent = validation.name;
deployingUrl.textContent = deploymentUrl;
// Switch to progress state
setState(STATE.PROGRESS);
// Start SSE connection
startProgressStream(deploymentId);
} catch (error) {
console.error('Deployment error:', error);
showError(error.message);
deployBtn.disabled = false;
deployBtn.innerHTML = `
<span class="btn-text">Deploy My AI Stack</span>
<svg class="btn-icon" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M10 4V16M4 10H16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
`;
}
});
// SSE Progress Streaming
function startProgressStream(deploymentId) {
eventSource = new EventSource(`/api/status/${deploymentId}`);
eventSource.addEventListener('progress', (event) => {
const data = JSON.parse(event.data);
updateProgress(data);
});
eventSource.addEventListener('complete', (event) => {
const data = JSON.parse(event.data);
eventSource.close();
showSuccess(data);
});
eventSource.addEventListener('error', (event) => {
const data = event.data ? JSON.parse(event.data) : { message: 'Unknown error' };
eventSource.close();
showError(data.message);
});
eventSource.onerror = () => {
eventSource.close();
showError('Connection lost. Please refresh and try again.');
};
}
// Update Progress UI
function updateProgress(data) {
// Update progress bar
progressBar.style.width = `${data.progress}%`;
progressPercent.textContent = `${data.progress}%`;
// Update current step
const stepContainer = document.querySelector('.progress-steps');
stepContainer.innerHTML = `
<div class="step active">
<div class="step-icon">⚙️</div>
<div class="step-text">${data.currentStep}</div>
</div>
`;
// Add to log
const logEntry = document.createElement('div');
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${data.currentStep}`;
progressLog.appendChild(logEntry);
progressLog.scrollTop = progressLog.scrollHeight;
}
// Show Success
function showSuccess(data) {
successName.textContent = deployingName.textContent;
successUrl.textContent = deploymentUrl;
successUrl.href = deploymentUrl;
openStackBtn.href = deploymentUrl;
setState(STATE.SUCCESS);
}
// Show Error
function showError(message) {
errorMessage.textContent = message;
setState(STATE.ERROR);
}
// Reset to Form
function resetToForm() {
deploymentId = null;
deploymentUrl = null;
stackNameInput.value = '';
previewName.textContent = 'yourname';
validationMessage.textContent = '';
validationMessage.className = 'validation-message';
stackNameInput.classList.remove('error', 'success');
progressLog.innerHTML = '';
progressBar.style.width = '0%';
progressPercent.textContent = '0%';
deployBtn.disabled = false;
deployBtn.innerHTML = `
<span class="btn-text">Deploy My AI Stack</span>
<svg class="btn-icon" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M10 4V16M4 10H16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
`;
setState(STATE.FORM);
}
// Event Listeners
deployAnotherBtn.addEventListener('click', resetToForm);
tryAgainBtn.addEventListener('click', resetToForm);
// Initialize
setState(STATE.FORM);
console.log('AI Stack Deployer initialized');

149
src/frontend/index.html Normal file
View File

@@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Stack Deployer - Deploy Your Personal OpenCode Assistant</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div class="container">
<header class="header">
<div class="logo">
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="40" height="40" rx="8" fill="url(#gradient)"/>
<path d="M12 20L18 26L28 14" stroke="white" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<defs>
<linearGradient id="gradient" x1="0" y1="0" x2="40" y2="40">
<stop offset="0%" stop-color="#667eea"/>
<stop offset="100%" stop-color="#764ba2"/>
</linearGradient>
</defs>
</svg>
<h1>AI Stack Deployer</h1>
</div>
<p class="subtitle">Deploy your personal OpenCode AI coding assistant in seconds</p>
</header>
<main id="app">
<!-- Form State -->
<div id="form-state" class="card">
<h2>Choose Your Stack Name</h2>
<p class="info-text">Your AI assistant will be available at <strong><span id="preview-name">yourname</span>.ai.flexinit.nl</strong></p>
<form id="deploy-form">
<div class="input-group">
<label for="stack-name">Stack Name</label>
<input
type="text"
id="stack-name"
name="name"
placeholder="e.g., john-dev"
pattern="[a-z0-9-]{3,20}"
required
autocomplete="off"
>
<div class="input-hint" id="name-hint">
3-20 characters, lowercase letters, numbers, and hyphens only
</div>
<div class="validation-message" id="validation-message"></div>
</div>
<button type="submit" class="btn btn-primary" id="deploy-btn">
<span class="btn-text">Deploy My AI Stack</span>
<svg class="btn-icon" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M10 4V16M4 10H16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
</button>
</form>
</div>
<!-- Deployment Progress State -->
<div id="progress-state" class="card" style="display: none;">
<div class="progress-header">
<h2>Deploying Your Stack</h2>
<div class="spinner"></div>
</div>
<div class="progress-info">
<p>Stack: <strong id="deploying-name"></strong></p>
<p>URL: <strong id="deploying-url"></strong></p>
</div>
<div class="progress-bar-container">
<div class="progress-bar" id="progress-bar">
<div class="progress-fill" id="progress-fill" style="width: 0%"></div>
</div>
<span class="progress-percent" id="progress-percent">0%</span>
</div>
<div class="progress-steps">
<div class="step" id="step-0">
<div class="step-icon"></div>
<div class="step-text" id="step-text-0">Initializing deployment...</div>
</div>
</div>
<div class="progress-log" id="progress-log"></div>
</div>
<!-- Success State -->
<div id="success-state" class="card success-card" style="display: none;">
<div class="success-icon">
<svg width="80" height="80" viewBox="0 0 80 80" fill="none">
<circle cx="40" cy="40" r="40" fill="#10b981"/>
<path d="M25 40L35 50L55 30" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<h2>Stack Deployed Successfully!</h2>
<p class="success-message">Your AI coding assistant is ready to use</p>
<div class="success-details">
<div class="detail-item">
<span class="detail-label">Stack Name:</span>
<span class="detail-value" id="success-name"></span>
</div>
<div class="detail-item">
<span class="detail-label">URL:</span>
<a href="#" target="_blank" class="detail-link" id="success-url"></a>
</div>
</div>
<div class="success-actions">
<a href="#" target="_blank" class="btn btn-primary" id="open-stack-btn">
Open My AI Stack
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M10 4L16 10L10 16M16 10H4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</a>
<button class="btn btn-secondary" id="deploy-another-btn">
Deploy Another Stack
</button>
</div>
</div>
<!-- Error State -->
<div id="error-state" class="card error-card" style="display: none;">
<div class="error-icon">
<svg width="80" height="80" viewBox="0 0 80 80" fill="none">
<circle cx="40" cy="40" r="40" fill="#ef4444"/>
<path d="M30 30L50 50M50 30L30 50" stroke="white" stroke-width="4" stroke-linecap="round"/>
</svg>
</div>
<h2>Deployment Failed</h2>
<p class="error-message" id="error-message"></p>
<button class="btn btn-secondary" id="try-again-btn">
Try Again
</button>
</div>
</main>
<footer class="footer">
<p>Powered by <a href="https://dokploy.com" target="_blank">Dokploy</a> • OpenCode AI Assistant</p>
</footer>
</div>
<script src="/static/app.js"></script>
</body>
</html>

448
src/frontend/style.css Normal file
View File

@@ -0,0 +1,448 @@
:root {
--primary: #667eea;
--primary-dark: #5568d3;
--secondary: #764ba2;
--success: #10b981;
--error: #ef4444;
--text: #1f2937;
--text-light: #6b7280;
--bg: #f9fafb;
--card-bg: #ffffff;
--border: #e5e7eb;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.container {
max-width: 640px;
margin: 0 auto;
padding: 2rem 1rem;
width: 100%;
}
/* Header */
.header {
text-align: center;
margin-bottom: 3rem;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
margin-bottom: 1rem;
}
.logo h1 {
font-size: 2rem;
font-weight: 700;
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
color: var(--text-light);
font-size: 1.125rem;
}
/* Card */
.card {
background: var(--card-bg);
border-radius: 16px;
padding: 2.5rem;
box-shadow: var(--shadow-lg);
border: 1px solid var(--border);
}
.card h2 {
font-size: 1.5rem;
margin-bottom: 1rem;
color: var(--text);
}
.info-text {
color: var(--text-light);
margin-bottom: 2rem;
font-size: 0.95rem;
}
.info-text strong {
color: var(--primary);
}
/* Form */
.input-group {
margin-bottom: 1.5rem;
}
label {
display: block;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text);
}
input[type="text"] {
width: 100%;
padding: 0.875rem 1rem;
border: 2px solid var(--border);
border-radius: 8px;
font-size: 1rem;
transition: all 0.2s;
font-family: 'Monaco', 'Menlo', monospace;
}
input[type="text"]:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
input[type="text"].error {
border-color: var(--error);
}
input[type="text"].success {
border-color: var(--success);
}
.input-hint {
font-size: 0.875rem;
color: var(--text-light);
margin-top: 0.5rem;
}
.validation-message {
font-size: 0.875rem;
margin-top: 0.5rem;
min-height: 1.25rem;
}
.validation-message.error {
color: var(--error);
}
.validation-message.success {
color: var(--success);
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.875rem 1.5rem;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
text-decoration: none;
width: 100%;
}
.btn-primary {
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-primary:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.btn-secondary {
background: var(--bg);
color: var(--text);
border: 2px solid var(--border);
}
.btn-secondary:hover {
background: white;
border-color: var(--primary);
color: var(--primary);
}
.btn-icon {
width: 20px;
height: 20px;
}
/* Progress */
.progress-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.5rem;
}
.spinner {
width: 24px;
height: 24px;
border: 3px solid var(--border);
border-top-color: var(--primary);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.progress-info {
background: var(--bg);
padding: 1rem;
border-radius: 8px;
margin-bottom: 1.5rem;
}
.progress-info p {
margin-bottom: 0.5rem;
font-size: 0.95rem;
}
.progress-info p:last-child {
margin-bottom: 0;
}
.progress-bar-container {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 2rem;
}
.progress-bar {
flex: 1;
height: 12px;
background: var(--bg);
border-radius: 6px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
transition: width 0.3s ease;
border-radius: 6px;
}
.progress-percent {
font-weight: 600;
color: var(--primary);
min-width: 3rem;
text-align: right;
}
.progress-steps {
display: flex;
flex-direction: column;
gap: 1rem;
}
.step {
display: flex;
align-items: center;
gap: 1rem;
padding: 0.75rem;
background: var(--bg);
border-radius: 8px;
transition: all 0.3s;
}
.step.active {
background: rgba(102, 126, 234, 0.1);
border-left: 3px solid var(--primary);
}
.step-icon {
font-size: 1.5rem;
}
.step-text {
flex: 1;
font-size: 0.95rem;
}
.progress-log {
margin-top: 1.5rem;
padding: 1rem;
background: var(--bg);
border-radius: 8px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 0.875rem;
color: var(--text-light);
max-height: 200px;
overflow-y: auto;
}
.progress-log:empty {
display: none;
}
/* Success */
.success-card {
text-align: center;
}
.success-icon {
margin-bottom: 1.5rem;
animation: scaleIn 0.5s ease;
}
@keyframes scaleIn {
from {
transform: scale(0);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
.success-message {
color: var(--text-light);
margin-bottom: 2rem;
}
.success-details {
background: var(--bg);
padding: 1.5rem;
border-radius: 8px;
margin-bottom: 2rem;
text-align: left;
}
.detail-item {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
font-size: 0.95rem;
}
.detail-item:last-child {
margin-bottom: 0;
}
.detail-label {
color: var(--text-light);
font-weight: 500;
}
.detail-value {
font-weight: 600;
font-family: 'Monaco', 'Menlo', monospace;
}
.detail-link {
color: var(--primary);
text-decoration: none;
font-weight: 600;
font-family: 'Monaco', 'Menlo', monospace;
}
.detail-link:hover {
text-decoration: underline;
}
.success-actions {
display: flex;
flex-direction: column;
gap: 1rem;
}
/* Error */
.error-card {
text-align: center;
}
.error-icon {
margin-bottom: 1.5rem;
animation: shake 0.5s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
.error-message {
color: var(--text-light);
margin-bottom: 2rem;
padding: 1rem;
background: rgba(239, 68, 68, 0.1);
border-radius: 8px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 0.875rem;
}
/* Footer */
.footer {
text-align: center;
margin-top: auto;
padding: 2rem 1rem;
color: var(--text-light);
font-size: 0.875rem;
}
.footer a {
color: var(--primary);
text-decoration: none;
font-weight: 600;
}
.footer a:hover {
text-decoration: underline;
}
/* Responsive */
@media (max-width: 640px) {
.container {
padding: 1rem;
}
.card {
padding: 1.5rem;
}
.logo h1 {
font-size: 1.5rem;
}
.subtitle {
font-size: 1rem;
}
}