'How to deploy Spring boot and React application together on GCP App Engine?

I don't have any experience in deployment and trying to deploy Frontend and backend together. I am able to successfully deploy the spring boot application. I followed this tutorial and successfully generated a build. Is it possible to deploy the frontend and backend together? This is how my folder structure inside target/classes/public look like



Solution 1:[1]

As mentioned in this GCP docs:

Use services in App Engine to factor your large apps into logical components that can securely share App Engine features and communicate with one another. Generally, your App Engine services behave like microservices.

Deploying two apps written in different language on a same runtime in App Engine standard is not possible as you won't be able to run Javascript apps if the current runtime in your app.yaml is Java.

My suggestion would be to split your applications into separate services as mentioned in the docs.

Finally, if you insist on a monolithic approach, consider deploying your app to a custom runtime in App Engine flex. Refer to this doc. Do note that it requires a Dockerfile so you will have to manage the containerization of your apps.

Solution 2:[2]

We can deploy a spring boot backend application with react front end as a single JAR in GCP. I simply followed instructions in tutorial , Created an app engine in GCP and ran this command - gcloud app deploy ***.jar

You need to create the jar using maven and then run the command on that jar. It will deploy in gcp.

     <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
                <mainClass>${start-class}</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Donnald Cucharo
Solution 2 Karthik Rengasamy