Publish AI workspace source through the isolated runtime
This commit is contained in:
1 parent
03169bd0f6
commit
d1d14f0f77
21 files changed
+487
-68
No files matched your search
@@ -44,6 +44,7 @@ const subscriptionActive = computed(() =>
|
||||
subscription.value.status === "ACTIVE" && new Date(subscription.value.paid_until).getTime() > Date.now(),
|
||||
);
|
||||
const hasService = computed(() => services.value.some(service => service.enabled));
|
||||
const hasManagedSource = computed(() => services.value.some(service => service.enabled && service.source_managed));
|
||||
const deploying = computed(() =>
|
||||
deployments.value.some(deployment => ["QUEUED", "APPLYING", "HEALTH_CHECK"].includes(deployment.status)),
|
||||
);
|
||||
@@ -159,21 +160,26 @@ async function buy(p: any) {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function deploy(rollbackId?: string) {
|
||||
if (!canPublish.value || (!rollbackId && !hasService.value) || busy.value) return;
|
||||
if (!confirm(rollbackId ? "确认重新发布历史版本?" : "确认发布当前配置?"))
|
||||
const sourceKeys = new Map<string, string>();
|
||||
async function deploy(rollbackId?: string, fromSource = false) {
|
||||
if (!canPublish.value || (!rollbackId && !fromSource && (!hasService.value || hasManagedSource.value)) || busy.value) return;
|
||||
const id = project.value;
|
||||
if (!confirm(rollbackId ? "确认重新发布历史版本?" : fromSource ? "确认从当前 AI 工作区源码构建并发布?" : "确认发布当前服务配置?"))
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await api("/projects/" + project.value + "/deployments", {
|
||||
if (fromSource && !sourceKeys.has(id)) sourceKeys.set(id, crypto.randomUUID());
|
||||
await api("/projects/" + id + "/deployments" + (fromSource ? "/source" : ""), {
|
||||
method: "POST",
|
||||
...(fromSource ? { signal: AbortSignal.timeout(170000) } : {}),
|
||||
body: body({
|
||||
idempotencyKey: crypto.randomUUID(),
|
||||
rollbackId: rollbackId || null,
|
||||
idempotencyKey: fromSource ? sourceKeys.get(id) : crypto.randomUUID(),
|
||||
...(fromSource ? {} : { rollbackId: rollbackId || null }),
|
||||
}),
|
||||
});
|
||||
success.value = "部署已入队";
|
||||
if (fromSource) sourceKeys.delete(id);
|
||||
success.value = fromSource ? "已保存源码快照,等待自动构建与发布" : "部署已入队";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
@@ -236,11 +242,12 @@ onUnmounted(() => clearInterval(timer));
|
||||
<div>
|
||||
<span class="eyebrow">CLOUD RUNTIME</span>
|
||||
<h1>云托管</h1>
|
||||
<p>OCI 多服务、健康发布与版本回滚。</p>
|
||||
<p>从项目源码自动发布,也可以使用已有镜像。</p>
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button class="primary" :disabled="!canPublish || busy" @click="deploy(undefined, true)">从源码发布</button>
|
||||
<button class="secondary" :disabled="!canPublish || !hasService || hasManagedSource || busy" @click="deploy()">发布已有镜像</button>
|
||||
</div>
|
||||
<button class="primary" :disabled="!canPublish || !hasService || busy" @click="deploy()">
|
||||
发布当前配置
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
@@ -262,7 +269,7 @@ onUnmounted(() => clearInterval(timer));
|
||||
<p v-else-if="publication.reviewStatus === 'PENDING'">请联系管理员在「网站管理与人工审核」中处理,通过后即可发布。</p>
|
||||
<p v-else-if="publication.reviewStatus !== 'APPROVED'">请联系管理员处理审核状态。</p>
|
||||
<p v-if="!subscriptionActive">发布需要有效的托管套餐,可在下方购买或续期。</p>
|
||||
<p v-if="!hasService">请添加并启用至少一个服务。</p>
|
||||
<p v-if="!hasService">可直接从 AI 工作区发布源码。使用已有镜像时,需要先添加服务。</p>
|
||||
<p v-if="deploying">已有发布任务正在处理。</p>
|
||||
</div>
|
||||
<section class="project-grid">
|
||||
@@ -271,13 +278,13 @@ onUnmounted(() => clearInterval(timer));
|
||||
<h3>{{ s.name }}</h3>
|
||||
<span class="status">{{ s.enabled ? "启用" : "停用" }}</span>
|
||||
</div>
|
||||
<p>{{ s.image }}</p>
|
||||
<p>{{ s.source_managed ? "平台自动构建的源码服务" : s.image }}</p>
|
||||
<small
|
||||
>{{ s.cpu_millis }}m CPU / {{ s.memory_mb }}MiB / {{ s.replicas }} 副本
|
||||
/ 端口 {{ s.port }}</small
|
||||
>
|
||||
<div class="project-actions">
|
||||
<button class="link" @click="edit(s)">配置</button
|
||||
<button v-if="!s.source_managed" class="link" @click="edit(s)">配置</button
|
||||
><button class="link" :disabled="busy" @click="runtime(s, 'status')">
|
||||
状态</button
|
||||
><button class="link" :disabled="busy" @click="runtime(s, 'logs')">
|
||||
@@ -289,7 +296,7 @@ onUnmounted(() => clearInterval(timer));
|
||||
</article>
|
||||
</section>
|
||||
<div v-if="!services.length" class="panel empty">
|
||||
尚无服务,添加已有 OCI 镜像开始。
|
||||
尚无运行服务。可从 AI 工作区源码发布,平台会自动创建服务。
|
||||
</div>
|
||||
<section v-if="output" class="panel event-log">
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
@@ -337,6 +344,7 @@ onUnmounted(() => clearInterval(timer));
|
||||
<th>版本</th>
|
||||
<th>时间</th>
|
||||
<th>状态</th>
|
||||
<th>来源</th>
|
||||
<th>错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
@@ -346,6 +354,7 @@ onUnmounted(() => clearInterval(timer));
|
||||
<td class="truncate" :title="d.id">{{ d.id }}</td>
|
||||
<td>{{ new Date(d.created_at).toLocaleString() }}</td>
|
||||
<td>{{ d.status }}</td>
|
||||
<td>{{ d.release_type === "SOURCE" ? "源码" : "镜像" }}</td>
|
||||
<td>{{ d.error }}</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
@@ -362,7 +371,7 @@ onUnmounted(() => clearInterval(timer));
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!deployments.length">
|
||||
<td colspan="5" class="empty">暂无部署</td>
|
||||
<td colspan="6" class="empty">暂无部署</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in new issue
Block a user