This project is cloned from Spring PetClinic and its purpose is to showcase how Buildpacks works.
pack
CLI installed- Docker daemon installed
First, choose one of the suggested builder from the output of this command:
pack suggest-builders
As this is a Java application, select one with a buildpack for Java, for example cloudfoundry/cnb:bionic
. You could choose a builder from another source or even build your own (Create a buildpack and Create a builder).
Once you've chosen a builder, you can build it as follows:
pack build <image-name> --builder <builder-name>
For example:
pack build petclinic:buildpack --builder cloudfoundry/cnb:bionic
From the command output you can determine which buildpacks where involved and which layers where rebuilt. Once your image is built, use docker images
to see it and docker run -p 8080:8080 --rm <image-name>:<tag>
to run it.
Once you have built your image, you can inspect it to see some metadata:
pack inspect-image <image-name>
For example, building this petclinic application with cloudfoundry/cnb:bionic
and then inspecting it returns the following output:
REMOTE:
(not present)
LOCAL:
Stack: io.buildpacks.stacks.bionic
Base Image:
Reference: 1332879bc8e38793a45ebe5a750f2a1c35df07ec2aa9c18f694644a9de77359b
Top Layer: sha256:eb195d29dc1aa6e4239f00e7868deebc5ac12bebe76104e0b774c1ef29ca78e3
Run Images:
cloudfoundry/run:base-cnb
Buildpacks:
ID VERSION
org.cloudfoundry.openjdk v1.2.14
org.cloudfoundry.buildsystem v1.2.15
org.cloudfoundry.jvmapplication v1.1.12
org.cloudfoundry.tomcat v1.3.18
org.cloudfoundry.springboot v1.2.13
org.cloudfoundry.distzip v1.1.12
org.cloudfoundry.springautoreconfiguration v1.1.11
Processes:
TYPE SHELL COMMAND ARGS
web (default) bash java -cp $CLASSPATH $JAVA_OPTS org.springframework.samples.petclinic.PetClinicApplication
executable-jar bash java -cp $CLASSPATH $JAVA_OPTS org.springframework.boot.loader.JarLauncher
spring-boot bash java -cp $CLASSPATH $JAVA_OPTS org.springframework.samples.petclinic.PetClinicApplication
task bash java -cp $CLASSPATH $JAVA_OPTS org.springframework.samples.petclinic.PetClinicApplication
We can see that the buildpacks used for its building process, the name of the stack used (useful for rebasing our image to another stack) and the reference for the top layer of the stack. You can also use the flag --bom
, which returns a bill of materials as a JSON object, with more information about each layer.
Inspecting an image can be done in images generated by Buildpacks, as well as in any other image. Keep in mind other images may not contain this kind of metadata in them.
You can access the official Buildpacks documentation here.