index.html 9.59 KB
Newer Older
Edward Tang's avatar
Edward Tang committed
1
2
3
4
5
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
Edward Tang's avatar
Edward Tang committed
6
    <title>App Deployment</title>
Edward Tang's avatar
Edward Tang committed
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
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container { max-width: 800px; }
        .log-container {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            padding: 15px;
            height: 300px;
            overflow-y: auto;
            font-family: monospace;
            margin-top: 20px;
        }
        .log-entry {
            margin: 5px 0;
            white-space: pre-wrap;
        }
        .log-error { color: #dc3545; }
        .log-success { color: #198754; }
        .log-info { color: #0dcaf0; }
        .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;
        }
Edward Tang's avatar
Edward Tang committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        .nav-tabs {
            margin-bottom: 20px;
        }
        .nav-link {
            color: #495057;
            font-weight: 500;
        }
        .nav-link.active {
            color: #0d6efd;
            font-weight: 600;
        }
        .page-header {
            margin-bottom: 30px;
        }
        .page-header h1 {
            font-size: 2rem;
            margin-bottom: 10px;
        }
        .page-header p {
            color: #6c757d;
            margin-bottom: 0;
        }
Edward Tang's avatar
Edward Tang committed
72
73
74
75
    </style>
</head>
<body>
    <div class="container mt-5">
Edward Tang's avatar
Edward Tang committed
76
77
78
79
80
81
82
83
84
85
86
87
88
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="/">App Deployment</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/model">Model Deployment</a>
            </li>
        </ul>

        <div class="page-header">
            <h1>App Deployment</h1>
            <p>Deploy your GitHub repository to a server using Docker</p>
        </div>
Edward Tang's avatar
Edward Tang committed
89
90
91
92
93
        
        <form id="deployForm" class="needs-validation" novalidate>
            <div class="row g-3">
                <!-- GitHub Credentials -->
                <div class="col-md-6">
94
95
                    <label for="githubUsername" class="form-label">GitHub Username (optional)</label>
                    <input type="text" class="form-control" id="githubUsername">
Edward Tang's avatar
Edward Tang committed
96
97
                </div>
                <div class="col-md-6">
98
99
                    <label for="githubToken" class="form-label">GitHub Token (optional)</label>
                    <input type="password" class="form-control" id="githubToken">
Edward Tang's avatar
Edward Tang committed
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
                </div>

                <!-- Repository URL -->
                <div class="col-12">
                    <label for="repoUrl" class="form-label">Repository URL</label>
                    <input type="url" class="form-control" id="repoUrl" required>
                </div>

                <!-- Server Credentials -->
                <div class="col-md-6">
                    <label for="serverHost" class="form-label">Server Host</label>
                    <input type="text" class="form-control" id="serverHost" required>
                </div>
                <div class="col-md-6">
                    <label for="serverPort" class="form-label">Server Port</label>
                    <input type="number" class="form-control" id="serverPort" value="22">
                </div>
                <div class="col-md-6">
                    <label for="serverUsername" class="form-label">Server Username</label>
                    <input type="text" class="form-control" id="serverUsername" required>
                </div>
                <div class="col-md-6">
                    <label for="serverPassword" class="form-label">Server Password</label>
                    <input type="password" class="form-control" id="serverPassword" required>
                </div>

                <!-- Deployment Options -->
                <div class="col-md-6">
                    <label for="targetUrl" class="form-label">Target URL (optional)</label>
                    <input type="text" class="form-control" id="targetUrl">
                </div>
                <div class="col-md-6">
                    <label for="appPort" class="form-label">App Port</label>
                    <input type="number" class="form-control" id="appPort" value="3000">
                </div>
            </div>

            <div class="mt-4">
                <button type="submit" class="btn btn-primary" id="deployButton">Deploy</button>
                <span id="deploymentStatus" class="deployment-status status-idle">Idle</span>
            </div>
        </form>

        <!-- Log Output -->
        <div class="log-container" id="logOutput"></div>
    </div>

    <script>
        let currentDeployment = null;

        document.getElementById('deployForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const deployButton = document.getElementById('deployButton');
            const logOutput = document.getElementById('logOutput');
            const statusElement = document.getElementById('deploymentStatus');
            
            // Clear logs and update status
            logOutput.innerHTML = '';
            statusElement.className = 'deployment-status status-running';
            statusElement.textContent = 'Deploying...';
            
            // Add initial log
            addLog('Starting deployment...', 'info');
            
            try {
                // Abort any existing deployment
                if (currentDeployment) {
                    currentDeployment.abort();
                }

                const controller = new AbortController();
                currentDeployment = controller;

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
                const formData = {
                    repo_url: document.getElementById('repoUrl').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,
                    target_url: document.getElementById('targetUrl').value,
                    app_port: document.getElementById('appPort').value
                };

                // Only add GitHub credentials if both are provided
                const githubUsername = document.getElementById('githubUsername').value;
                const githubToken = document.getElementById('githubToken').value;
                if (githubUsername && githubToken) {
                    formData.github_username = githubUsername;
                    formData.github_token = githubToken;
                }

Edward Tang's avatar
Edward Tang committed
192
193
194
195
196
                const response = await fetch('/deploy', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
197
                    body: JSON.stringify(formData),
Edward Tang's avatar
Edward Tang committed
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
                    signal: controller.signal
                });

                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);
                    const lines = text.split('\n');
                    
                    for (const line of lines) {
                        if (line.trim()) {
                            if (line.includes('ERROR')) {
                                addLog(line, 'error');
                                statusElement.className = 'deployment-status status-error';
                                statusElement.textContent = 'Failed';
                            } else if (line.includes('Deployment completed successfully')) {
                                addLog(line, 'success');
                                statusElement.className = 'deployment-status status-success';
                                statusElement.textContent = 'Success';
                            } else if (line.includes('INFO')) {
                                addLog(line, 'info');
                            } else {
                                addLog(line, 'info');
                            }
                        }
                    }
                }
            } catch (error) {
                if (error.name !== 'AbortError')  {
                    addLog(`Error: ${error.message}`, 'error');
                    statusElement.className = 'deployment-status status-error';
                    statusElement.textContent = 'Failed';
                }
            } finally {
                currentDeployment = null;
            }
        });

        function addLog(message, type) {
            const logOutput = document.getElementById('logOutput');
            const logEntry = document.createElement('div');
            logEntry.className = `log-entry log-${type}`;
            logEntry.textContent = message;
            logOutput.appendChild(logEntry);
            logOutput.scrollTop = logOutput.scrollHeight;
        }
    </script>
</body>
</html>