Skip to content

Case Study - Github Screenshot Mailer (Java 21, Spring Boot, MySql, JUnit, Docker, Prometheus , Grafana, Kubernetes, Github Action (CI/CD), TestContainer)

Notifications You must be signed in to change notification settings

Rapter1990/githubscreenshotmailer

Repository files navigation

Case Study - Github Screenshot Mailer

Main Information

📖 Information

Project Definition

This service captures a GitHub profile screenshot for a given username, emails the image to a recipient, and persists an operation record.

End-to-end flow (create API):

  • Capture https://github.com/{githubUsername} (optionally after login if withLogin=true).
  • Email the PNG to recipientEmail.
  • Persist a ScreenshotRecord with: githubUsername, recipientEmail, fileName, filePath, fileSizeBytes, sentAt, status (SUCCESS/FAILED).

Optional login:

If withLogin=true, the service signs in with configured credentials and supports GitHub Mobile approval (emails the mobile challenge screenshot). If OTP is enforced and cannot be switched to Mobile, the request fails with a clear error.

Storage layout:

Screenshots are saved in daily directories under the configured base dir (GithubAutomationProperties.screenshotDir). Filenames are auto-suggested PNG names from the username.

Email sending:

Uses JavaMailSender. Failures raise EmailSendException (503).

Search & paging:

A paginated search API lists records with filters (username, email, status, date range, file size, filename, keyword).

Explore Rest APIs

Endpoints Summary

Method URL Description Request Body Headers/Path Response Status Codes
POST /api/github-screenshots Capture GitHub profile screenshot, email it, and persist a record ScreenshotRequest CustomResponse<ScreenshotResponse> 201, 400, 401*, 500
POST /api/github-screenshots/search Paged listing of screenshot records with filters FilterServicePagingRequest CustomResponse<CustomPagingResponse<ScreenshotResponse>> 200, 400

Technologies


  • Java 21
  • Spring Boot 3.0
  • Restful API
  • Open Api (Swagger)
  • Maven
  • Junit5
  • Mockito
  • Integration Tests
  • Docker
  • Docker Compose
  • CI/CD (Github Actions)
  • Postman
  • Prometheus
  • Grafana
  • Kubernetes
  • JaCoCo (Test Report)
  • AOP

Postman

Import postman collection under postman_collection folder

Prerequisites

Define Variable in .env file

GITHUB_SCREENSHOT_DB_IP=localhost
GITHUB_SCREENSHOT_DB_PORT=3306
DATABASE_USERNAME={MY_SQL_DATABASE_USERNAME}
DATABASE_PASSWORD={MY_SQL_DATABASE_PASSWORD}

GMAIL_ADDRESS={your_gmail_email}
GMAIL_PASSWORD={gmail_authentication_password}

GITHUB_LOGIN_EMAIL={github_login_email}
GITHUB_LOGIN_PASSWORD={github_login_password}

Open Api (Swagger)

http://localhost:1926/swagger-ui/index.html

JaCoCo (Test Report)

After the command named mvn clean install completes, the JaCoCo report will be available at:

target/site/jacoco/index.html

Navigate to the target/site/jacoco/ directory.

Open the index.html file in your browser to view the detailed coverage report.


Maven, Docker and Kubernetes Running Process

Maven Run

To build and run the application with Maven, please follow the directions shown below;

$ cd git clone https://github.com/Rapter1990/githubscreenshotmailer.git
$ cd githubscreenshotmailer
$ mvn clean install
$ mvn spring-boot:run

Docker Run

The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.

Please follow directions shown below in order to build and run the application with Docker Compose file;

$ cd githubscreenshotmailer
$ docker-compose up -d

If you change anything in the project and run it on Docker, you can also use this command shown below

$ cd githubscreenshotmailer
$ docker-compose up --build

To monitor the application, you can use the following tools:

  • Prometheus:
    Open in your browser at http://localhost:9090
    Prometheus collects and stores application metrics.

  • Grafana:
    Open in your browser at http://localhost:3000
    Grafana provides a dashboard for visualizing the metrics.
    Default credentials:

    • Username: admin
    • Password: admin

Define prometheus data source url, use this link shown below

http://prometheus:9090

Kubernetes Run

To run the application, please follow the directions shown below;

  • Start Minikube
$ minikube start
  • Open Minikube Dashboard
$ minikube dashboard
  • Revise GITHUB_LOGIN_EMAIL and GITHUB_LOGIN_PASSWORD in github-credentials-secret.yml and GMAIL_ADDRESS and GMAIL_PASSWORD in gmail-secret.yml according to your usage

  • To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder

$ kubectl apply -f k8s
  • To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service prometheus-service
  • To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service grafana-service
  • Define prometheus data source url, use this link shown below
http://prometheus-service.default.svc.cluster.local:9090

Docker Image Location

https://hub.docker.com/repository/docker/noyandocker/githubscreenshotmailer/general

📸 Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12

Figure 13

Figure 14

Figure 15

Figure 16

Figure 17

Figure 18

Figure 19

Figure 20

Figure 21

Figure 22

Contributors

About

Case Study - Github Screenshot Mailer (Java 21, Spring Boot, MySql, JUnit, Docker, Prometheus , Grafana, Kubernetes, Github Action (CI/CD), TestContainer)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published