docker_deploy.html 15.6 KB
Newer Older
Edward Tang's avatar
Edward Tang committed
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Docker Llama 3.1 8B Deployment</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container { max-width: 900px; }
        .log-container {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            padding: 15px;
            height: 400px;
            overflow-y: auto;
            font-family: monospace;
            margin-top: 20px;
        }
        .deployment-status {
            display: inline-block;
            margin-left: 10px;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 0.9em;
        }
        .status-running {
            background-color: #fff3cd;
            color: #856404;
        }
        .status-success {
            background-color: #d4edda;
            color: #155724;
        }
        .status-error {
            background-color: #f8d7da;
            color: #721c24;
        }
        .status-idle {
            background-color: #e2e3e5;
            color: #383d41;
        }
        .nav-tabs {
            margin-bottom: 20px;
        }
        .nav-link {
            color: #495057;
            font-weight: 500;
        }
        .nav-link.active {
            color: #0d6efd;
            font-weight: 600;
        }
        .form-section {
            margin-bottom: 20px;
            padding: 20px;
            border: 1px solid #dee2e6;
            border-radius: 5px;
        }
        .form-section h3 {
            margin-bottom: 15px;
            color: #0d6efd;
        }
        .button-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .docker-info {
            background-color: #e7f3ff;
            padding: 15px;
            border-radius: 5px;
            border-left: 4px solid #0d6efd;
            margin-bottom: 20px;
        }
        .success-info {
            background-color: #d4edda;
            padding: 20px;
            border-radius: 5px;
            border-left: 4px solid #28a745;
            margin-top: 20px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container mt-4">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link" href="/">App Deployment</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/model">Model Deployment</a>
            </li>
            <li class="nav-item">
                <a class="nav-link active" href="/docker">Docker Llama Deploy</a>
            </li>
        </ul>

        <h1 class="mb-4">🐳 Docker Llama 3.1 8B Deployment</h1>
        <p class="lead mb-4">Deploy Llama 3.1 8B Instruct with vLLM in Docker and push to Docker Hub</p>

        <div class="docker-info">
            <h5>🚀 What this deployment does:</h5>
            <ul class="mb-0">
                <li><strong>Creates a Docker image</strong> with Llama 3.1 8B Instruct and vLLM</li>
                <li><strong>Pushes to Docker Hub</strong> for easy sharing and deployment</li>
                <li><strong>Deploys the container</strong> on your server with GPU support</li>
                <li><strong>Provides OpenAI-compatible API</strong> endpoints</li>
                <li><strong>Includes monitoring and management</strong> tools</li>
            </ul>
        </div>

        <form id="dockerDeployForm">
            <div class="form-section">
                <h3>🤗 Hugging Face Configuration</h3>
                <div class="mb-3">
                    <label for="hfToken" class="form-label">Hugging Face Token</label>
                    <input type="password" class="form-control" id="hfToken" required>
                    <div class="form-text">Required for accessing Llama 3.1 8B Instruct model</div>
                </div>
            </div>

            <div class="form-section">
                <h3>🐳 Docker Hub Configuration</h3>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="dockerhubUsername" class="form-label">Docker Hub Username</label>
                            <input type="text" class="form-control" id="dockerhubUsername" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="dockerhubPassword" class="form-label">Docker Hub Password</label>
                            <input type="password" class="form-control" id="dockerhubPassword" required>
                        </div>
                    </div>
                </div>
                <div class="mb-3">
                    <label for="imageName" class="form-label">Docker Image Name</label>
                    <input type="text" class="form-control" id="imageName" value="llama3-vllm-api" required>
                    <div class="form-text">Will be pushed as: {username}/{image-name}:latest</div>
                </div>
            </div>

            <div class="form-section">
                <h3>🖥️ Server Configuration</h3>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="serverHost" class="form-label">Server Host</label>
                            <input type="text" class="form-control" id="serverHost" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="serverPort" class="form-label">SSH Port</label>
                            <input type="number" class="form-control" id="serverPort" value="22" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="serverUsername" class="form-label">Server Username</label>
                            <input type="text" class="form-control" id="serverUsername" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="serverPassword" class="form-label">Server Password</label>
                            <input type="password" class="form-control" id="serverPassword" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-section">
                <h3>⚙️ API Configuration</h3>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="apiPort" class="form-label">API Port</label>
                            <input type="number" class="form-control" id="apiPort" value="8000" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="targetUrl" class="form-label">Target URL (Optional)</label>
                            <input type="text" class="form-control" id="targetUrl" placeholder="e.g., llama.example.com">
                            <div class="form-text">For Nginx reverse proxy configuration</div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="button-container">
                <button type="submit" class="btn btn-primary btn-lg" id="deployButton">
                    🚀 Deploy Docker Container
                </button>
                <span id="deploymentStatus" class="deployment-status status-idle">Idle</span>
            </div>
        </form>

        <div class="mt-4">
            <h3>📋 Deployment Logs</h3>
            <div class="log-container" id="logOutput">Ready to deploy Llama 3.1 8B with Docker...</div>
        </div>

        <div class="success-info" id="successInfo">
            <h4>🎉 Deployment Successful!</h4>
            <div id="deploymentDetails"></div>
        </div>

        <div class="mt-4">
            <h3>📚 Docker Commands Reference</h3>
            <div class="alert alert-info">
                <h5>Useful Docker commands after deployment:</h5>
                <pre><code># Pull the image on any server
docker pull {username}/{image-name}:latest

# Run the container
docker run -d --name llama3-api --gpus all -p 8000:8000 \\
  -e HF_TOKEN=your_token \\
  {username}/{image-name}:latest

# View logs
docker logs llama3-vllm-api

# Stop container
docker stop llama3-vllm-api

# Monitor resources
docker stats llama3-vllm-api</code></pre>
            </div>
        </div>

        <div class="mt-4">
            <h3>🔧 System Requirements</h3>
            <div class="alert alert-warning">
                <h5>Minimum Requirements:</h5>
                <ul class="mb-0">
                    <li><strong>GPU:</strong> NVIDIA GPU with 8GB+ VRAM (recommended)</li>
                    <li><strong>RAM:</strong> 16GB+ system RAM</li>
                    <li><strong>Storage:</strong> 30GB+ free space</li>
                    <li><strong>Docker:</strong> Docker with NVIDIA Container Toolkit</li>
                    <li><strong>Network:</strong> Good internet connection for Docker Hub push</li>
                </ul>
            </div>
        </div>
    </div>

    <script>
        function updateDeploymentStatus(status, message) {
            const statusElement = document.getElementById('deploymentStatus');
            statusElement.className = `deployment-status status-${status}`;
            statusElement.textContent = message;
        }

        function showSuccessInfo(dockerImage, baseUrl) {
            const successInfo = document.getElementById('successInfo');
            const deploymentDetails = document.getElementById('deploymentDetails');
            
            deploymentDetails.innerHTML = `
                <p><strong>Docker Image:</strong> <code>${dockerImage}:latest</code></p>
                <p><strong>API Base URL:</strong> <a href="${baseUrl}" target="_blank">${baseUrl}</a></p>
                <p><strong>Model:</strong> meta-llama/Llama-3.1-8B-Instruct</p>
                
                <h5>API Endpoints:</h5>
                <ul>
                    <li><strong>Models:</strong> GET <code>${baseUrl}/v1/models</code></li>
                    <li><strong>Chat:</strong> POST <code>${baseUrl}/v1/chat/completions</code></li>
                    <li><strong>Completions:</strong> POST <code>${baseUrl}/v1/completions</code></li>
                </ul>
                
                <h5>Quick Test:</h5>
                <pre><code>curl ${baseUrl}/v1/models</code></pre>
            `;
            
            successInfo.style.display = 'block';
        }

        document.getElementById('dockerDeployForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const deployButton = document.getElementById('deployButton');
            const logOutput = document.getElementById('logOutput');
            const successInfo = document.getElementById('successInfo');
            
            // Reset UI
            logOutput.textContent = 'Starting Docker deployment...\n';
            successInfo.style.display = 'none';
            updateDeploymentStatus('running', 'Deploying...');
            deployButton.disabled = true;
            deployButton.textContent = '🔄 Deploying...';

            const data = {
                hf_token: document.getElementById('hfToken').value,
                dockerhub_username: document.getElementById('dockerhubUsername').value,
                dockerhub_password: document.getElementById('dockerhubPassword').value,
                image_name: document.getElementById('imageName').value,
                server_host: document.getElementById('serverHost').value,
                server_port: document.getElementById('serverPort').value,
                server_username: document.getElementById('serverUsername').value,
                server_password: document.getElementById('serverPassword').value,
                api_port: document.getElementById('apiPort').value,
                target_url: document.getElementById('targetUrl').value || null
            };

            try {
                const response = await fetch('/deploy-docker', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                const reader = response.body.getReader();
                const decoder = new TextDecoder();

                while (true) {
                    const {value, done} = await reader.read();
                    if (done) break;
                    
                    const text = decoder.decode(value);
                    logOutput.textContent += text;
                    logOutput.scrollTop = logOutput.scrollHeight;

                    // Check for success
                    if (text.includes('🎉 DEPLOYMENT SUCCESSFUL!')) {
                        updateDeploymentStatus('success', 'Success');
                        
                        const targetUrl = document.getElementById('targetUrl').value;
                        const serverHost = document.getElementById('serverHost').value;
                        const apiPort = document.getElementById('apiPort').value;
                        const baseUrl = targetUrl ? `http://${targetUrl}` : `http://${serverHost}:${apiPort}`;
                        const dockerImage = `${data.dockerhub_username}/${data.image_name}`;
                        
                        showSuccessInfo(dockerImage, baseUrl);
                    } else if (text.includes('Deployment failed') || text.includes('Error:')) {
                        updateDeploymentStatus('error', 'Failed');
                    }
                }

                if (!response.ok) {
                    throw new Error('Deployment failed');
                }
            } catch (error) {
                logOutput.textContent += `\nError: ${error.message}`;
                updateDeploymentStatus('error', 'Failed');
            } finally {
                deployButton.disabled = false;
                deployButton.textContent = '🚀 Deploy Docker Container';
            }
        });

        // Update Docker commands reference with actual username
        document.getElementById('dockerhubUsername').addEventListener('input', function() {
            const username = this.value;
            const imageName = document.getElementById('imageName').value;
            const codeBlocks = document.querySelectorAll('code');
            
            codeBlocks.forEach(block => {
                block.textContent = block.textContent.replace(/{username}/g, username);
                block.textContent = block.textContent.replace(/{image-name}/g, imageName);
            });
        });

        document.getElementById('imageName').addEventListener('input', function() {
            const username = document.getElementById('dockerhubUsername').value;
            const imageName = this.value;
            const codeBlocks = document.querySelectorAll('code');
            
            codeBlocks.forEach(block => {
                block.textContent = block.textContent.replace(/{image-name}/g, imageName);
            });
        });
    </script>
</body>
</html>