remote-deploy-cli 1.1.2 → 1.2.0

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.
@@ -0,0 +1,9 @@
1
+ # Ignore artifacts:
2
+ build
3
+ coverage
4
+ dist
5
+ node_modules
6
+ .git
7
+
8
+ # Ignore config files that don't need formatting
9
+ package-lock.json
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 100
7
+ }
package/README.md CHANGED
@@ -71,7 +71,9 @@ redep deploy <type>
71
71
  ```
72
72
 
73
73
  **Parameters:**
74
- - `<type>`: The service type to deploy. Currently supports `fe` (frontend).
74
+ - `<type>`: The service type to deploy.
75
+ - `fe`: Frontend (pre-configured to run `docker compose pull && docker compose up -d`).
76
+ - `custom`: Custom command (configured on server via `deployment_command`).
75
77
 
76
78
  **Requirements:**
77
79
  - `SERVER_URL` must be configured.
@@ -81,6 +83,9 @@ redep deploy <type>
81
83
  ```bash
82
84
  # Deploy frontend service
83
85
  redep deploy fe
86
+
87
+ # Deploy custom command
88
+ redep deploy custom
84
89
  ```
85
90
 
86
91
  **Expected Output:**
@@ -155,6 +160,9 @@ redep config set working_dir /path/to/project
155
160
 
156
161
  # Set Secret Key
157
162
  redep config set secret_key my-secret-key
163
+
164
+ # Set Custom Deployment Command (Optional)
165
+ redep config set deployment_command "git pull && npm install && pm2 restart app"
158
166
  ```
159
167
 
160
168
  #### Running with Docker (Recommended)
@@ -172,6 +180,7 @@ services:
172
180
  environment:
173
181
  - WORKING_DIR=/workspace
174
182
  - SECRET_KEY=secure-key
183
+ - DEPLOYMENT_COMMAND=docker compose restart app
175
184
  ```
176
185
 
177
186
  ---
@@ -208,6 +217,7 @@ sequenceDiagram
208
217
  | :------------ | :------------ | :----------------------------------------------- | :--------------- |
209
218
  | `server_port` | `SERVER_PORT` | Port for the server to listen on (Default: 3000) | **Server** |
210
219
  | `working_dir` | `WORKING_DIR` | Directory to execute commands in | **Server** |
220
+ | `deployment_command` | `DEPLOYMENT_COMMAND` | Custom command for `deploy custom` | **Server** |
211
221
  | `server_url` | `SERVER_URL` | URL of the remote `redep` server | **Client** |
212
222
  | `secret_key` | `SECRET_KEY` | Shared secret for authentication | **Both** |
213
223
 
@@ -16,16 +16,35 @@ export const deploy = async (type, serverUrl, secret) => {
16
16
  if (result.output.stdout) console.log(result.output.stdout);
17
17
  if (result.output.stderr) console.log(result.output.stderr);
18
18
  logger.log('---------------------');
19
+ } else if (type === 'custom') {
20
+ logger.info('Sending custom deployment instruction to server machine...');
21
+
22
+ try {
23
+ const result = await sendCommand(serverUrl, '/deploy/custom', secret, {});
24
+
25
+ if (result.status === 'success') {
26
+ logger.success('Server successfully executed the custom deployment command.');
27
+ logger.log('--- Remote Output ---');
28
+ if (result.output.stdout) console.log(result.output.stdout);
29
+ if (result.output.stderr) console.log(result.output.stderr);
30
+ logger.log('---------------------');
31
+ } else {
32
+ logger.error('Server reported failure.');
33
+ console.error(result);
34
+ }
35
+ } catch (err) {
36
+ throw err;
37
+ }
19
38
  } else {
20
- logger.error('Server reported failure.');
21
- console.error(result);
22
- }
23
- } catch (err) {
24
- throw err;
25
- }
39
+ logger.error('Server reported failure.');
40
+ console.error(result);
41
+ }
42
+ } catch (err) {
43
+ throw err;
44
+ }
26
45
 
27
- } else {
28
- logger.error(`Deployment type "${type}" is not supported yet.`);
29
- throw new Error(`Unsupported deployment type: ${type}`);
30
- }
31
- };
46
+ } else {
47
+ logger.error(`Deployment type "${type}" is not supported yet.`);
48
+ throw new Error(`Unsupported deployment type: ${type}`);
49
+ }
50
+ };
@@ -5,6 +5,7 @@ import helmet from 'helmet';
5
5
  import morgan from 'morgan';
6
6
  import { logger } from '../logger.js';
7
7
  import { executeCommand } from './executor.js';
8
+ import { getConfig } from '../config.js';
8
9
 
9
10
  export const createServer = (secretKey, workingDir) => {
10
11
  const app = express();
@@ -59,5 +60,31 @@ export const createServer = (secretKey, workingDir) => {
59
60
  }
60
61
  });
61
62
 
63
+ // Endpoint for custom deployment command
64
+ app.post('/deploy/custom', authenticate, async (req, res) => {
65
+ logger.info('Received custom deploy request');
66
+
67
+ // Get command from environment variable or config
68
+ const deploymentCommand = getConfig('deployment_command') || process.env.DEPLOYMENT_COMMAND;
69
+
70
+ if (!deploymentCommand) {
71
+ logger.error('No DEPLOYMENT_COMMAND set');
72
+ return res.status(400).json({
73
+ status: 'error',
74
+ error: 'No DEPLOYMENT_COMMAND configured. Set it via env var or "redep config set deployment_command <cmd>"'
75
+ });
76
+ }
77
+
78
+ logger.info(`Executing custom command: ${deploymentCommand}`);
79
+
80
+ try {
81
+ const result = await executeCommand(deploymentCommand, workingDir);
82
+ res.json({ status: 'success', output: result });
83
+ } catch (error) {
84
+ logger.error(`Deployment failed: ${error}`);
85
+ res.status(500).json({ status: 'error', error: error.message || error });
86
+ }
87
+ });
88
+
62
89
  return app;
63
90
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote-deploy-cli",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,7 +8,10 @@
8
8
  },
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
11
- "update": "node scripts/update.js"
11
+ "update": "node scripts/update.js",
12
+ "format": "prettier --write .",
13
+ "format:check": "prettier --check .",
14
+ "sonar": "node sonar-project.js"
12
15
  },
13
16
  "keywords": [],
14
17
  "author": "",
@@ -26,5 +29,9 @@
26
29
  "helmet": "^7.1.0",
27
30
  "morgan": "^1.10.0",
28
31
  "pm2": "^6.0.14"
32
+ },
33
+ "devDependencies": {
34
+ "prettier": "^3.8.0",
35
+ "sonarqube-scanner": "^4.3.4"
29
36
  }
30
37
  }
@@ -0,0 +1,18 @@
1
+ const scanner = require('sonarqube-scanner');
2
+
3
+ scanner(
4
+ {
5
+ serverUrl: process.env.SONAR_HOST_URL || 'http://localhost:9000',
6
+ token: process.env.SONAR_TOKEN,
7
+ options: {
8
+ 'sonar.projectKey': 'remote-deploy-cli',
9
+ 'sonar.projectName': 'Remote Deploy CLI',
10
+ 'sonar.projectVersion': '1.0.0',
11
+ 'sonar.sources': 'bin,lib',
12
+ 'sonar.tests': 'test', // Assuming tests are in a 'test' directory
13
+ 'sonar.javascript.lcov.reportPaths': 'coverage/lcov.info',
14
+ 'sonar.sourceEncoding': 'UTF-8',
15
+ },
16
+ },
17
+ () => process.exit()
18
+ );