I cannot run a spring-boot web image built with Paketo Buildpacks by spring-maven-plugin. Error says:
Deploying container to Cloud Run service [bff] in project [merchantloans] region [us-central1]
X Deploying...
- Creating Revision...
. Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Revision 'bff-00002-wtm' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
Any ideas? Even if I try to set PORT=8080 environment variable in local docker it doesn't expose port 8080. Only if I use the docker -p argument does that work, but that doesn't seem to be available in google-cloud-run
[INFO] Building image 'docker.io/library/bff:1.0-SNAPSHOT'
[INFO]
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder-jammy-base:latest' 100%
[INFO] > Pulled builder image 'paketobuildpacks/builder-jammy-base@sha256:94593b2ad54362e1256da43631661d3dad936a177609a3d297fc638e87c6ee91'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 100%
[INFO] > Pulled run image 'paketobuildpacks/run-jammy-base@sha256:c2bc9ac828642aee2376a649ef5affd6912507c739247a40086bcae6d62a8b41'
[INFO] > Executing lifecycle version v0.18.5
[INFO] > Using build cache volume 'pack-cache-65773be3b4d2.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Restoring data for SBOM from previous image
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 26 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.6.7
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 10.5.2
[INFO] [creator] paketo-buildpacks/syft 1.44.0
[INFO] [creator] paketo-buildpacks/executable-jar 6.8.3
[INFO] [creator] paketo-buildpacks/dist-zip 5.6.8
[INFO] [creator] paketo-buildpacks/spring-boot 5.27.8
[INFO] [creator] ===> RESTORING
[INFO] [creator] Restoring metadata for "paketo-buildpacks/ca-certificates:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:java-security-properties" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:jre" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/syft:syft" from cache
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:spring-cloud-bindings" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:web-application-type" from app image
[INFO] [creator] Restoring data for "paketo-buildpacks/syft:syft" from cache
[INFO] [creator] Restoring data for SBOM from cache
[INFO] [creator] ===> BUILDING
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for CA Certificates 3.6.7
[INFO] [creator] https://github.com/paketo-buildpacks/ca-certificates
[INFO] [creator] Launch Helper: Reusing cached layer
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 10.5.2
[INFO] [creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[INFO] [creator] $BP_JVM_JLINK_ENABLED false enables running jlink tool to generate custom JRE
[INFO] [creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[INFO] [creator] $BP_JVM_VERSION 17 the Java version
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[INFO] [creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[INFO] [creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[INFO] [creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[INFO] [creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[INFO] [creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[INFO] [creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[INFO] [creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[INFO] [creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[INFO] [creator] $BPL_JMX_PORT 5000 configure the JMX port
[INFO] [creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[INFO] [creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] Using Java version 17 extracted from MANIFEST.MF
[INFO] [creator] BellSoft Liberica JRE 17.0.10: Reusing cached layer
[INFO] [creator] Launch Helper: Reusing cached layer
[INFO] [creator] Java Security Properties: Reusing cached layer
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Syft 1.44.0
[INFO] [creator] https://github.com/paketo-buildpacks/syft
[INFO] [creator] Downloading from https://github.com/anchore/syft/releases/download/v0.104.0/syft_0.104.0_linux_amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Executable JAR 6.8.3
[INFO] [creator] https://github.com/paketo-buildpacks/executable-jar
[INFO] [creator] Command "packages" is deprecated, use `syft scan` instead
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env/CLASSPATH.delim
[INFO] [creator] Writing env/CLASSPATH.prepend
[INFO] [creator] Process types:
[INFO] [creator] executable-jar: java org.springframework.boot.loader.launch.JarLauncher (direct)
[INFO] [creator] task: java org.springframework.boot.loader.launch.JarLauncher (direct)
[INFO] [creator] web: java org.springframework.boot.loader.launch.JarLauncher (direct)
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Spring Boot 5.27.8
[INFO] [creator] https://github.com/paketo-buildpacks/spring-boot
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_DISABLED false whether to contribute Spring Boot cloud bindings support
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_VERSION 1 default version of Spring Cloud Bindings library to contribute
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_DISABLED false whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_ENABLED true Deprecated - whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] Creating slices from layers index
[INFO] [creator] dependencies (22.5 MB)
[INFO] [creator] spring-boot-loader (446.0 KB)
[INFO] [creator] snapshot-dependencies (0.0 B)
[INFO] [creator] application (117.4 KB)
[INFO] [creator] Launch Helper: Reusing cached layer
[INFO] [creator] Spring Cloud Bindings 2.0.2: Contributing to layer
[INFO] [creator] Downloading from https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-bindings/2.0.2/spring-cloud-bindings-2.0.2.jar
[INFO] [creator] Verifying checksum
[INFO] [creator] Copying to /layers/paketo-buildpacks_spring-boot/spring-cloud-bindings
[INFO] [creator] Web Application Type: Contributing to layer
[INFO] [creator] Servlet web application detected
[INFO] [creator] Writing env.launch/BPL_JVM_THREAD_COUNT.default
[INFO] [creator] 4 application slices
[INFO] [creator] Image labels:
[INFO] [creator] org.opencontainers.image.title
[INFO] [creator] org.opencontainers.image.version
[INFO] [creator] org.springframework.boot.version
[INFO] [creator] ===> EXPORTING
[INFO] [creator] Reusing layer 'paketo-buildpacks/ca-certificates:helper'
[INFO] [creator] Reusing layer 'paketo-buildpacks/bellsoft-liberica:helper'
[INFO] [creator] Reusing layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
[INFO] [creator] Reusing layer 'paketo-buildpacks/bellsoft-liberica:jre'
[INFO] [creator] Reusing layer 'paketo-buildpacks/executable-jar:classpath'
[INFO] [creator] Reusing layer 'paketo-buildpacks/spring-boot:helper'
[INFO] [creator] Reusing layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
[INFO] [creator] Reusing layer 'paketo-buildpacks/spring-boot:web-application-type'
[INFO] [creator] Adding layer 'buildpacksio/lifecycle:launch.sbom'
[INFO] [creator] Reusing 3/5 app layer(s)
[INFO] [creator] Adding 2/5 app layer(s)
[INFO] [creator] Reusing layer 'buildpacksio/lifecycle:launcher'
[INFO] [creator] Reusing layer 'buildpacksio/lifecycle:config'
[INFO] [creator] Reusing layer 'buildpacksio/lifecycle:process-types'
[INFO] [creator] Adding label 'io.buildpacks.lifecycle.metadata'
[INFO] [creator] Adding label 'io.buildpacks.build.metadata'
[INFO] [creator] Adding label 'io.buildpacks.project.metadata'
[INFO] [creator] Adding label 'org.opencontainers.image.title'
[INFO] [creator] Adding label 'org.opencontainers.image.version'
[INFO] [creator] Adding label 'org.springframework.boot.version'
[INFO] [creator] Setting default process type 'web'
[INFO] [creator] Saving docker.io/library/bff:1.0-SNAPSHOT...
[INFO] [creator] *** Images (506f57c215a7):
[INFO] [creator] docker.io/library/bff:1.0-SNAPSHOT
[INFO] [creator] Reusing cache layer 'paketo-buildpacks/syft:syft'
[INFO] [creator] Reusing cache layer 'buildpacksio/lifecycle:cache.sbom'
[INFO]
[INFO] Successfully built image 'docker.io/library/bff:1.0-SNAPSHOT'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.917 s
[INFO] Finished at: 2024-03-01T13:32:15-05:00
[INFO] ------------------------------------------------------------------------
You're on the right track! Using the pack CLI and setting the port argument during the build is a good approach to ensure your Spring Boot web image listens on the correct port for Google Cloud Run.
Steps:
pack
CLI:pack build my-spring-boot-app:latest --env PORT=8080
Replace my-spring-boot-app:latest
with your application name and tag.
This sets the PORT
environment variable to 8080 within the container image.
Push the built image to your container registry.
Deploy the image to Cloud Run using gcloud run deploy
:
gcloud run deploy SERVICE_NAME --image REGISTRY_URL/my-spring-boot-app:latest
This approach ensures your application listens on the expected port (8080) for Cloud Run.
Documentation Reference: