File size: 7,117 Bytes
cc6a2ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32641af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!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>