The Bookmark Application allows users to store and manage bookmarks of interesting articles. It includes features such as pagination and search functionality.
- Add new bookmarks
- View bookmarks with pagination
- Search for bookmarks
- Uses H2 database for local development
- Flyway for database migrations
- Docker & Kubernetes setup for containerization and orchestration
- Backend: Spring Boot
- Database: H2 (in-memory for local development), PostgreSQL (for production)
- Containerization: Docker, Docker Compose
- Orchestration: Kubernetes (using KIND)
- Testing: Testcontainers for integration testing
- Dev Tools: Spring Boot DevTools for auto-reloading
- Validation: Spring Boot Validation for bean validation
- Lombok: To generate getters and setters
- CI/CD: GitHub Actions for automated testing and Docker image creation
- Clone the repository:
git clone <repository-url> cd bookmarker-api
- Run the application using Maven:
./mvnw spring-boot:run
- Access the application:
- Bookmarks API: http://localhost:8080/api/bookmarks
- Pagination: http://localhost:8080/api/bookmarks?page=2
- H2 Console: http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:<db-instance>
- User:
sa
- Password: (leave empty)
- JDBC URL:
To execute tests, use:
./mvnw clean verify
- Build the Docker image:
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=ck9913/bookmarker-api
- Run the container:
docker run -p 8080:8080 ck9913/bookmarker-api
Flyway is used to manage database migrations. All migration scripts are stored in src/main/resources/db/migration
and are executed in sequence.
Important:
- Once a Flyway migration script has been executed, do not modify it. Instead, create a new script for any changes.
- Flyway sorts migration scripts based on version numbers and executes them sequentially.
Kubernetes is used for container orchestration to ensure high availability and scalability.
- Create a cluster using KIND:
./kind/create-cluster.sh
- Deploy the application:
kubectl apply -f kubernetes/
- Destroy the cluster (if needed):
./kind/destroy-cluster.sh
- Pods: Deploy and manage application containers.
- ReplicaSets: Ensures the required number of instances are running.
- Deployments: Manages rollout history and upgrades.
- Services: Exposes the application.
- Ingress Controller: Routes traffic based on DNS patterns.
- Persistent Volumes: Ensures data persistence for databases.
A GitHub Actions workflow is configured in .github/workflows/build.yml
. It performs the following tasks:
- Runs tests
- Builds the Docker image
- Pushes the image to Docker Hub
- Kubernetes GUI: Lens for managing Kubernetes clusters.
- Enhance search functionality
- Improve scalability for production
- Follow best practices for Spring Boot development.
- Ensure tests are written for all new features.
- Use feature branches for development.
This README provides an overview of the project, setup instructions, and development best practices.