Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active December 21, 2020 13:42
Show Gist options
  • Select an option

  • Save jonashackt/4a051720e0bae16fef3ffa290071f5b5 to your computer and use it in GitHub Desktop.

Select an option

Save jonashackt/4a051720e0bae16fef3ffa290071f5b5 to your computer and use it in GitHub Desktop.
Cheat sheet for Cloud Native Buildpacks / Paketo building Spring Boot apps
# Samples:
https://github.com/buildpacks/samples
# We can override the default ENTRYPOINT in a CNB build container
see https://buildpacks.io/docs/app-developer-guide/run-an-app/#user-provided-shell-process
So we need to know the default launch process of a CNB build Spring Boot container - and then add the needed installation command
# How is the Spring Boot app launched inside the container?
(see https://github.com/buildpacks/spec/blob/main/platform.md#launcher)
./cnb/lifecycle/launcher java org.springframework.boot.loader.JarLauncher
or as stated in https://stackoverflow.com/q/65013814/4964553, we can also use the new 2.4 behavior with process type web
./cnb/process/web
# How can we achieve the same startup behavior as a default CNB build Spring Boot app?
docker run --rm -p 8080:8080 --entrypoint launcher spring-boot-buildpack:0.0.1-SNAPSHOT "java org.springframework.boot.loader.JarLauncher"
or 2.4-style
docker run --rm -p 8080:8080 --entrypoint /cnb/process/web spring-boot-buildpack:0.0.1-SNAPSHOT
# Finally combine the default startup override with the installation command
docker run --rm -p 8080:8080 --entrypoint launcher spring-boot-buildpack:0.0.1-SNAPSHOT "sudo apt install curl; java org.springframework.boot.loader.JarLauncher"
--> error, since we're not root (which is one of the goals of CNBs/Paketo)
# So we need to use the root user to install curl
docker run --user="root" --entrypoint launcher spring-boot-buildpack:0.0.1-SNAPSHOT "apt-get update && apt-get install curl -y"
But that container shouldn't be used to run our Spring Boot app, since the user is now configured to be root. Therefore we need to switch to a non-root container for our App to run.
# Use our curl-installed container - but provide a different ENTRYPOINT and user
https://stackoverflow.com/questions/32353055/how-to-start-a-stopped-docker-container-with-a-different-command
docker commit 2ff7db32825f spring-boot-buildpack-with-curl
docker run --rm -p 8080:8080 --user="cnb" --entrypoint /cnb/process/web spring-boot-buildpack-with-curl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment