Go2FullStack
Go2FullStack
Auto remote deployment script with Ant

A common scenario is that you are developing a project on your laptop, but you need to deploy the project to a remote server. Moreover, this remote server is located in an internal network for security reasons and has no external network IP address, so it cannot be directly accessed from the external network, so it needs to be indirectly accessed through a gateway server. As shown in the following figure:

https://go2fullstack.com/wp-content/uploads/2020/05/image-1.png

For simplicity, we can develop Ant scripts :
1、You need an Ant script locally to package and upload the project to the gateway server. This can be done through SCP tasks in Ant.
2、You need to deploy an Ant script on the gateway server as well. After packaging and uploading, execute the Ant script on the gateway server and deploy it to the production environment. This requires the sshexec task.

Here’s a diagram of the process:

https://go2fullstack.com/wp-content/uploads/2020/05/image-2.png

In order to use the sshexec and SCP tasks, in the Ant script, you need to define it:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

Scp and sshexec tasks examples:

		<scp 
			todir="${server.ssh.username}@${server.ssh.ip}:${server.target.dir}/conf" 
			keyfile="${server.ssh.keyfile}"
			passphrase="${server.ssh.passphrase}"
			trust="yes"
		>
			<fileset dir="../../conf/${deploy_process}/${ant.project.name}"></fileset>
		</scp>
		<sshexec host="${server.ssh.ip}"
			username="${server.ssh.username}"
			keyfile="${server.ssh.keyfile}"
			passphrase="${server.ssh.passphrase}"
			trust="yes"
			command="cd ${project.server.dir}/${tomcat.version}; ${server.ant.exec} -f ${project.server.dir}/build_in_server.xml -Dserver.ssh.ip=${deploy.server.ssh.ip} -Dserver.ssh.username=${deploy.server.ssh.username} -Dserver.ssh.keyfile=${deploy.server.ssh.keyfile} -Dserver.ssh.passphrase=${deploy.server.ssh.passphrase} -Dpackage.name=${package.name} -Ddeploy.name=${deploy.name} ${deploy.targets}"/>

Leave a Reply

textsms
account_circle
email

Go2FullStack

Auto remote deployment script with Ant
A common scenario is that you are developing a project on your laptop, but you need to deploy the project to a remote server. Moreover, this remote server is located in an in…
Scan QR code to continue reading
2018-02-03