1
votes

I am deploying my spring boot application through Github actions. In that I have pipeline which executes app deploy using gcloud to deploy my application to Google App Engine Standard. I have created profiles and I want to inject that to spring boot application at runtime

In Short : How to deployment app engine standard java 11 application using gcloud and support spring profile

Command that deploy

app deploy src/main/appengine/app-dev.yaml --version=1

Profile Definition

<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 file

 
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 file

spring:
  profiles:
    active: @ACTIVE_PROFILE@

2

2 Answers

2
votes

I am able to run my application in dev spring profile in google app engine standard java 11 by just including spring_profiles_active in app.yaml file.

env_variables:
 spring_profiles_active: "dev"
0
votes

This seems to occure due to App Engine needing an entrypoint for your application.

Some frameworks, Spring Boot as well, build an executable uber JAR file. When this happens, the runtime starts your application by running an Uber JAR application.

So you need an entrypoint that App Engine will use for its contents. This should be defined in your app.yaml as shown below:

runtime: java11
entrypoint: java -Xmx64m -jar YOUR-ARTIFACT.jar

Where the example YOUR-ARTIFACT.jar application jar must:

  • Be in the root directory with your app.yaml file.
  • Contain a Main-Class entry in its META-INF/MANIFEST.MF metadata file.
  • Optionally, contain a Class-Path entry with a list of relative paths to other dependent jars. These will upload with the application automatically.

Source