This repository holds the code mentioned in the Codefresh blog post "Using Docker from Maven and Maven from Docker"
It consists of 4 individual projects mentioned in the article
- A Java project that uses the Maven spotify plugin
- A Java project that uses the Fabric8 Maven plugin (also runs integration tests)
- A Java project with a Multi-stage dockerfile that runs Maven from within Docker
- The same multi-stage Java projects with a YAML build file for Codefresh
To build the project
cd 01-using-spotify-plugin
mvn package
This command will create a Docker image
To build the project and run integration tests
cd 02-using-fabric8-plugin
mvn verify
This command will
- compile and the code create a Docker image
- launch the docker image and run integration tests against it
To build the project and run unit tests
cd 03-multistage
docker build -t my-java-app .
This command will
- Download a Maven docker image and use it to compile the code and run unit tests
- Keep the WAR file produced it will place it in a Tomcat Docker image
Create a Codefresh account and use the provided build yaml file.
version: '1.0'
steps:
build_image:
type: build
description: Building the image...
image_name: docker-maven-comparison
working_directory: ./04-codefresh
tag: develop
build_image_with_tests:
type: build
description: Building the Test image...
image_name: maven-integration-tests
working_directory: ./04-codefresh
dockerfile: Dockerfile.testing
integration_tests:
type: composition
title: Launching QA environment
description: Temporary test environment
working_directory: ${{main_clone}}
composition:
version: '2'
services:
app:
image: ${{build_image}}
ports:
- 8080
composition_candidates:
test_service:
image: ${{build_image_with_tests}}
links:
- app
command: bash -c '/usr/bin/wait-for-it.sh -t 20 app:8080 -- mvn verify -Dserver.host=app'
Once build this Codefresh YAML will
- Create a multi-stage Docker image with the war file (based on Tomcat) also running unit tests
- Create a Maven image that holds the integration tests
- Launch the tomcat image and run the integration tests against it (using wait-for-it.sh as well)