Azure and Google Cloud have built-in support for cloud native buildpacks. You can use Azure or Google Cloud to easily deploy Java applications by using the Paketo Buildpack for Liberty with your source code or container images.
This post provides instructions on how to use the Paketo Buildpack for Liberty with Azure and Google Cloud. To learn more about using Azure and Google Cloud, see their respective documentation.
What do you need?
To build and deploy container images or create a custom builder, you’ll also need:
The Paketo Buildpack for Liberty is included in the composite Paketo Buildpack for Java that also includes
tomee application servers. Tomcat is the default application server and to use Open Liberty requires a little extra configuration. The Paketo Buildpack for Java includes Bellsoft Liberica as the default JVM provider. To use other JVM providers requires extra configuration.
You can set the application server that the Paketo Buildpack for Java uses by specifying the
BP_JAVA_APP_SERVER environment variable and select an alternate JVM provider using a project descriptor.
Let’s get started
Create the project descriptior file,
project.toml, in the application’s root source directory. At a minimum,
project.toml must specify the
BP_JAVA_APP_SERVER=liberty environment variable but can contain other environment variables that are consumed by buildpacks.
To use the alternate and preferred Eclipse OpenJ9 JVM, change the order that the buildpacks run in the project descriptor. To minimize the size of the application container image, the buildpack installs the Liberty kernel profile by default. You can override the profile using the
BP_LIBERTY_PROFILE environment variable or use the
BP_LIBERTY_FEATURES environment variable to install the Liberty features your application requires.
For example, your project descriptor might contain the following content to use the Liberty runtime and install Eclipse OpenJ9, the Liberty kernel profile, and a set of Liberty features:
[[build.env]] name = "BP_JAVA_APP_SERVER" value = "liberty" [[build.env]] name = "BP_LIBERTY_FEATURES" value = "jsonb-2.0 mpconfig-3.0 mpmetrics-4.0 restfulws-3.0 jsonp-2.0 cdi-3.0" [[build.buildpacks]] uri = "docker://gcr.io/paketo-buildpacks/eclipse-openj9" [[build.buildpacks]] uri = "docker://gcr.io/paketo-buildpacks/java"
Build and push a container image with Azure
Use the az acr pack build command to build and push a container image using the built-in cloud native buildpack support.
For example, the following command builds and pushes the container image using the
mycr Azure container registry and the full Paketo Buildpacks builder. The resulting image name is
myapp and the application source resides in
~/myappsourcedir. The application source can also be specified as the URL of a Git repo. This example assumes the
mycr Azure container registry was previously created.
az acr pack build --registry mycr --pull --builder paketobuildpacks/builder:full --image myapp ~/myappsourcedir
Build and push a container image with Google Cloud
The command uses the following basic syntax:
gcloud builds submit --pack image=LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/IMAGE_NAME
In the following example,
us-east1 is the LOCATION,
paketobuildpacks is the PROJECT_ID,
paketobuildpacktest is the REPO_NAME and
javatest is the IMAGE_NAME. The command is executed from the application’s root directory.
gcloud builds submit --pack image=us-east1-docker.pkg.dev/paketobuildpacks/paketobuildpacktest/javatest,builder=paketobuildpacks/builder:full
Liberty environment variables you can set in the
Specifies the Install type of Liberty. Open Liberty (value of
ol) is the default. Use
wlpfor WebSphere Liberty.
Specifies which Liberty profile to install. Valid profiles for Liberty are documented in the buildpacks documentation. The default profile is
Specifies a space-separated list of Liberty features to be installed with the Liberty runtime. Supports any valid Liberty feature.
Take full advantage of the Paketo Buildpack for Liberty with the pack build CLI
Some features of the Paketo Buildpack for Liberty are not easily available to Azure or Google Cloud. Features like installing iFixes, custom features, and installing from a packaged server or server directory aren’t available when you use the built-in support to create the container image.
For these features, you can use the
pack build CLI to create the container image, tag and push the image to an external container registry. Then, use Azure or Google Cloud to deploy and manage your container by pulling your container image from the container registry. See Introducing the Paketo Liberty Buildpack for details on using the
pack build CLI with Liberty.