luki530
luki530

Reputation: 1

How to deploy springboot application with google cloud build (compilation on git pushes)?

Can someone tell me how to configure automatic deployment of springboot appilcation stored on github ?

I tried some solution from stack over flow but it is not working. My app.yaml file looks like

runtime: java
env: flex
runtime_config:
  jdk: openjdk11
handlers:
- url: /.*
  script: this field is required, but ignored

my cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/mvn'
  args: ['package']
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy', '/workspace/src/main/resources/app.yaml']

And the error I am having:

Exception in thread "main" com.google.cloud.runtimes.builder.exception.ArtifactNotFoundException: No deployable artifacts were found. Unable to proceed.

Thanks for your reply.

Upvotes: 0

Views: 1594

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 76010

First, the openJKD11 runtime config doesn't exist for AppEngine Flexible. You have to use a custom runtime like this:

runtime: custom
env: flex
handlers:
- url: /.*
  script: this field is required, but ignored

Then, you have to build an container image of your code. You can use a standard Dockerfile at your project root like this one

FROM maven:3.6.3-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 

FROM adoptopenjdk/openjdk11

COPY --from=builder /app/target/java-*.jar /java.jar

# Run the web service on container startup.
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/java.jar"]

Change the java-*.jar of this line COPY --from=builder /app/target/java-*.jar /java.jar according with the name of your JAR

And in your Cloud Build, simply deploy your app

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']

Additional remark

Your previous Cloud Build couldn't work, because your jar file was in target/ directory and not in the root directory, and your deployment didn't find it. For this, you could add a dir param in your Cloud Build

steps:
- name: 'gcr.io/cloud-builders/mvn'
  args: ['package']
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy', '/workspace/src/main/resources/app.yaml']
  dir: "target"

But the next error would be the runtime openjdk11 not supported.

Upvotes: 1

Related Questions