如何在gcloud vm实例上使用ant部署java web项目

时间:2016-04-29 07:01:49

标签: google-compute-engine gcloud gcloud-java

我已经搜索了用于java web项目部署的gcloud doc但是我在结果中只获得了maven项目doc。已在谷歌云控制台和谷歌sdk中创建的项目也已安装。

1 个答案:

答案 0 :(得分:0)

一种方法是使用sshexec& amp; s简单地连接到谷歌云计算机。在ant中的scp任务,并存放一个tarball和extract,一个例子可能是......:

<target name="deploy-staging" description="Deploy to staging">
        <input message="Staging Passphrase:" addproperty="my.password">
            <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
        </input>
        <!-- Create the new release folder on host-->
        <sshexec trust="true"
                 host="hosthere"
                 username="username"
                 keyfile="${user.home}/.ssh/keyfile"
                 passphrase="${my.password}"
                 command="mkdir /var/www/releases/${git.revision}" />

        <!-- Push the application tarball to the server-->
        <scp trust="true"
             file="${basedir}/build/${git.revision}.tar.gz"
             todir="username@${hosthere}:/var/www/releases/${git.revision}"
             keyfile="${user.home}/.ssh/keyfile"
             passphrase="${my.password}"/>

        <!-- Extract the tarball on the server-->
        <sshexec trust="true"
                 host="${hosthere}"
                 username="username"
                 keyfile="${user.home}/.ssh/keyfile"
                 passphrase="${my.password}"
                 command="cd /var/www/releases/${git.revision}; tar -xvzf ${git.revision}.tar.gz" />
        <sshexec trust="true"
                 host="${hosthere}"
                 username="username"
                 keyfile="${user.home}/.ssh/keyfile"
                 passphrase="${my.password}"
                 command="rm -rf /var/www/current" />

        <sshexec trust="true"
                 host="${hosthere}"
                 username="username"
                 keyfile="${user.home}/.ssh/keyfile"
                 passphrase="${my.password}"
                 command="ln -s /var/www/releases/${git.revision} -T /var/www/current" />
     </target>

以上未经过测试..最终使用此功能,同时寻找更好的方法来处理gcloud实例组。