auto-deploy-sh 2.1.1 → 2.1.2

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/README.md CHANGED
@@ -82,6 +82,12 @@ The configuration file is **fixed as `deploy-config.json`**. If missing, the too
82
82
  - `Options`: **Optional** advanced settings (all sub-properties are optional)
83
83
  - `volumes`: Volume mappings (array of strings), formatted as `[host-path/volume-name]:[container-path]:[optional-flags]` (e.g., `["/host/data:/container/data:ro"]`).
84
84
  - `networks`: Connect the container to a custom Docker network (created via `docker network create <network-name>`) for inter-container communication.
85
+ - `logging`: Docker log management configuration. During deployment, it is converted to Docker `--log-driver` and `--log-opt` arguments. Before starting the container, the tool checks the logging drivers supported by the remote Docker daemon. If the configured `driver` is not supported, deployment stops and prints the current default driver and supported driver list.
86
+ - `driver`: Logging driver. The interactive guide currently supports `json-file`, `local`, `none`, `syslog`, `journald`, `gelf`, `fluentd`, `awslogs`, `splunk`, and `gcplogs`.
87
+ - `options`: Logging driver options passed to `docker run` as `--log-opt key=value`.
88
+ - `options.max-size`: Maximum size of a single log file. The guided default is `10m`.
89
+ - `options.max-file`: Number of rotated log files to keep. The guided default is `3`.
90
+ - `options.compress`: Whether to enable log compression. The interactive guide asks for this option when `json-file` is selected.
85
91
 
86
92
  ### Format Introduction
87
93
 
@@ -100,7 +106,15 @@ The configuration file is **fixed as `deploy-config.json`**. If missing, the too
100
106
  "restart": "'no' | 'always' | 'unless-stopped' | 'on-failure'",
101
107
  "Options": {
102
108
  "volumes": "string[]",
103
- "networks": "string[]"
109
+ "networks": "string[]",
110
+ "logging": {
111
+ "driver": "'json-file' | 'local' | 'none' | 'syslog' | 'journald' | 'gelf' | 'fluentd' | 'awslogs' | 'splunk' | 'gcplogs'",
112
+ "options": {
113
+ "max-size": "string",
114
+ "max-file": "string",
115
+ "compress": "boolean"
116
+ }
117
+ }
104
118
  }
105
119
  }
106
120
  ```
@@ -122,7 +136,15 @@ The configuration file is **fixed as `deploy-config.json`**. If missing, the too
122
136
  "restart": "unless-stopped",
123
137
  "Options": {
124
138
  "volumes": ["/host/logs:/app/logs:rw"],
125
- "networks": ["my-custom-network", "my-custom-network-1"]
139
+ "networks": ["my-custom-network", "my-custom-network-1"],
140
+ "logging": {
141
+ "driver": "json-file",
142
+ "options": {
143
+ "max-size": "10m",
144
+ "max-file": "3",
145
+ "compress": true
146
+ }
147
+ }
126
148
  }
127
149
  }
128
150
  ```
@@ -81,6 +81,98 @@ const optionsMethod = {
81
81
  message: 'Bound networks (separated by , ): ',
82
82
  handleFn: (value) => value.split(','),
83
83
  },
84
+ logging: {
85
+ type: 'confirm',
86
+ message: 'Do you want to enable Docker log management?',
87
+ default: false,
88
+ handleFn: async (value) => {
89
+ if (!value)
90
+ return {};
91
+ const loggingDriver = {
92
+ type: 'select',
93
+ message: 'Select a logging driver for the container: ',
94
+ choices: [
95
+ {
96
+ name: 'json-file (default)',
97
+ value: 'json-file',
98
+ description: 'Write logs as JSON files on the host. Docker default and supports max-size/max-file.',
99
+ },
100
+ {
101
+ name: 'local (recommended)',
102
+ value: 'local',
103
+ description: 'Write logs in Docker local format. More efficient for local log rotation and disk usage.',
104
+ },
105
+ {
106
+ name: 'none',
107
+ value: 'none',
108
+ description: 'Disable container logging. Useful when logs are handled entirely by the app.',
109
+ },
110
+ {
111
+ name: 'syslog',
112
+ value: 'syslog',
113
+ description: 'Send logs to the syslog service.',
114
+ },
115
+ {
116
+ name: 'journald',
117
+ value: 'journald',
118
+ description: 'Send logs to systemd journald.',
119
+ },
120
+ {
121
+ name: 'gelf',
122
+ value: 'gelf',
123
+ description: 'Send logs to a Graylog Extended Log Format endpoint.',
124
+ },
125
+ {
126
+ name: 'fluentd',
127
+ value: 'fluentd',
128
+ description: 'Send logs to a Fluentd collector.',
129
+ },
130
+ {
131
+ name: 'awslogs',
132
+ value: 'awslogs',
133
+ description: 'Send logs to Amazon CloudWatch Logs.',
134
+ },
135
+ {
136
+ name: 'splunk',
137
+ value: 'splunk',
138
+ description: 'Send logs to Splunk using the HTTP Event Collector.',
139
+ },
140
+ {
141
+ name: 'gcplogs',
142
+ value: 'gcplogs',
143
+ description: 'Send logs to Google Cloud Logging.',
144
+ },
145
+ ],
146
+ };
147
+ const loggingMaxSize = {
148
+ type: 'input',
149
+ message: 'Logging max-size: (eg: 10m, 1g)',
150
+ default: '10m',
151
+ };
152
+ const loggingMaxFile = {
153
+ type: 'input',
154
+ message: 'Logging max-file: (eg: 3)',
155
+ default: '3',
156
+ };
157
+ const driver = await inquirer.invoke(loggingDriver);
158
+ let options = {
159
+ 'max-size': await inquirer.invoke(loggingMaxSize),
160
+ 'max-file': await inquirer.invoke(loggingMaxFile),
161
+ };
162
+ if (driver === 'json-file') {
163
+ const compress = await inquirer.invoke({
164
+ type: 'confirm',
165
+ message: 'Do you want to enable log compression?',
166
+ default: false,
167
+ });
168
+ options['compress'] = compress;
169
+ }
170
+ return {
171
+ driver,
172
+ options: options,
173
+ };
174
+ },
175
+ },
84
176
  };
85
177
  export async function createConfig(rootPath) {
86
178
  const config = {};
@@ -96,7 +188,7 @@ export async function createConfig(rootPath) {
96
188
  return value;
97
189
  };
98
190
  const value = (await inquirer.invoke(configMethod[key]));
99
- config[key] = fn(value);
191
+ config[key] = await fn(value);
100
192
  }
101
193
  const options = await inquirer.invoke({
102
194
  type: 'checkbox',
@@ -104,6 +196,7 @@ export async function createConfig(rootPath) {
104
196
  choices: [
105
197
  { name: 'Volumes', value: 'volumes' },
106
198
  { name: 'Networks', value: 'networks' },
199
+ { name: 'Logging', value: 'logging' },
107
200
  ],
108
201
  });
109
202
  config['Options'] = {};
@@ -118,7 +211,7 @@ export async function createConfig(rootPath) {
118
211
  return value;
119
212
  };
120
213
  const value = (await inquirer.invoke(optionsMethod[key]));
121
- config['Options'][key] = fn(value);
214
+ config['Options'][key] = await fn(value);
122
215
  }
123
216
  await fs.writeFileSync(path.resolve(rootPath, 'deploy-config.json'), JSON.stringify(config, null, 2));
124
217
  const gitIgnorePath = path.resolve(rootPath, '.gitignore');
@@ -268,6 +268,36 @@ export class Deploy {
268
268
  optionsCLI += ` ${cli}`;
269
269
  break;
270
270
  }
271
+ case 'logging': {
272
+ if (options.logging && options.logging.driver) {
273
+ const logDriver = options.logging.driver.trim();
274
+ const { stderr, code, stdout } = await ssh.execCommand(`docker info --format '{{.LoggingDriver}}|{{json .Plugins.Log}}'`);
275
+ if (code !== 0 || (stderr && code !== 0)) {
276
+ stderr && log.error(stderr);
277
+ throw new Error('Failed to get Docker logging information.');
278
+ }
279
+ const [defaultLogDriver, supportedLogDriversJson = '[]'] = stdout.trim().split('|');
280
+ const supportedLogDrivers = JSON.parse(supportedLogDriversJson);
281
+ if (!supportedLogDrivers.includes(logDriver)) {
282
+ log.error(`Docker logging driver "${logDriver}" is not supported by the remote Docker daemon. ` +
283
+ `Current default driver is "${defaultLogDriver}", supported drivers are: ${supportedLogDrivers.join(', ')}`);
284
+ throw new Error();
285
+ }
286
+ optionsCLI += ` --log-driver ${logDriver}`;
287
+ if (options.logging.options) {
288
+ const logOptions = options.logging.options;
289
+ const logOptionsKeys = Object.keys(logOptions);
290
+ for (let j = 0; j < logOptionsKeys.length; ++j) {
291
+ const logKey = logOptionsKeys[j];
292
+ const logValue = logOptions[logKey];
293
+ if (logValue !== undefined) {
294
+ optionsCLI += ` --log-opt ${logKey}=${logValue}`;
295
+ }
296
+ }
297
+ }
298
+ }
299
+ break;
300
+ }
271
301
  default:
272
302
  break;
273
303
  }
@@ -14,6 +14,14 @@ export type sshConfig = {
14
14
  Options: {
15
15
  volumes: string[];
16
16
  networks: string[];
17
+ logging: {
18
+ driver?: string;
19
+ options?: {
20
+ 'max-size': string;
21
+ 'max-file': string;
22
+ compress?: boolean;
23
+ };
24
+ };
17
25
  };
18
26
  };
19
27
  export type fileData = string | NodeJS.ArrayBufferView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-deploy-sh",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Automated Docker deployment tool",
5
5
  "bin": {
6
6
  "auto-deploy-sh": "./dist/cli/index.js"