Skip to content

Commit e48c58c

Browse files
committed
feat: add deploy command
1 parent 209eadc commit e48c58c

File tree

8 files changed

+625
-2
lines changed

8 files changed

+625
-2
lines changed

src/commands/app/deploy.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import { readAuthConfig } from "../../utils/utils.js";
3+
import chalk from "chalk";
4+
import { getProject, getProjects } from "../../utils/shared.js";
5+
import inquirer from "inquirer";
6+
import type { Answers } from "./create.js";
7+
import axios from "axios";
8+
9+
export default class AppDeploy extends Command {
10+
static description = "Deploy an application to a project.";
11+
12+
static examples = ["$ <%= config.bin %> app deploy"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to deploy the application in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.applications.length === 0) {
38+
this.error(chalk.yellow("No applications found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.applications.map((app) => ({
45+
name: app.name,
46+
value: app.applicationId,
47+
})),
48+
message: "Select the application to deploy:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const applicationId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to deploy this application?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("Application deployment cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/application.deploy`,
71+
{
72+
json: {
73+
applicationId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error deploying application"));
86+
}
87+
this.log(chalk.green("Application deploy successful."));
88+
}
89+
}

src/commands/app/stop.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import { readAuthConfig } from "../../utils/utils.js";
3+
import chalk from "chalk";
4+
import inquirer from "inquirer";
5+
import { getProject, getProjects } from "../../utils/shared.js";
6+
import type { Answers } from "./create.js";
7+
import axios from "axios";
8+
9+
export default class AppStop extends Command {
10+
static description = "Stop an application from a project.";
11+
12+
static examples = ["$ <%= config.bin %> app stop"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to stop the application in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.applications.length === 0) {
38+
this.error(chalk.yellow("No applications found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.applications.map((app) => ({
45+
name: app.name,
46+
value: app.applicationId,
47+
})),
48+
message: "Select the application to stop:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const applicationId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to stop this application?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("Application stop cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/application.stop`,
71+
{
72+
json: {
73+
applicationId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error stopping application"));
86+
}
87+
this.log(chalk.green("Application stop successful."));
88+
}
89+
}

src/commands/database/mariadb/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export default class DatabaseMariadbCreate extends Command {
7575
type: "password",
7676
},
7777
{
78-
default: "mariadb:4",
79-
message: "Docker Image (default: mariadb:4):",
78+
default: "mariadb:11",
79+
message: "Docker Image (default: mariadb:11):",
8080
name: "dockerImage",
8181
type: "input",
8282
},
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import { readAuthConfig } from "../../../utils/utils.js";
3+
import chalk from "chalk";
4+
import { getProject, getProjects } from "../../../utils/shared.js";
5+
import inquirer from "inquirer";
6+
import type { Answers } from "../../app/create.js";
7+
import axios from "axios";
8+
9+
export default class DatabaseMariadbDeploy extends Command {
10+
static description = "Deploy an mariadb to a project.";
11+
12+
static examples = ["$ <%= config.bin %> app deploy"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to deploy the mariadb in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.mariadb.length === 0) {
38+
this.error(chalk.yellow("No mariadb found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.mariadb.map((app) => ({
45+
name: app.name,
46+
value: app.mariadbId,
47+
})),
48+
message: "Select the mariadb to deploy:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const mariadbId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to deploy this mariadb?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("mariadb deployment cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/mariadb.deploy`,
71+
{
72+
json: {
73+
mariadbId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error deploying mariadb"));
86+
}
87+
this.log(chalk.green("Mariadb deploy successful."));
88+
}
89+
}

src/commands/database/mongo/deploy.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import { readAuthConfig } from "../../../utils/utils.js";
3+
import chalk from "chalk";
4+
import { getProject, getProjects } from "../../../utils/shared.js";
5+
import inquirer from "inquirer";
6+
import type { Answers } from "../../app/create.js";
7+
import axios from "axios";
8+
9+
export default class DatabaseMongoDeploy extends Command {
10+
static description = "Deploy an mongo to a project.";
11+
12+
static examples = ["$ <%= config.bin %> app deploy"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to deploy the mongo in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.mongo.length === 0) {
38+
this.error(chalk.yellow("No mongo found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.mongo.map((app) => ({
45+
name: app.name,
46+
value: app.mongoId,
47+
})),
48+
message: "Select the mongo to deploy:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const mongoId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to deploy this mongo?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("mongo deployment cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/mongo.deploy`,
71+
{
72+
json: {
73+
mongoId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error deploying mongo"));
86+
}
87+
this.log(chalk.green("Mongo deploy successful."));
88+
}
89+
}

0 commit comments

Comments
 (0)