dockerfile-generator / index.html
Battingchart300's picture
Upload 2 files
cc6a2ce verified
Raw History Blame Contribute Delete
7.12 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dockerfile Generator</title>
<style>
:root { --p: #00f0ff; --bg: #07070c; --panel: #12121c; --line: rgba(255,255,255,.12); }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: #eee; font-family: 'Segoe UI', Arial, sans-serif; padding: 24px; }
.wrap { max-width: 860px; margin: 0 auto; }
h1 { font-size: 26px; margin-bottom: 6px; }
h1 span { color: var(--p); }
p.sub { color: #9aa; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
label { display: block; font-size: 13px; color: #aaa; margin: 12px 0 4px; }
label:first-child { margin-top: 0; }
select, input[type=text], input[type=number] { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: #0a0a12; color: #fff; font-size: 14px; }
.row { display: flex; gap: 12px; }
.row > div { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; }
.check input { width: 18px; height: 18px; }
pre { background: #0a0a12; border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; font-size: 13px; line-height: 1.5; white-space: pre; margin-top: 8px; }
h2 { font-size: 16px; margin-bottom: 4px; }
.btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
button { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #1c1c2a; color: #fff; cursor: pointer; font-size: 14px; }
button.primary { background: var(--p); color: #000; border-color: var(--p); font-weight: 700; }
button:hover { opacity: .85; }
.note { color: #888; font-size: 13px; margin-top: 14px; }
</style>
</head>
<body>
<div class="wrap">
<h1>Dockerfile <span>Generator</span></h1>
<p class="sub">Pick your app type, get a ready Dockerfile + docker-compose.yml. No API key, no server — everything runs in your browser.</p>
<div class="card">
<div class="row">
<div>
<label for="preset">App type</label>
<select id="preset">
<option value="flask">Flask (Python)</option>
<option value="fastapi">FastAPI (Python)</option>
<option value="script">Plain Python script</option>
<option value="node">Node.js</option>
</select>
</div>
<div>
<label for="pyver">Python version</label>
<select id="pyver">
<option value="3.11">3.11</option>
<option value="3.12" selected>3.12</option>
<option value="3.13">3.13</option>
</select>
</div>
</div>
<div class="row">
<div>
<label for="entry">Entry file</label>
<input type="text" id="entry" value="app.py">
</div>
<div>
<label for="port">Port</label>
<input type="number" id="port" value="5000" min="1" max="65535">
</div>
</div>
<label class="check"><input type="checkbox" id="reqs" checked> Install from requirements.txt</label>
<label class="check"><input type="checkbox" id="compose" checked> Also generate docker-compose.yml</label>
</div>
<div class="card">
<h2>Dockerfile</h2>
<pre id="out-dockerfile"></pre>
<div class="btns">
<button class="primary" onclick="copyText('out-dockerfile')">Copy Dockerfile</button>
<button onclick="downloadText('out-dockerfile', 'Dockerfile')">Download Dockerfile</button>
</div>
</div>
<div class="card" id="compose-card">
<h2>docker-compose.yml</h2>
<pre id="out-compose"></pre>
<div class="btns">
<button class="primary" onclick="copyText('out-compose')">Copy compose file</button>
<button onclick="downloadText('out-compose', 'docker-compose.yml')">Download docker-compose.yml</button>
</div>
</div>
<p class="note">Tip: build with <code>docker build -t my-app .</code> and run with <code>docker compose up</code>. Generated files are a starting point — check the port and entry file match your project.</p>
</div>
<script>
function buildDockerfile(o) {
if (o.preset === 'node') {
var lines = ['FROM node:20-slim', 'WORKDIR /app', 'COPY package*.json ./', 'RUN npm install --production', 'COPY . .'];
if (o.port) lines.push('EXPOSE ' + o.port);
lines.push('CMD ["node", "' + o.entry + '"]');
return lines.join('\n');
}
var lines = ['FROM python:' + o.pyver + '-slim', 'WORKDIR /app'];
if (o.reqs) lines.push('COPY requirements.txt .', 'RUN pip install --no-cache-dir -r requirements.txt');
lines.push('COPY . .');
if (o.preset === 'flask' && o.port) lines.push('EXPOSE ' + o.port);
if (o.preset === 'fastapi' && o.port) lines.push('EXPOSE ' + o.port);
if (o.preset === 'flask') lines.push('CMD ["python", "' + o.entry + '"]');
else if (o.preset === 'fastapi') lines.push('CMD ["uvicorn", "' + o.entry.replace(/\.py$/, '') + ':app", "--host", "0.0.0.0", "--port", "' + o.port + '"]');
else lines.push('CMD ["python", "' + o.entry + '"]');
return lines.join('\n');
}
function buildCompose(o) {
if (!o.port) return 'services:\n app:\n build: .\n';
return 'services:\n app:\n build: .\n ports:\n - "' + o.port + ':' + o.port + '"\n';
}
function readOpts() {
var preset = document.getElementById('preset').value;
var pyver = document.getElementById('pyver').value;
var entry = document.getElementById('entry').value.trim() || 'app.py';
var port = document.getElementById('port').value.trim();
if (preset === 'script') port = '';
if (preset === 'fastapi' && !port) port = '8000';
if (preset === 'node' && !port) port = '3000';
return { preset: preset, pyver: pyver, entry: entry, port: port,
reqs: document.getElementById('reqs').checked,
compose: document.getElementById('compose').checked };
}
function generate() {
var o = readOpts();
document.getElementById('out-dockerfile').textContent = buildDockerfile(o);
document.getElementById('compose-card').style.display = o.compose ? 'block' : 'none';
if (o.compose) document.getElementById('out-compose').textContent = buildCompose(o);
var isNode = o.preset === 'node';
document.getElementById('pyver').disabled = isNode;
document.getElementById('reqs').disabled = isNode;
}
function copyText(id) {
var t = document.getElementById(id).textContent;
if (navigator.clipboard) navigator.clipboard.writeText(t);
}
function downloadText(id, name) {
var t = document.getElementById(id).textContent;
var a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([t], { type: 'text/plain' }));
a.download = name; a.click();
}
['preset', 'pyver', 'entry', 'port', 'reqs', 'compose'].forEach(function (id) {
document.getElementById(id).addEventListener('input', generate);
document.getElementById(id).addEventListener('change', generate);
});
generate();
if (typeof module !== 'undefined') { module.exports = { buildDockerfile: buildDockerfile, buildCompose: buildCompose }; }
</script>
</body>
</html>