mirror of
				https://github.com/easingthemes/ssh-deploy.git
				synced 2025-10-30 23:30:09 +08:00 
			
		
		
		
	Use SSH_CMD_ARGS in SCRIPT_BEFORE and SCRIPT_AFTER
This commit is contained in:
		
							parent
							
								
									a1aa0b6cf9
								
							
						
					
					
						commit
						0e3540cf8f
					
				| @ -25,7 +25,7 @@ const run = async () => { | |||||||
|   } |   } | ||||||
|   // Check Script before
 |   // Check Script before
 | ||||||
|   if (scriptBefore) { |   if (scriptBefore) { | ||||||
|     await remoteCmdBefore(scriptBefore, privateKeyPath, scriptBeforeRequired); |     await remoteCmdBefore(scriptBefore, privateKeyPath, scriptBeforeRequired, sshCmdArgs); | ||||||
|   } |   } | ||||||
|   /* eslint-disable object-property-newline */ |   /* eslint-disable object-property-newline */ | ||||||
|   await sshDeploy({ |   await sshDeploy({ | ||||||
| @ -34,7 +34,7 @@ const run = async () => { | |||||||
|   }); |   }); | ||||||
|   // Check script after
 |   // Check script after
 | ||||||
|   if (scriptAfter) { |   if (scriptAfter) { | ||||||
|     await remoteCmdAfter(scriptAfter, privateKeyPath, scriptAfterRequired); |     await remoteCmdAfter(scriptAfter, privateKeyPath, scriptAfterRequired, sshCmdArgs); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ const handleError = (message, isRequired, callback) => { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // eslint-disable-next-line max-len
 | // eslint-disable-next-line max-len
 | ||||||
| const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Promise((resolve, reject) => { | const remoteCmd = async (content, privateKeyPath, isRequired, label, sshCmdArgs) => new Promise((resolve, reject) => { | ||||||
|   const uuid = crypto.randomUUID(); |   const uuid = crypto.randomUUID(); | ||||||
|   const filename = `local_ssh_script-${label}-${uuid}.sh`; |   const filename = `local_ssh_script-${label}-${uuid}.sh`; | ||||||
|   try { |   try { | ||||||
| @ -21,7 +21,7 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom | |||||||
|     const rsyncStdout = (process.env.RSYNC_STDOUT || '').substring(0, dataLimit); |     const rsyncStdout = (process.env.RSYNC_STDOUT || '').substring(0, dataLimit); | ||||||
|     console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`); |     console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`); | ||||||
|     exec( |     exec( | ||||||
|       `DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`, |       `DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} ${sshCmdArgs} ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`, | ||||||
|       (err, data = '', stderr = '') => { |       (err, data = '', stderr = '') => { | ||||||
|         if (err) { |         if (err) { | ||||||
|           const message = `⚠️ [CMD] Remote script failed: ${err.message}`; |           const message = `⚠️ [CMD] Remote script failed: ${err.message}`; | ||||||
| @ -42,6 +42,6 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|   remoteCmdBefore: async (cmd, privateKeyPath, isRequired) => remoteCmd(cmd, privateKeyPath, isRequired, 'before'), |   remoteCmdBefore: async (cmd, privateKeyPath, isRequired, sshCmdArgs) => remoteCmd(cmd, privateKeyPath, isRequired, 'before', sshCmdArgs), | ||||||
|   remoteCmdAfter: async (cmd, privateKeyPath, isRequired) => remoteCmd(cmd, privateKeyPath, isRequired, 'after') |   remoteCmdAfter: async (cmd, privateKeyPath, isRequired, sshCmdArgs) => remoteCmd(cmd, privateKeyPath, isRequired, 'after', sshCmdArgs) | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Artyom Belousov
						Artyom Belousov