This example shows how to build multiple containers for a multi-module project in both Maven and Gradle.
The project consists of two microservices:
name-service
- responds with a namehello-service
- callsname-service
and responds with a greeting
The Maven project is set up with a parent POM (pom.xml
) that defines most of the common build configuration. The module POMs (name-service/pom.xml
and hello-service/pom.xml
) just define inheritance on the parent POM. However, if needed, the module POMs can define custom configuration on jib-maven-plugin
specific to that module.
The Gradle project is set up with a single build.gradle
that configures both subprojects (modules). settings.gradle
defines which modules to include in the overall build. If needed, the subprojects can have build.gradle
files to define custom configuration on jib-gradle-plugin
specific to that module.
Set the PROJECT_ID
environment variable to your own Google Cloud Platform project:
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
Run the Maven build:
./mvnw compile jib:build
Run the Gradle build:
./gradlew jib
You can also run ./maven-build.sh
or ./gradle-build.sh
as a shorthand.
The output of the build should have the container image references highlighted in cyan. You can expect them to be at:
name-service
:gcr.io/PROJECT_ID/name-service:0.1.0
hello-service
:gcr.io/PROJECT_ID/hello-service:0.1.0
kubernetes.yaml
defines the manifests for running the two microservices on Kubernetes. Make sure to open the file and change PROJECT_ID
to your own Google Cloud Platform project.
Create a Kubernetes cluster:
gcloud container clusters create jib
Apply to your Kubernetes cluster:
kubectl apply -f kubernetes.yaml
Find the EXTERNAL-IP
of the hello-service
.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/hello-service LoadBalancer 10.19.243.223 35.237.89.148 80:30196/TCP 1m
Visit the IP in your web browser and you should see:
Hello Jib Multimodule