简体   繁体   中英

How to deploy SpringBoot (.war) aplication to Cloud Run?

I have a SpringBoot project and i deployed to Google App Engine. Its working fine. The site was not accessed very much. But it's billing cost goes up.

So i decided to move my SpringBoot project to "Cloud Run".

I have tried with the following link https://cloud.google.com/run/docs/quickstarts/build-and-deploy/java

But in the above tutorials, they specifed about jar file.

Jave 8, SpringBoot 2.3.0.RELEASE versions are using in this project.

pom.xml for app engine

<plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <projectId>MY-SPRING-BOOT-APP</projectId>
                    <version>1</version>
                    <ssl-enabled>true</ssl-enabled>
                </configuration>
            </plugin>

DockerFile

# Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven
FROM maven:3.8-jdk-11 as builder

# Copy local code to the container image.
WORKDIR /app
COPY pom.xml .
COPY src ./src

# Build a release artifact.
RUN mvn package -DskipTests

# Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk11:alpine-slim

# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/myapp.war /target/myapp.war

# Run the web service on container startup.
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/target/myapp.war"]
#CMD ["catalina.sh","run"]

Any idea?

Finally i had successfully deploy my springboot application to cloud run without changing package type.

# Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven
FROM maven:3.8-jdk-11 as builder

# Copy local code to the container image.
WORKDIR /app
COPY pom.xml .
COPY src ./src

# Build a release artifact.
RUN mvn package -DskipTests

# Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk11:alpine-slim

# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/myapp-*.war /myapp.war

# Run the web service on container startup.
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/myapp.war"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM