fix: rewrite Dokploy client with correct API format (tRPC + x-api-key)

- Verified endpoints from @dokploy/mcp source code:
  - Auth: x-api-key header (not Authorization: Bearer)
  - Base URL: {url}/api
  - application.create → needs environmentId (not projectId)
  - Git provider saved separately: saveGiteaProvider / saveGithubProvider / saveGitProvider
  - Environment vars saved via saveEnvironment
  - Deploy is a separate call after create
  - Domain attach via domain.create
- Provisioning flow now multi-step:
  1. application.create
  2. saveGiteaProvider or saveGithubProvider (based on gitRepo URL)
  3. saveEnvironment (env vars)
  4. application.deploy
  5. domain.create (optional, non-fatal)
- Removed database provisioning (Dokploy apps use their own DB via env vars)
- Teardown simplified: deleteDomain → deleteApplication
- Updated instances route + cleanup route to match new API
This commit is contained in:
Z User committed 2026-10-28 23:05:53 +00:00
1 parent 970986fef7
commit 617f00b715
4 files changed
+209 -195

No files matched your search

+1 -2
View File
@@ -184,8 +184,7 @@ export async function DELETE(_req: Request, { params }: { params: Promise<{ id:
try {
const result = await dokploy.teardownInstance({
dokployAppId: instance.dokployAppId ?? undefined,
dokployDbId: instance.dokployDbId ?? undefined,
dnsDomainId: meta.dokployDomainId,
dokployDomainId: meta.dokployDomainId,
})
steps.push(...result.steps)
await db.instanceEvent.create({
+1 -2
View File
@@ -88,8 +88,7 @@ export async function POST(req: Request) {
try {
const r = await dokploy.teardownInstance({
dokployAppId: inst.dokployAppId ?? undefined,
dokployDbId: inst.dokployDbId ?? undefined,
dnsDomainId: meta.dokployDomainId,
dokployDomainId: meta.dokployDomainId,
})
steps.push(...r.steps)
} catch (e) {
+3 -8
View File
@@ -158,7 +158,7 @@ export async function POST(req: Request) {
gitRepo,
gitBranch,
envVars: instanceEnv,
databaseName: `${product}_${subdomain}`.replace(/-/g, '_').slice(0, 40),
gitProvider: gitRepo.includes('github.com') ? 'github' : 'gitea',
cpuLimit: plan === 'enterprise' ? '2' : plan === 'pro' ? '1' : '0.5',
memoryLimit: plan === 'enterprise' ? '2048m' : plan === 'pro' ? '1024m' : '512m',
}
@@ -183,8 +183,7 @@ export async function POST(req: Request) {
result: 'ok',
details: JSON.stringify({
appId: result.app.applicationId,
dbId: result.database?.databaseId,
domainId: result.domain.domainId,
domainId: result.domain?.domainId,
url: result.url,
}),
},
@@ -227,15 +226,11 @@ export async function POST(req: Request) {
data: {
status: isDemo ? 'demo_active' : 'active',
dokployAppId: result.app.applicationId,
dokployDbId: result.database?.databaseId ?? null,
dokployDbName: result.database?.database ?? null,
dokployDbUser: result.database?.username ?? null,
dokployDbPassword: result.database?.password ?? null,
dnsRecordId,
metadata: JSON.stringify({
gitRepo,
gitBranch,
dokployDomainId: result.domain.domainId,
dokployDomainId: result.domain?.domainId ?? null,
url: result.url,
provisionedAt: now.toISOString(),
}),