52 lines
2.1 KiB
HTML
52 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Docker Compose to .env Converter</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
</head>
|
|
<body class="bg-gray-100 min-h-screen flex flex-col items-center py-10">
|
|
<div class="w-full max-w-2xl bg-white rounded-lg shadow-md p-6">
|
|
<h1 class="text-2xl font-bold text-gray-800 mb-4">Docker Compose to .env Converter</h1>
|
|
|
|
<textarea id="input" class="w-full h-48 border border-gray-300 rounded-md p-3 focus:ring-2 focus:ring-blue-500 focus:outline-none mb-4" placeholder="Paste your docker-compose.yml snippet here..."></textarea>
|
|
|
|
<button id="convertBtn" class="bg-blue-500 text-white px-4 py-2 rounded-md hover:bg-blue-600 focus:ring-2 focus:ring-blue-500 focus:outline-none">Convert to .env</button>
|
|
|
|
<textarea id="output" class="w-full h-48 border border-gray-300 rounded-md p-3 focus:ring-2 focus:ring-blue-500 focus:outline-none mt-4" placeholder="Converted .env variables will appear here..." readonly></textarea>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('convertBtn').addEventListener('click', () => {
|
|
const input = document.getElementById('input').value;
|
|
const output = document.getElementById('output');
|
|
|
|
try {
|
|
// Extract the environment section from the input
|
|
const environmentRegex = /environment:\n((?:\s+.+:.+\n)+)/;
|
|
const match = input.match(environmentRegex);
|
|
|
|
if (!match) {
|
|
output.value = 'No valid environment variables found!';
|
|
return;
|
|
}
|
|
|
|
const environmentBlock = match[1];
|
|
|
|
// Convert YAML format to .env format
|
|
const lines = environmentBlock.split('\n').filter(line => line.trim() !== '');
|
|
const envVariables = lines.map(line => {
|
|
const [key, value] = line.trim().split(/:\s+/);
|
|
return `${key}=${value.replace(/"/g, '')}`;
|
|
});
|
|
|
|
output.value = envVariables.join('\n');
|
|
} catch (error) {
|
|
output.value = 'Error processing input. Please check your input format.';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|