feat: deploy all stacks to shared ai-stack-portal project
- Add SHARED_PROJECT_ID and SHARED_ENVIRONMENT_ID env vars - Add findApplicationByName to Dokploy client for app-based lookup - Update production-deployer to use shared project instead of creating new ones - Update name availability check to query apps in shared environment - Update delete endpoint to remove apps from shared project - Rollback no longer deletes shared project (only app/domain) - Backward compatible: falls back to per-project if env vars not set
This commit is contained in:
@@ -20,6 +20,8 @@ export interface DeploymentConfig {
|
||||
healthCheckTimeout?: number;
|
||||
healthCheckInterval?: number;
|
||||
registryId?: string;
|
||||
sharedProjectId?: string;
|
||||
sharedEnvironmentId?: string;
|
||||
}
|
||||
|
||||
export interface DeploymentState {
|
||||
@@ -179,17 +181,27 @@ export class ProductionDeployer {
|
||||
): Promise<void> {
|
||||
state.phase = 'creating_project';
|
||||
state.progress = 10;
|
||||
state.message = 'Creating or finding project';
|
||||
state.message = 'Using shared project for deployment';
|
||||
|
||||
// Use shared project and environment IDs from config or env vars
|
||||
const sharedProjectId = config.sharedProjectId || process.env.SHARED_PROJECT_ID;
|
||||
const sharedEnvironmentId = config.sharedEnvironmentId || process.env.SHARED_ENVIRONMENT_ID;
|
||||
|
||||
if (sharedProjectId && sharedEnvironmentId) {
|
||||
console.log(`Using shared project: ${sharedProjectId}, environment: ${sharedEnvironmentId}`);
|
||||
state.resources.projectId = sharedProjectId;
|
||||
state.resources.environmentId = sharedEnvironmentId;
|
||||
state.message = 'Using shared project';
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback to legacy behavior if shared IDs not configured
|
||||
const projectName = `ai-stack-${config.stackName}`;
|
||||
|
||||
// Idempotency: Check if project already exists
|
||||
const existingProject = await this.client.findProjectByName(projectName);
|
||||
|
||||
if (existingProject) {
|
||||
console.log(`Project ${projectName} already exists, reusing...`);
|
||||
state.resources.projectId = existingProject.project.projectId;
|
||||
// Also capture environment ID if available
|
||||
if (existingProject.environmentId) {
|
||||
state.resources.environmentId = existingProject.environmentId;
|
||||
}
|
||||
@@ -197,7 +209,6 @@ export class ProductionDeployer {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new project (returns both project and environment)
|
||||
const response = await this.client.createProject(
|
||||
projectName,
|
||||
`AI Stack for ${config.stackName}`
|
||||
@@ -413,6 +424,8 @@ export class ProductionDeployer {
|
||||
state.phase = 'rolling_back';
|
||||
state.message = 'Rolling back deployment';
|
||||
|
||||
const isSharedProject = !!(process.env.SHARED_PROJECT_ID || process.env.SHARED_ENVIRONMENT_ID);
|
||||
|
||||
try {
|
||||
if (state.resources.domainId) {
|
||||
console.log(`Rolling back: deleting domain ${state.resources.domainId}`);
|
||||
@@ -432,7 +445,7 @@ export class ProductionDeployer {
|
||||
}
|
||||
}
|
||||
|
||||
if (state.resources.projectId) {
|
||||
if (state.resources.projectId && !isSharedProject) {
|
||||
console.log(`Rolling back: deleting project ${state.resources.projectId}`);
|
||||
try {
|
||||
await this.client.deleteProject(state.resources.projectId);
|
||||
|
||||
Reference in New Issue
Block a user