Bootstrapping a Maven App

For bootstrapping a maven application to use the complete set of files to use our artifacts, you can take the following steps:

Build a Spring Boot Application

Create a spring boot maven application and make sure it is running fine locally.

Pre-requisites

You should have

  • Jenkins
  • Chartmuseum
  • Helm

installed on your cluster for this to work fully.

Adding Stakater's Draft Pack

Go to Stakater Maven Draft Packopen in new window, and copy the following files and folders from there:

  • Dockerfile
  • Jenkinsfile
  • Makefile
  • deployments folder

Replacing Contents

First of all, add *.tgz in your .gitignore so that your chart never gets pushed on your git repository.

Now you would need to replace some values in the above files, as we have left them as placeholders. So you would need to change them with their actual values when using this draft. All such values start with REPLACE_ME. The values are:

VALUEDescription
REPLACE_ME_APP_NAMEreplace it with app name in lower case, make sure your app name is set to the artifact id in pom.xml. Notice that in deployments/kubernetes/chart/ we also need to replace the folder name with your app name
REPLACE_ME_IMAGE_NAMEreplace it with your <git-repo-owner>/<app-name> name
REPLACE_ME_IMAGE_SECRETreplace with "" if using a public image
REPLACE_ME_IMAGE_TAGreplace it with your app tag
REPLACE_ME_HEALTH_ENDPOINTreplace it with endpoint of your application or remove the probe section if you dont want liveness and readiness probes
REPLACE_ME_HEALTH_PORTreplace it with the liveness/readiness probe port
REPLACE_ME_SERVICE_PORTreplace it with the port on which your service will run
REPLACE_ME_NAMESPACE_NAMEthe namespace you want the app to be deployed if deploying through Makefile.

The above values need to be changed in the values.yaml.tmpl(the file needed to generate values.yaml in pipeline) and values.yaml(for local verification) files.

Moreover, you can add/remove stuff from the above files, like if you dont want configmap and secrets, you can remove that part. You can remove/change tolerations or replicas or any such stuff in above files. Please make sure to make changes in values.yaml.tpl file as that file is actually used to deploy your application in a pipeline.

Understanding the Jenkinsfile

In Jenkinsfile, we are using a generic function for releasing Maven based applications, so the pipeline is parameterized. The following parameters can be set.

ParameterDescription
REPLACE_ME_GIT_USERThe Git Username used to clone the repository
REPLACE_ME_GIT_MAILThe git user email needed to clone the repo in Jenkins pipeline
deployUsingMakeTargetThe boolean value if you want to deploy your application using the make target in your makefile
dockerRepositoryURLThe docker registry url where you want to publish your image
chartRepositoryURLThe chart registry url where you want to publish your helm chart
javaRepositoryURLThe nexus registry url where you want to publish your jars