@dokploy/cli 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mauricio Siu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class EnvPull extends Command {
3
+ static args: {
4
+ file: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {};
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,68 @@
1
+ import { Args, 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 fs from 'fs';
7
+ export default class EnvPull extends Command {
8
+ static args = {
9
+ file: Args.string({ description: 'write to file', required: true }),
10
+ };
11
+ static description = 'Store remote environment variables in local';
12
+ static examples = [
13
+ '<%= config.bin %> <%= command.id %> .env.stage.local',
14
+ ];
15
+ static flags = {};
16
+ async run() {
17
+ const { args } = await this.parse(EnvPull);
18
+ if (fs.existsSync(args.file)) {
19
+ const { override } = await inquirer.prompt([
20
+ {
21
+ message: `Do you want to override ${args.file} file?`,
22
+ name: "override",
23
+ default: false,
24
+ type: "confirm",
25
+ },
26
+ ]);
27
+ if (!override) {
28
+ return;
29
+ }
30
+ }
31
+ const auth = await readAuthConfig(this);
32
+ console.log(chalk.blue.bold("\n Listing all Projects \n"));
33
+ const projects = await getProjects(auth, this);
34
+ const { project } = await inquirer.prompt([
35
+ {
36
+ choices: projects.map((project) => ({
37
+ name: project.name,
38
+ value: project,
39
+ })),
40
+ message: "Select the project:",
41
+ name: "project",
42
+ type: "list",
43
+ },
44
+ ]);
45
+ const projectId = project.projectId;
46
+ const projectSelected = await getProject(projectId, auth, this);
47
+ const choices = [
48
+ ...projectSelected.applications.map((app) => ({
49
+ name: `${app.name} (Application)`,
50
+ value: app.env,
51
+ })),
52
+ ...projectSelected.compose.map((compose) => ({
53
+ name: `${compose.name} (Compose)`,
54
+ value: compose.env,
55
+ })),
56
+ ];
57
+ const { env } = await inquirer.prompt([
58
+ {
59
+ choices,
60
+ message: "Select a service to pull the environment variables:",
61
+ name: "env",
62
+ type: "list",
63
+ },
64
+ ]);
65
+ fs.writeFileSync(args.file, env || "");
66
+ this.log(chalk.green("Environment variable write to file successful."));
67
+ }
68
+ }
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class EnvPush extends Command {
3
+ static args: {
4
+ file: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {};
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,106 @@
1
+ import { Args, Command } from '@oclif/core';
2
+ import fs from "fs";
3
+ import chalk from "chalk";
4
+ import inquirer from "inquirer";
5
+ import { readAuthConfig } from "../../utils/utils.js";
6
+ import { getProject, getProjects } from "../../utils/shared.js";
7
+ import axios from "axios";
8
+ export default class EnvPush extends Command {
9
+ static args = {
10
+ file: Args.string({ description: '.env file to push', required: true }),
11
+ };
12
+ static description = 'Push dotenv file to remote service';
13
+ static examples = [
14
+ '<%= config.bin %> <%= command.id %> .env.stage.local',
15
+ ];
16
+ static flags = {};
17
+ async run() {
18
+ const { args, flags } = await this.parse(EnvPush);
19
+ if (!fs.existsSync(args.file)) {
20
+ console.log(chalk.red.bold(`\n File ${args.file} doesn't exists \n`));
21
+ return;
22
+ }
23
+ const { override } = await inquirer.prompt([
24
+ {
25
+ message: `This command will override entire remote environment variables. Do you want to continue?`,
26
+ name: "override",
27
+ default: false,
28
+ type: "confirm",
29
+ },
30
+ ]);
31
+ if (!override) {
32
+ return;
33
+ }
34
+ const fileContent = fs.readFileSync(args.file, 'utf-8');
35
+ const auth = await readAuthConfig(this);
36
+ console.log(chalk.blue.bold("\n Listing all Projects \n"));
37
+ const projects = await getProjects(auth, this);
38
+ const { project } = await inquirer.prompt([
39
+ {
40
+ choices: projects.map((project) => ({
41
+ name: project.name,
42
+ value: project,
43
+ })),
44
+ message: "Select the project:",
45
+ name: "project",
46
+ type: "list",
47
+ },
48
+ ]);
49
+ const projectId = project.projectId;
50
+ const projectSelected = await getProject(projectId, auth, this);
51
+ const choices = [
52
+ ...projectSelected.applications.map((app) => ({
53
+ name: `${app.name} (Application)`,
54
+ value: { serviceType: 'app', service: app },
55
+ })),
56
+ ...projectSelected.compose.map((compose) => ({
57
+ name: `${compose.name} (Compose)`,
58
+ value: { serviceType: 'compose', service: compose }
59
+ })),
60
+ ];
61
+ const { result: { serviceType, service } } = await inquirer.prompt([
62
+ {
63
+ choices,
64
+ message: "Select a service to pull the environment variables:",
65
+ name: "result",
66
+ type: "list",
67
+ },
68
+ ]);
69
+ if (serviceType === 'app') {
70
+ const { applicationId } = service;
71
+ const response = await axios.post(`${auth.url}/api/trpc/application.update`, {
72
+ json: {
73
+ applicationId,
74
+ env: fileContent
75
+ }
76
+ }, {
77
+ headers: {
78
+ Authorization: `Bearer ${auth.token}`,
79
+ "Content-Type": "application/json",
80
+ },
81
+ });
82
+ if (response.status !== 200) {
83
+ this.error(chalk.red("Error stopping application"));
84
+ }
85
+ this.log(chalk.green("Environment variable push successful."));
86
+ }
87
+ if (serviceType === 'compose') {
88
+ const { composeId } = service;
89
+ const response = await axios.post(`${auth.url}/api/trpc/compose.update`, {
90
+ json: {
91
+ composeId,
92
+ env: fileContent
93
+ }
94
+ }, {
95
+ headers: {
96
+ Authorization: `Bearer ${auth.token}`,
97
+ "Content-Type": "application/json",
98
+ },
99
+ });
100
+ if (response.status !== 200) {
101
+ this.error(chalk.red("Error stopping application"));
102
+ }
103
+ this.log(chalk.green("Environment variable push successful."));
104
+ }
105
+ }
106
+ }
@@ -181,6 +181,66 @@
181
181
  "stop.js"
182
182
  ]
183
183
  },
184
+ "env:pull": {
185
+ "aliases": [],
186
+ "args": {
187
+ "file": {
188
+ "description": "write to file",
189
+ "name": "file",
190
+ "required": true
191
+ }
192
+ },
193
+ "description": "Store remote environment variables in local",
194
+ "examples": [
195
+ "<%= config.bin %> <%= command.id %> .env.stage.local"
196
+ ],
197
+ "flags": {},
198
+ "hasDynamicHelp": false,
199
+ "hiddenAliases": [],
200
+ "id": "env:pull",
201
+ "pluginAlias": "@dokploy/cli",
202
+ "pluginName": "@dokploy/cli",
203
+ "pluginType": "core",
204
+ "strict": true,
205
+ "enableJsonFlag": false,
206
+ "isESM": true,
207
+ "relativePath": [
208
+ "dist",
209
+ "commands",
210
+ "env",
211
+ "pull.js"
212
+ ]
213
+ },
214
+ "env:push": {
215
+ "aliases": [],
216
+ "args": {
217
+ "file": {
218
+ "description": ".env file to push",
219
+ "name": "file",
220
+ "required": true
221
+ }
222
+ },
223
+ "description": "Push dotenv file to remote service",
224
+ "examples": [
225
+ "<%= config.bin %> <%= command.id %> .env.stage.local"
226
+ ],
227
+ "flags": {},
228
+ "hasDynamicHelp": false,
229
+ "hiddenAliases": [],
230
+ "id": "env:push",
231
+ "pluginAlias": "@dokploy/cli",
232
+ "pluginName": "@dokploy/cli",
233
+ "pluginType": "core",
234
+ "strict": true,
235
+ "enableJsonFlag": false,
236
+ "isESM": true,
237
+ "relativePath": [
238
+ "dist",
239
+ "commands",
240
+ "env",
241
+ "push.js"
242
+ ]
243
+ },
184
244
  "project:create": {
185
245
  "aliases": [],
186
246
  "args": {},
@@ -891,5 +951,5 @@
891
951
  ]
892
952
  }
893
953
  },
894
- "version": "v0.2.3"
954
+ "version": "v0.2.4"
895
955
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dokploy/cli",
3
3
  "description": "A CLI to manage dokploy server remotely",
4
- "version": "v0.2.3",
4
+ "version": "v0.2.4",
5
5
  "author": "Mauricio Siu",
6
6
  "licenses": [{
7
7
  "type": "MIT",
@@ -81,7 +81,8 @@
81
81
  "posttest": "pnpm run lint",
82
82
  "prepack": "oclif manifest && oclif readme",
83
83
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
84
- "version": "oclif readme && git add README.md"
84
+ "version": "oclif readme && git add README.md",
85
+ "publish" :"npm publish"
85
86
  },
86
87
  "types": "dist/index.d.ts"
87
88
  }
@@ -17,6 +17,7 @@ Dokploy CLI is a powerful and versatile command-line tool designed to remotely m
17
17
  - [Authentication](#authentication)
18
18
  - [Project Management](#project-management)
19
19
  - [Application Management](#application-management)
20
+ - [Environment Management](#environment-management)
20
21
  - [Database Management](#database-management)
21
22
  - [Contributing](#contributing)
22
23
  - [Support](#support)
@@ -25,7 +26,7 @@ Dokploy CLI is a powerful and versatile command-line tool designed to remotely m
25
26
  ## Installation
26
27
 
27
28
  ```sh-session
28
- $ npm install -g dokploy
29
+ $ npm install -g @dokploy/cli
29
30
  ```
30
31
 
31
32
  ## Usage
@@ -63,35 +64,45 @@ USAGE
63
64
  - `dokploy app:deploy`: Deploy an application.
64
65
  - `dokploy app:stop`: Stop a running application.
65
66
 
67
+ ### Enviroment Management
68
+
69
+ - `dokploy env pull <file>`: Pull environment variables from Dokploy in a <file>.
70
+ - `dokploy env push <file>`: Push environment variables to Dokploy from a <file>.
71
+
66
72
  ### Database Management
67
73
 
68
74
  Dokploy supports various types of databases:
69
75
 
70
76
  #### MariaDB
77
+
71
78
  - `dokploy database:mariadb:create`
72
79
  - `dokploy database:mariadb:delete`
73
80
  - `dokploy database:mariadb:deploy`
74
81
  - `dokploy database:mariadb:stop`
75
82
 
76
83
  #### MongoDB
84
+
77
85
  - `dokploy database:mongo:create`
78
86
  - `dokploy database:mongo:delete`
79
87
  - `dokploy database:mongo:deploy`
80
88
  - `dokploy database:mongo:stop`
81
89
 
82
90
  #### MySQL
91
+
83
92
  - `dokploy database:mysql:create`
84
93
  - `dokploy database:mysql:delete`
85
94
  - `dokploy database:mysql:deploy`
86
95
  - `dokploy database:mysql:stop`
87
96
 
88
97
  #### PostgreSQL
98
+
89
99
  - `dokploy database:postgres:create`
90
100
  - `dokploy database:postgres:delete`
91
101
  - `dokploy database:postgres:deploy`
92
102
  - `dokploy database:postgres:stop`
93
103
 
94
104
  #### Redis
105
+
95
106
  - `dokploy database:redis:create`
96
107
  - `dokploy database:redis:delete`
97
108
  - `dokploy database:redis:deploy`
@@ -103,6 +114,10 @@ For more information about a specific command, use:
103
114
  $ dokploy [COMMAND] --help
104
115
  ```
105
116
 
117
+ ## Contributing
118
+
119
+ If you want to contribute to Dokploy CLI, please check out our [Contributing Guide](https://github.com/Dokploy/cli/blob/main/CONTRIBUTING.md).
120
+
106
121
  ## Support
107
122
 
108
123
  If you encounter any issues or have any questions, please [open an issue](https://github.com/yourusername/dokploy/issues) in our GitHub repository.