download docker compose during launch process
This commit is contained in:
@@ -228,6 +228,18 @@ function initializeSteps() {
|
||||
</div>
|
||||
`;
|
||||
stepsContainer.appendChild(portainerStep);
|
||||
|
||||
// Add Docker Compose download step
|
||||
const dockerComposeStep = document.createElement('div');
|
||||
dockerComposeStep.className = 'step-item';
|
||||
dockerComposeStep.innerHTML = `
|
||||
<div class="step-icon"><i class="fas fa-file-code"></i></div>
|
||||
<div class="step-content">
|
||||
<h5>Downloading Docker Compose</h5>
|
||||
<p class="step-status">Fetching docker-compose.yml from repository...</p>
|
||||
</div>
|
||||
`;
|
||||
stepsContainer.appendChild(dockerComposeStep);
|
||||
}
|
||||
|
||||
async function startLaunch(data) {
|
||||
@@ -336,6 +348,37 @@ async function startLaunch(data) {
|
||||
portainerStep.classList.add('completed');
|
||||
portainerStep.querySelector('.step-status').textContent = 'Successfully connected to Portainer';
|
||||
|
||||
// Step 6: Download Docker Compose
|
||||
await updateStep(6, 'Downloading Docker Compose', 'Fetching docker-compose.yml from repository...');
|
||||
const dockerComposeResult = await downloadDockerCompose(data.repository, data.branch);
|
||||
|
||||
if (!dockerComposeResult.success) {
|
||||
throw new Error(dockerComposeResult.error || 'Failed to download docker-compose.yml');
|
||||
}
|
||||
|
||||
// Update the step to show success
|
||||
const dockerComposeStep = document.querySelectorAll('.step-item')[5];
|
||||
dockerComposeStep.classList.remove('active');
|
||||
dockerComposeStep.classList.add('completed');
|
||||
dockerComposeStep.querySelector('.step-status').textContent = 'Successfully downloaded docker-compose.yml';
|
||||
|
||||
// Add download button
|
||||
const downloadButton = document.createElement('button');
|
||||
downloadButton.className = 'btn btn-sm btn-primary mt-2';
|
||||
downloadButton.innerHTML = '<i class="fas fa-download me-1"></i> Download docker-compose.yml';
|
||||
downloadButton.onclick = () => {
|
||||
const blob = new Blob([dockerComposeResult.content], { type: 'text/yaml' });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'docker-compose.yml';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
};
|
||||
dockerComposeStep.querySelector('.step-content').appendChild(downloadButton);
|
||||
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
}
|
||||
@@ -962,5 +1005,39 @@ function retryLaunch() {
|
||||
// Reload the page to start over
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
// Add new function to download docker-compose.yml
|
||||
async function downloadDockerCompose(repo, branch) {
|
||||
try {
|
||||
const response = await fetch('/api/admin/download-docker-compose', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
repository: repo,
|
||||
branch: branch
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || 'Failed to download docker-compose.yml');
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
return {
|
||||
success: true,
|
||||
content: result.content
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error downloading docker-compose.yml:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user