mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-15 20:25:22 +02:00
feat: enhance app deployment command with environment selection
- Added environmentId flag to the AppDeploy command for specifying the environment. - Implemented interactive prompts for selecting project, environment, and application if flags are not provided. - Updated type definitions to include Application and Environment types for better type safety. - Improved error handling for cases with no available environments or applications.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Command, Flags } from "@oclif/core";
|
||||
import { readAuthConfig } from "../../utils/utils.js";
|
||||
import chalk from "chalk";
|
||||
import { getProject, getProjects } from "../../utils/shared.js";
|
||||
import { getProject, getProjects, type Application } from "../../utils/shared.js";
|
||||
import inquirer from "inquirer";
|
||||
import type { Answers } from "./create.js";
|
||||
import axios from "axios";
|
||||
@@ -26,6 +26,11 @@ export default class AppDeploy extends Command {
|
||||
description: 'ID of the project',
|
||||
required: false,
|
||||
}),
|
||||
environmentId: Flags.string({
|
||||
char: 'e',
|
||||
description: 'ID of the environment',
|
||||
required: false,
|
||||
}),
|
||||
skipConfirm: Flags.boolean({
|
||||
char: 'y',
|
||||
description: 'Skip confirmation prompt',
|
||||
@@ -36,13 +41,17 @@ export default class AppDeploy extends Command {
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
const { flags } = await this.parse(AppDeploy);
|
||||
let { projectId, applicationId } = flags;
|
||||
let { projectId, applicationId, environmentId } = flags;
|
||||
|
||||
// Modo interactivo si no se proporcionan los flags necesarios
|
||||
if (!projectId || !applicationId) {
|
||||
if (!projectId || !applicationId || !environmentId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
let selectedProject;
|
||||
let selectedEnvironment;
|
||||
|
||||
// 1. Seleccionar proyecto
|
||||
if (!projectId) {
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
@@ -55,20 +64,44 @@ export default class AppDeploy extends Command {
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
selectedProject = project;
|
||||
projectId = project.projectId;
|
||||
} else {
|
||||
selectedProject = projects.find(p => p.projectId === projectId);
|
||||
}
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
// 2. Seleccionar environment del proyecto
|
||||
if (!environmentId) {
|
||||
if (!selectedProject?.environments || selectedProject.environments.length === 0) {
|
||||
this.error(chalk.yellow("No environments found in this project."));
|
||||
}
|
||||
|
||||
if (projectSelected.applications.length === 0) {
|
||||
this.error(chalk.yellow("No applications found in this project."));
|
||||
const { environment } = await inquirer.prompt([
|
||||
{
|
||||
choices: selectedProject.environments.map((env) => ({
|
||||
name: `${env.name} (${env.description})`,
|
||||
value: env,
|
||||
})),
|
||||
message: "Select an environment:",
|
||||
name: "environment",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
selectedEnvironment = environment;
|
||||
environmentId = environment.environmentId;
|
||||
} else {
|
||||
selectedEnvironment = selectedProject?.environments?.find(e => e.environmentId === environmentId);
|
||||
}
|
||||
|
||||
// 3. Seleccionar application del environment
|
||||
if (!applicationId) {
|
||||
if (!selectedEnvironment?.applications || selectedEnvironment.applications.length === 0) {
|
||||
this.error(chalk.yellow("No applications found in this environment."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.applications.map((app) => ({
|
||||
choices: selectedEnvironment.applications.map((app: Application) => ({
|
||||
name: app.name,
|
||||
value: app.applicationId,
|
||||
})),
|
||||
|
||||
@@ -103,7 +103,3 @@ export default class Authenticate extends Command {
|
||||
}
|
||||
}
|
||||
}
|
||||
// curl -X 'GET' \
|
||||
// 'https://panel.jinza.app/api/project.all' \
|
||||
// -H 'accept: application/json' \
|
||||
// -H 'x-api-key: EawCkTREMhxoAqvCxJFZurgCGoDZPjYHHrLgUPghRjJTpXLaahFdhCOGfABZXTRP'
|
||||
@@ -5,11 +5,34 @@ import chalk from "chalk";
|
||||
|
||||
import type { AuthConfig } from "./utils.js";
|
||||
|
||||
export type Application = {
|
||||
applicationId: string;
|
||||
name: string;
|
||||
// Add other application properties as needed
|
||||
};
|
||||
|
||||
export type Environment = {
|
||||
name: string;
|
||||
environmentId: string;
|
||||
description: string;
|
||||
createdAt: string;
|
||||
env: string;
|
||||
projectId: string;
|
||||
applications: Application[];
|
||||
mariadb: any[];
|
||||
mongo: any[];
|
||||
mysql: any[];
|
||||
postgres: any[];
|
||||
redis: any[];
|
||||
compose: any[];
|
||||
};
|
||||
|
||||
export type Project = {
|
||||
adminId: string;
|
||||
name: string;
|
||||
projectId?: string | undefined;
|
||||
description?: string | undefined;
|
||||
environments?: Environment[];
|
||||
};
|
||||
|
||||
export const getProjects = async (
|
||||
|
||||
Reference in New Issue
Block a user