This projekt is a simple example how to use Jenkins Pipelines to build and containerize a project, having the infrastructure available as Docker image as well. The project is based on Java/SpringBoot and is packaged and containerized with Docker.
The infrastructure is located in the folder /build-env
. The Dockerfile
describes the Jenkins base Docker image
extended by Maven and Docker itself. Maven is required to build the project, Docker tooling is needed to build
and push the Docker image.
The docker-compose-yml
bundles the custom Jenkins image with the standard Docker registry and a web frontend for
the registry.
The project itself is quite small, it just consists of a static page. To build the project, you may use
mvn clean verify
. This will build, test, package and, for convenience, bundle the project with it's dependencies
in a single jar.
Simply execute docker-compose build
to build the respective docker images and docker-compose up
in the
/build-env
folder. Hello Jenkins at http://localhost:8081
. You need to setup your Jenkins, please do as
you're told ;)
Create a Multi-Branch Project on your Jenkins build server. Map the project to
github.com:stefanreichert/hello-jenkinspipelines.git
(or any other project you like...). Since the build server will use the Jenkinsfile
no further configuration is required. Your project will automatically be built, the result will be pushed to your local Docker registry at http://localhost:5000
. That's basically it...
There is a registry UI deployed with the infrastructure. At http://localhost:8082
you will find a web frontend
exposing your registry content. Your build results will show up here.
There will be state on your host machine...
- Jenkins home folder
~/tmp/docker/jenkins/home
- Maven home folder
~/tmp/docker/maven/home
In order to allow Docker tooling inside a Docker image, the Jenkins images maps the Docker socket file as volume to share the engine with the container. Seems to good practice ;)