Search code examples
spring-bootgoogle-app-enginegcloudgithub-actionsspring-profiles

Spring boot profile in Google App Engine Standard Java 11 - gcloud


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@


Solution

  • 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"