这是对我们非常有效的 ant 目标的核心。上述步骤中唯一未实现的部分是 #7,因为 AppEngine 尚无法实现。我们发现使用日期作为版本号对于跟踪部署非常方便。
<target name="auth">
<java classname="com.google.appengine.tools.admin.AppCfg" inputstring="${appengine.pass}" fork="true">
<sysproperty key="appengine.sdk.root" value="${appengine.sdk.dir}" />
<classpath>
<fileset dir="${appengine.sdk.dir}/lib" includes="**/*.jar" />
</classpath>
<arg value="--email=${appengine.email}" />
<arg value="resource_limits_info" />
<arg value="war" />
</java>
</target>
<target name="optimize">
<delete dir="${staging.dir}" />
<mkdir dir="${staging.dir}" />
<copy todir="${staging.dir}">
<fileset dir="war">
<exclude name="WEB-INF/classes/**" />
<exclude name="WEB-INF/appengine-generated/**" />
<exclude name="include.js" />
<exclude name="js/app/**" />
<exclude name="js/tmpl/**" />
</fileset>
</copy>
<jar destfile="${staging.dir}/WEB-INF/lib/classes.jar" basedir="${classes.dir}" />
<exec executable="./scripts/optimize.sh">
<env key="PATH" value="/usr/bin:/bin:/usr/local/bin" />
</exec>
</target>
<target name="deploy-prod" depends="auth, optimize">
<property name="appid" value="voost0" />
<tstamp>
<format property="vnum" pattern="yyyy-MM-dd-HHmm"/>
</tstamp>
<echo message="Deploying to version: ${vnum}" />
<appcfg action="update" war="${staging.dir}">
<options>
<arg value="--application=${appid}" />
<arg value="--version=${vnum}" />
</options>
</appcfg>
<get src="http://${vnum}.${appid}.appspot.com/ping" dest="${build.dir}/warmup-garbage" verbose="true" />
</target>
<target name="deploy-prod-switch" depends="deploy-prod">
<appcfg action="set_default_version" war="${staging.dir}">
<options>
<arg value="--application=${appid}" />
<arg value="--version=${vnum}" />
</options>
</appcfg>
</target>