Spring Google App Engine Standard Java 11 中的启动配置文件 - gcloud
Spring boot profile in Google App Engine Standard Java 11 - gcloud
我正在通过 Github 操作部署我的 spring 启动应用程序。在那里,我有管道使用 gcloud 执行应用程序部署,将我的应用程序部署到 Google App Engine Standard。我已经创建了配置文件,我想在运行时将其注入 spring 启动应用程序
简而言之:如何使用 gcloud 部署 App Engine 标准 java 11 应用程序并支持 spring 配置文件
部署命令
app deploy src/main/appengine/app-dev.yaml --version=1
配置文件定义
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<ACTIVE_PROFILE>dev</ACTIVE_PROFILE>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<ACTIVE_PROFILE>prod</ACTIVE_PROFILE>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>${ACTIVE_PROFILE}</profile>
</profiles>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.3.0</version>
<configuration>
<projectId>${gcloud-projectId}</projectId>
<version>1</version>
</configuration>
</plugin>
</plugins>
</build>
app-dev.yaml文件
runtime: java11
env: standard
instance_class: B4_1G
handlers:
- url: .*
script: auto
secure: always
redirect_http_response_code: 301
basic_scaling:
max_instances: 5
idle_timeout: 60m
env_variables:
ACTIVE_PROFILE: dev
Application.yaml 文件
spring:
profiles:
active: @ACTIVE_PROFILE@
这似乎是由于 App Engine 需要您的应用程序的入口点。
一些框架,Spring引导以及构建一个可执行的 uber JAR 文件。发生这种情况时,运行时会通过 运行 Uber JAR 应用程序启动您的应用程序。
因此您需要 App Engine 将用于其内容的入口点。这应该在您的 app.yaml
中定义,如下所示:
runtime: java11
entrypoint: java -Xmx64m -jar YOUR-ARTIFACT.jar
其中示例YOUR-ARTIFACT.jar
应用程序 jar 必须:
- 与您的 app.yaml 文件位于根目录中。
- 在其 META-INF/MANIFEST.MF 元数据文件中包含一个 Main-Class 条目。
- 可选地,包含一个 Class-Path 条目,其中包含到其他相关 jar 的相对路径列表。这些将自动与应用程序一起上传。
我能够 运行 我的应用程序 spring google 应用引擎标准 java 11 中的开发 spring 配置文件,只需将 spring_profiles_active 包含在 app.yaml 文件.
env_variables:
spring_profiles_active: "dev"
我正在通过 Github 操作部署我的 spring 启动应用程序。在那里,我有管道使用 gcloud 执行应用程序部署,将我的应用程序部署到 Google App Engine Standard。我已经创建了配置文件,我想在运行时将其注入 spring 启动应用程序
简而言之:如何使用 gcloud 部署 App Engine 标准 java 11 应用程序并支持 spring 配置文件
部署命令
app deploy src/main/appengine/app-dev.yaml --version=1
配置文件定义
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<ACTIVE_PROFILE>dev</ACTIVE_PROFILE>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<ACTIVE_PROFILE>prod</ACTIVE_PROFILE>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>${ACTIVE_PROFILE}</profile>
</profiles>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.3.0</version>
<configuration>
<projectId>${gcloud-projectId}</projectId>
<version>1</version>
</configuration>
</plugin>
</plugins>
</build>
app-dev.yaml文件
runtime: java11
env: standard
instance_class: B4_1G
handlers:
- url: .*
script: auto
secure: always
redirect_http_response_code: 301
basic_scaling:
max_instances: 5
idle_timeout: 60m
env_variables:
ACTIVE_PROFILE: dev
Application.yaml 文件
spring:
profiles:
active: @ACTIVE_PROFILE@
这似乎是由于 App Engine 需要您的应用程序的入口点。
一些框架,Spring引导以及构建一个可执行的 uber JAR 文件。发生这种情况时,运行时会通过 运行 Uber JAR 应用程序启动您的应用程序。
因此您需要 App Engine 将用于其内容的入口点。这应该在您的 app.yaml
中定义,如下所示:
runtime: java11
entrypoint: java -Xmx64m -jar YOUR-ARTIFACT.jar
其中示例YOUR-ARTIFACT.jar
应用程序 jar 必须:
- 与您的 app.yaml 文件位于根目录中。
- 在其 META-INF/MANIFEST.MF 元数据文件中包含一个 Main-Class 条目。
- 可选地,包含一个 Class-Path 条目,其中包含到其他相关 jar 的相对路径列表。这些将自动与应用程序一起上传。
我能够 运行 我的应用程序 spring google 应用引擎标准 java 11 中的开发 spring 配置文件,只需将 spring_profiles_active 包含在 app.yaml 文件.
env_variables:
spring_profiles_active: "dev"