Example Spring Boot application and CI/CD pipeline showing how to run a Java project on Semaphore 2.0.
- Simple login screen
- User registration
- An endpoint secured with
Basicauthentification layer - Persistence layer for storing users in database
"/admin/home"a secured endpoint that returns a webpage in a form oftext/html, generated with thymeleaf. AdminController"/login"standard spring login endpoint"/logout"rest endpoint, ends user session, redirects to"/login""/users/signup"rest endpoint, adds a new user to the system. UserController
Persistence for this project is set up using Spring Data JPA, and utilizes m2 database,
which is a runtime database for the ease of testing and continuous integration, however is fully compatible with many
standard database technologies like Postgres.
There is a single database entity User and a corresponding repository UserRepository
Tests are separated into two classpaths (in order to run them as separate tasks):
- src/test holds the unit tests
- src/it holds the integration tests, in this case repository and rest endpoint tests.
The Semaphore pipeline is configured to:
- Build the project
- Run tests
- Build Docker image
- Push image to
hub.docker.com
Semaphore pipeline configuration is located at .semaphore/semaphore.yml
To set up this pipeline on your Semaphore account:
- If you don't have
semcommand line tool installed, do so usingcurl https://storage.googleapis.com/sem-cli-releases/get.sh | bashand then connect to your account usingsem connect <your organisation>.semaphoreci.com <your private key>. You can get the private key from your account dashboard atsemaphoreci.com. - Add the project to Semaphore using
sem init. - This pipeline relies on public Docker repository to push artifacts of successful builds. Create an account on
https://hub.docker.com/if you don't have one. - Add your
hub.docker.comcredentials to./docker-hub-secret.yml. The credentials should remain private, so don't publish them to your Git repository by mistake. - Add your
./docker-hub-secret.ymlcredentials to Semaphore withsem create -f docker-hub-secret.yml
After pushing a new commit to master, Semaphore will initiate a workflow:
This project is set up using Maven. Build configuration can be found at pom.xml.
mvn spring-boot:run
Tests are separated into two classpaths: src/test for unit tests, and src/it for integration tests.
To run unit tests:
mvn clean test
To run integration tests
mvn clean test -Pintegration-testing
To run performance tests
mvn clean jmeter:jmeter
mvn jmeter:gui
Copyright (c) 2022 Rendered Text
Distributed under the MIT License. See the file LICENSE.
