document.addEventListener('DOMContentLoaded', function() {
// Get the launch data from sessionStorage
const launchData = JSON.parse(sessionStorage.getItem('instanceLaunchData'));
if (!launchData) {
showError('No launch data found. Please start over.');
return;
}
// Initialize the steps
initializeSteps();
// Start the launch process
startLaunch(launchData);
});
function initializeSteps() {
const stepsContainer = document.getElementById('stepsContainer');
// Add DNS check step
const dnsStep = document.createElement('div');
dnsStep.className = 'step-item';
dnsStep.innerHTML = `
Checking DNS Records
Verifying domain configurations...
`;
stepsContainer.appendChild(dnsStep);
// Add NGINX connection check step
const nginxStep = document.createElement('div');
nginxStep.className = 'step-item';
nginxStep.innerHTML = `
Checking NGINX Connection
Verifying connection to NGINX Proxy Manager...
`;
stepsContainer.appendChild(nginxStep);
// Add SSL Certificate generation step
const sslStep = document.createElement('div');
sslStep.className = 'step-item';
sslStep.innerHTML = `
Generating SSL Certificate
Setting up secure HTTPS connection...
`;
stepsContainer.appendChild(sslStep);
// Add Proxy Host creation step
const proxyStep = document.createElement('div');
proxyStep.className = 'step-item';
proxyStep.innerHTML = `
Creating Proxy Host
Setting up NGINX proxy host configuration...
`;
stepsContainer.appendChild(proxyStep);
// Add Portainer connection check step
const portainerStep = document.createElement('div');
portainerStep.className = 'step-item';
portainerStep.innerHTML = `
Checking Portainer Connection
Verifying connection to Portainer...
`;
stepsContainer.appendChild(portainerStep);
// Add Docker Compose download step
const dockerComposeStep = document.createElement('div');
dockerComposeStep.className = 'step-item';
dockerComposeStep.innerHTML = `
Downloading Docker Compose
Fetching docker-compose.yml from repository...
`;
stepsContainer.appendChild(dockerComposeStep);
// Add Portainer stack deployment step
const stackDeployStep = document.createElement('div');
stackDeployStep.className = 'step-item';
stackDeployStep.innerHTML = `
Deploying Stack
Launching your application stack...
`;
stepsContainer.appendChild(stackDeployStep);
// Add Save Instance Data step
const saveDataStep = document.createElement('div');
saveDataStep.className = 'step-item';
saveDataStep.innerHTML = `
Saving Instance Data
Storing instance information...
`;
stepsContainer.appendChild(saveDataStep);
// Add Health Check step
const healthStep = document.createElement('div');
healthStep.className = 'step-item';
healthStep.innerHTML = `
Health Check
Verifying instance health...
`;
stepsContainer.appendChild(healthStep);
}
async function startLaunch(data) {
try {
// Step 1: Check DNS records
await updateStep(1, 'Checking DNS Records', 'Verifying domain configurations...');
const dnsResult = await checkDNSRecords(data.webAddresses);
// Check if any domains failed to resolve
const failedDomains = Object.entries(dnsResult.results)
.filter(([_, result]) => !result.resolved)
.map(([domain]) => domain);
if (failedDomains.length > 0) {
throw new Error(`DNS records not found for: ${failedDomains.join(', ')}`);
}
// Update the step to show success
const dnsStep = document.querySelectorAll('.step-item')[0];
dnsStep.classList.remove('active');
dnsStep.classList.add('completed');
// Create a details section for DNS results
const detailsSection = document.createElement('div');
detailsSection.className = 'mt-3';
detailsSection.innerHTML = `