java-build  1.0.0
Containerized environment for building Java based projects.
Quick Start

Getting started with the containerized Java build environment.

For more detailed information, see:

These instructions assume two roles:

Role Responsibilities Permissions
DevOps Maintain and operate build, test and runtime environments Full administrator control over shared source control repositories, Docker image repositories etc.
Users Writes code, authors test automation, runs unit and integration tests Pull java-build image from repository

DevOps

Base Image

The build-base-image script provides a simple convenience wrapper for invoking docker build ... to create an image from base.dockerfile:

git clone https://gitlab.com/kirkrader/java-build.git
cd java-build
git checkout -b yourbranch
find . \( \
  -name \*.dockerfile \
  -o -name \* \
  -o -name .gitlab-ci.yml \
  \) \
  -exec sed -i'.bak' 's+registry.gitlab.com/kirkrader+yourtagprefix+g' \{\} \;
./build-base-image
push yourtagprefix/java-build:latest

CI/CD Server

DevOps can use build-user-image, described in the following section, to create images for use by the CI/CD server process by specifying an alternate user id as a second parameter.

mkdir ssh
ssh-keygen -o -t rsa -C "ciciduserid@yourdomain.com" -b 4096 -f ssh/id_rsa

# ...be sure to copy contents of ssh/id_rsa.pub into the CI/CD server's source
# control repository...

# ...create additional SSH configuration files as appropriate...

mkdir m2
vi m2/settings.xml

# ...populate m2/settings.xml and m2/settings-security.xml appropriately...

./build-user-image cicdpassword ciciduserid
# ...enter full name and email address for CI/CD identity when prompted...

# to test the container...
docker volume create projects
docker volume create mvn_repo
docker run --rm -it \
  -v projects:/projects \
  -v mvn_repo:/mvn_repo \
  cicduserid-java-build
  • Replace cicidpassword and ciciduserid with desired credentials for this special image
  • You will be prompted for full name and email address to use when configuring Git in the image
  • You should then configure your CI/CD server to use the custom user image you just created in an invocation of docker run ... similar to that shown in the preceding examples

Note: change the image tag in the various scripts and configuration files from registry.gitlab.com/kirkrader to your own Docker Hub or other image repository tag if you fork this source repository.

Users

Once DevOps has pushed java-build to a shared image repository, build-user-image provides a convenience wrapper for docker build ... to create an image from user.dockerfile:

# if you have never configured git...
git config --global user.name "Your Full Name"
git config --global user.email "yourid@yourdomain.com"

# if you don't yet have a SSH key...
ssh-keygen -o -t rsa -C "yourid@yourdomain.com" -b 4096

# if you don't have Maven installed...
mkdir -p ~/.m2
vi ~/.m2/settings.xml
# ...configure Maven as desired...

# after DevOps has pushed yourtagprefix/java-build...
git clone https://gitlab.com/kirkrader/java-build.git
cd java-build
git checkout -b yourbranch
find . \( \
  -name \*.dockerfile \
  -o -name \* \
  -o -name .gitlab-ci.yml \
  \) \
  -exec sed -i'.bak' 's+registry.gitlab.com/kirkrader+yourtagprefix+g' \{\} \;
./build-user-image
# ...enter desired password when prompted...

# note: this will create an image containing sensitive information including SSH
# keys, email address etc. so it should never be pushed to a shared repository

./run-java-build-container
# ..from here, you are typing into a bash shell running in the container...
cd /projects
ls
# ...see listing from your host file system ~/projects directory...
exit
# ...and now you are back in your host shell...
  • You will be prompted for the password you would like to use in your image
  • Full name and email address will be copied from your current Git configuration
  • ~/.ssh and ~/.m2 in the image will be copied from your host file-system home directory
  • ~/projects and ~/.m2/repository will be mapped into the container as /projects and /mvn_repo, respectively