Java8 将 appcfg 迁移到 gcloud

Java8 migrate appcfg to gcloud

最近 appcfg 弃用后出现问题。我的项目是 java8 在通往 GCP 的 jenkins 管道中使用 ant 构建的。

[exec] 95% Application deployment failed. Message: Deployments using appcfg are no longer supported. See https://cloud.google.com/appengine/docs/deprecations

在 GCP 中,我有 3 个项目,开发、测试和实时。我使用参数构建以通过 jenkins 匹配项目。例如。 building with test 传递了 deploy-test 参数。

来自蚂蚁的片段build.xml:

<target name="deploy-test" depends="build, setup-for-appengine, setup-for-test, deploy"></target>

<target name="deploy-live" depends="build, setup-for-appengine, setup-for-live, deploy"</target>

<target name="setup-for-test" description="Configuration for test">
  (Some config stuff e.g. replacing app id and version in the appengine-web.xml)
</target>

<target name="deploy" description="Upload to App Engine.">
  <exec executable="${FILE PATH TO appcfg.sh}" failonerror="true">
    <arg line="update '${.ENV FILE PATH}/war'" />
  </exec>
</target>

我已经从 App Engine SDK 更新到 Cloud SDK 并迁移到 gcloud CLI。我在 build.xml 中的可执行文件现在是:

<target name="deploy" description="Upload to App Engine.">
  <exec executable="${FILE PATH TO gcloud executable}" failonerror="true">
    <arg line="app deploy '${.ENV FILE PATH}/war'" />
  </exec>
</target>

此部署将通过 jenkins 运行 成功,但这会导致 500 错误并针对开发而不是测试。唯一改变的是文件路径从 App Engine SDK 到 Cloud SDK 并迁移到 gcloud 命令。

     [exec] descriptor:      [filepath/appengine-web.xml]
     [exec] source:          [filepath/war]
     [exec] target project:  [dev]
     [exec] target service:  [default]
     [exec] target version:  [version no.]
     [exec] target url:      [https://dev.appspot.com]

任何方向将不胜感激。提前致谢

您需要指定 appengine-web.xml 文件的路径。

<target name="deploy" description="Upload to App Engine.">
  <exec executable="${FILE PATH TO gcloud executable}" failonerror="true">
    <arg line="app deploy '${.ENV FILE PATH}/war/WEB-INF/appengine-web.xml'" />
  </exec>
</target>

此外,设置要部署的版本,因为从版本 311.0.0 (2020-09-22) 开始,applicationversion 元素在 appengine-web.xml 内不受尊重。

 <target name="deploy" description="Upload to App Engine.">
   <exec executable="${FILE PATH TO gcloud executable}" failonerror="true">
     <arg line="app deploy '${.ENV FILE PATH}/war/WEB-INF/appengine-web.xml'" />
     <arg line="-v ${version.name}"/>
   </exec>
 </target>

请注意,这仅适用于 Java 8。对于 Java 11,您需要将您的应用程序打包到可执行 jar 中。

gcloud app deploy ~/my_app/my_jar.jar

您还需要从现有应用程序中删除 appengine-web.xml 文件并将其替换为 app.yaml 文件

https://cloud.google.com/appengine/docs/standard/java11/java-differences

已通过添加 --project 和 --version 解决,因为在 appengine-web.xml 中不再受尊重。 -q 被添加以传递更新等任何提示。

<target name="deploy" description="Upload to App Engine.">
   <exec executable="${FILE PATH TO gcloud executable}" failonerror="true">
     <arg line="app deploy '${.ENV FILE PATH}/war/WEB-INF/appengine-web.xml' --project=${application_id} --version=${application_version} -q" />
   </exec>
 </target>

我在 GCP 和更改项目的 gservice 帐户范围权限方面也遇到了一些问题,现在已解决。