A Java quickstart to show how to use Drone to build and deploy Java application to Kubernetes
The following tools are required to run this quickstart,
All linux distributions adds envsubst via gettext package. On macOS it can be installed using Homebrew like brew install gettext
.
git clone https://github.com/kameshsampath/drone-java-quickstart && \
cd "$(basename "$_" .git)"
export QUICKSTART_HOME="$PWD"
Going forward we will call this folder as $QUICKSTART_HOME
in the README.
Follow my blog post Yours Kindly Drone to prepare your local environment to run Kubernetes and Drone together.
The Java builds will use Sonatype Nexus as the Apache Maven artifacts repository manager.
kubectl apply -k "$QUICKSTART_HOME/k8s/nexus"
Wait for nexus to be ready,
kubectl rollout status deploy/nexus --timeout=180s
Copy the settings Example CLI Usage from the drone account settings page http://drone-127.0.0.1.sslip.io:8080/account.
For this quickstart settings running the command drone info
should show the following output,
User: demo
Email: [email protected]
Ensure the Gitea demo
user is added as Repository Admin in Drone to allow modifying the required settings.
drone user update demo --admin
Running the command drone user admin info
should show the following output,
User: demo
Email: [email protected]
Admin: true
Active: true
Machine: false
To run drone in a trusted mode we need to mark the repository as trusted.
Run the following command to mark the drone-java-quickstart
as trusted,
drone repo update --trusted demo/drone-java-quickstart
Update the .drone.yml
with the following additional steps that allows you to build and test the Java application,
- name: test-java-application
image: docker.io/kameshsampath/drone-java-maven-plugin:v1.0.0
pull: if-not-exists
settings:
maven_mirror_url: http://nexus:8081/nexus/content/groups/public/
goals:
- clean
- test
maven_modules:
- springboot
- name: build-java-application
image: docker.io/kameshsampath/drone-java-maven-plugin:v1.0.0
pull: if-not-exists
settings:
maven_mirror_url: http://nexus:8081/nexus/content/groups/public/
goals:
- clean
- -DskipTests
- install
maven_modules:
- springboot
- name: build-image
image: plugins/docker
settings:
insecure: false
repo: localhost:5001/example/drone-java-quickstart
context: /drone/src/springboot